我已经在mac和linux上安装了pngquant,在这两台机器上我都可以通过命令行来使用pngquant,但是如果在php中运行同样的命令,pngquant就不起作用了。
我尝试过的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";
?>我只有一个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 )发布于 2017-12-14 16:35:43
使用sudo,它就会工作。对我很管用。
https://stackoverflow.com/questions/43274792
复制相似问题