我已经在 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 )