以下 PHP 在传递此图像时,将 0 字节写入 $cache(但适用于所有其他已知图像)。如果调用 writeImage 之前的回声未注释,则它可以正常工作。<?php exec('php -f thumb.php -- img=zc9vfo.png >output'); ?>
(由于不相关的原因
,PHP 正在运行。)如果有人可以给我一个提示,让我知道要研究什么,那就太好了。
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);
?>