通过php中echo插入图片,PHP / Imagick:只有在echo'd时才会写入图片

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

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值