pngquant不适用于PHP

时间:2017-04-07 09:40:45

标签: php linux pngquant

我已经在mac和运行centos 7的linux上安装了pngquant。在两台机器上我都可以使用命令行,但是如果在php中运行相同的命令则不行。

我试过的Linux命令:

yum install pngquant

说它成功安装了pngquant

which pngquant

返回/usr/bin/pngquant

我的php文件代码ptst.php:

<?php
echo "start";
 echo $get_compress = exec("find . -name '*.png' -exec /usr/bin/pngquant -ext .png -force 256 {} \;");
echo "end";
?>

我当前文件夹中只有1个png文件:image_5.png。它具有权限-rwxrwxrw-,与ptst.php

位于同一文件夹中

使用ls -la后,我可以看到文件大小没有改变。回音的输出只是startend

如果我在终端中运行相同的代码,文件大小将变为之前大小的1/3。

我做错了什么?显然有一些我不知道的问题。

编辑: 新命令:

echo $get_compress = exec("find . -name '*.png' -exec /usr/bin/pngquant --ext .png --force 256 {} \; 2>&1", $output);
print_r($output);

输出更具说明性;

'./image_5.png.tmp' for writingArray ( [0] => error: cannot open './image_5.png.tmp' for writing )

1 个答案:

答案 0 :(得分:0)

使用sudo它会起作用。为我工作。

相关问题