我已经在mac和运行centos 7的linux上安装了pngquant。在这两台机器上,我可以将它与命令行一起使用,但如果在php中运行相同的命令,则if将不起作用。
我试过的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 )
最佳答案
使用sudo
就行了。为我工作。