I am trying to use pngquant compression algorithm to compress PNG images on the fly using WAMP. They provide an example of PHP , which (I think) should use the binary command line for Windows , which I put in the system32 , and I can access from anywhere on the command line.
I gave their example and traced the problem to the line $compressed_png_content = shell_exec("pngquant --quality=$min_quality-$max_quality - < ".escapeshellarg( $path_to_png_file)); . I simplified it to var_dump(shell_exec('pngquant - < test.png')); but it only prints the first 5 characters, even if passthru('pngquant - < test.png'); seems to send the correct output to the user as a string. exec('pngquant - < test.png',$output); var_dump($output); also seems to capture the correct output, but in the form of an array, which I really don't know how to convert back to an image file. I want to capture the output in a variable, so I can use additional compression and manipulation algorithms and send it to the user as a downloadable file.
I read the differences between system () vs exec () vs shell_exec () vs passthru () vs proc_open () vs popen () . Shell_exec () seems like the right choice, however, php.net says shell_exec () prints a string. Maybe this is a problem? How to correctly write the output of pngquant - < test.png to a variable?
source share