I have the following code that seems to be generating a corrupted image. Photoshop says "PNG file corrupted by ASCII conversion"
$path_pngquant = "pngquant";
$status_code = null;
$image = null;
$output = null;
$image_input_escaped = escapeshellarg('test.png');
$command = "$path_pngquant --strip -- - < $image_input_escaped";
// Execute the command
exec($command, $output, $status_code);
if($status_code == 0)
{
//0 means success
$image = implode('', $output);
file_put_contents('test_2.png', $image);
}
exec will mess up the binary stream what you need is to open the output stream in binary mode read from it. Luckily popen is just for that
2>&1 is redirection syntax used in common shell scripts