Okay, ... between the two of us, I think I've got it. Although "JPG:-" is right there in the manual, I simply did not understand, .... but that was the key for me (thanks!).
The reason that your example is not working is that the exec command requires an extra input if you want the output of the command returned; i.e., exec($cmd, $output, $retval). Your script should be:
Code: Select all
exec("convert photo7.jpg -fill rgb\(255,0,0\) -opaque rgb\(170,170,170\) JPG:-", $output, $retval);
The image data should now be in $output (note: $output and $retval are optional).
That won't actually work, though, as $output is an array filled with every line of output from the command (
minus line feeds, so invalid data). Using shell_exec, the return is a string, but I haven't figured out how to get that string displayed as an image yet (not even when using the Php GD lib functions - imagecreatefromstring and imagejpeg ??).
This, however, does work, but I would rather have the output returned as a string, (using shell_exec, for example), so I could check the retval before sending the Content-type header:
Code: Select all
// $photo is the path to the source file:
$THUMB_SZ = 125;
$THUMB_PRESZ = $THUMB_SZ * 2;
$QUALITY = 87;
$cmd = "convert.exe -size $THUMB_PRESZ".'x'."$THUMB_PRESZ \"$photo\"" .
" -resize $THUMB_SZ".'x'."$THUMB_SZ" .
" -strip" .
" -unsharp 0.2x0.6+1.0" .
" -quality $QUALITY JPG:-";
header("Content-type: image/jpeg");
passthru($cmd, $retval);
From the Php manual - "The passthru function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser."
If I figure out how to display the image after using another of the program execution functions so I can verify the output before sending the image header, I'll post back.
Chuck