以下PHP在传递this image时将0字节写入$ cache(但对所有其他已知图像都正常工作)。如果在writeImage调用之前的回显被取消注释,它可以正常工作。 (由于不相关的原因,PHP正在通过<?php exec('php -f thumb.php -- img=zc9vfo.png >output'); ?>运行。)如果任何人都可以给我一个提示,看看会发生什么,那太棒了。
if(isset($argc) && (!isset($_GET) || empty($_GET))){
for($i = 1; $i < $argc; ++$i){
if(strpos($argv[$i], '--') === 0){
$argv[$i] = substr($argv[$i], 2);
}
list($key, $value) = explode('=', $argv[$i], 2);
$_GET[$key] = $value;
}
}
if(!isset($_SERVER['DOCUMENT_ROOT']) || $_SERVER['DOCUMENT_ROOT'] == ''){
$_SERVER['DOCUMENT_ROOT'] = /* ... */;
}
$name =& $_GET['img'];
if(!isset($name)){
die('unspecified');
}
$pipe_name = realpath("{$_SERVER['DOCUMENT_ROOT']}/lib/php/pipes") . "/$name";
if(!file_exists($pipe_name) && !posix_mkfifo($pipe_name, 0777)){
file_put_contents('output', 'Pipe could not be created.');
exit(1);
}
$pipe = fopen($pipe_name, 'r+');
if(!$pipe){
file_put_contents('output', 'Pipe could not be opened.');
exit(1);
}
function pipe($msg, $die=FALSE){
global $pipe;
fwrite($pipe, $msg . PHP_EOL);
if($die){
die($msg);
}else{
echo $msg;
}
}
$w = 150;
$h = 114;
if(!file_exists($image = $_SERVER['DOCUMENT_ROOT'] . '/images/' . $name)){
pipe('invalid', TRUE);
}
$cache = $_SERVER['DOCUMENT_ROOT'] . '/thumbs/' . $name;
if(!file_exists($cache)){
$thumb = new Imagick($image);
$thumb->flattenImages();
$quotient = min($thumb->getImageWidth() / $w,
$thumb->getImageHeight() / $h);
$thumb->cropImage($w * $quotient, $h * $quotient, 0, 0);
$thumb->scaleImage($w, $h);
// echo $thumb->getImageBlob();
$thumb->writeImage($cache);
}
pipe('success');
fclose($pipe);
?>