0

以下 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);

?>
4

2 回答 2

1

您可能误用flattenImages. 从用户注释:

请注意,该函数返回一个 Imagick 对象并且不修改现有对象。

您也可能不小心忽略了错误状态。 cropImagescaleImage并且writeImage在成功时都返回布尔值 true,而前两个在失败时抛出异常。

当它写入一个零字节文件时,是否getImageBlob也返回零字节?我看到你已经评论了它,所以很明显你在戳它一点。

于 2011-03-18T21:21:19.340 回答
-1

我显然安装了错误的 ImageMagick、IMagick 和/或 libpng。请参阅此论坛主题: http ://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=18326

于 2011-03-20T23:43:08.527 回答