简体   繁体   中英

pngquant doesn't work with php

I have installed pngquant on a mac and on a linux running centos 7. On both machines I can use it with command line, but if won't work when the same command is run in php.

Linux commands I tried:

yum install pngquant

says it succesfully installed pngquant

which pngquant

returns /usr/bin/pngquant

my php file code ptst.php:

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

I only have 1 png file in current folder: image_5.png . It has permissions: -rwxrwxrw- , and is in the same folder as ptst.php

upon using ls -la I can see that the file size hasn't changed. The echoed outout is just startend .

If I run the same code in Terminal, the file size changes to 1/3 of it's previous size.

What am I doing wrong? There is clearly some issues I don't know about.

EDIT: new command:

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

output is a bit more illustrative;

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

use sudo and it'll work. Worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM