I am trying to use the pngquant compression algorithm to compress PNG images on the fly using WAMP. They provide a PHP example that (I think) is supposed to use the command line binary for Windows, which I have put in the system32 folder and I can access from anywhere on the command line.
I have taken their example and traced the problem to the $compressed_png_content = shell_exec("pngquant --quality=$min_quality-$max_quality - < ".escapeshellarg(    $path_to_png_file)); line. I have simplified it to var_dump(shell_exec('pngquant - < test.png')); but it only outputs the first 5 characters even though 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 a form of an array, which I don't really know how to convert back into an image file. I want to capture the output in a variable so I can use further compression algorithms and manipulations and send it to the user as a downloadable file.
I have read up on the diferences between system() vs exec() vs shell_exec() vs passthru() vs proc_open() vs popen(). Shell_exec() seems to be the correct choice, however it says on php.net that shell_exec()'s outputs a string. Could that be a problem? How do I correctly capture the pngquant - < test.png command output to a variable?
 
     
    