I am trying to compress a jpg with mogrify (GraphicsMagicks) and i need to store the result in a variable.
$compressed_jpg_content = shell_exec("gm mogrify -quality 85 - < ".escapeshellarg($image_path)." $filename.jpg");
if (!$compressed_jpg_content) {
throw new Exception("Conversion to compressed JPG failed");
}
However its not working and i get Conversion to compressed JPG failed and i think there is a problem with my command
Edit
Thanks to Allen Butler
In this case $image_path is actually a POST variable and $filename is I4tWX0HI.jpg
Error : gm mogrify: Unable to open file (I4tWX0HI.jpg)
The error is pretty obvious since I4tWX0HI.jpg does not exist yet.That being said , how can i modify the command to make it put the content in the variable instead of trying to open a file
Regards
2>&1to the end of your command to convert standard error to standard out and echo outcompressed_jpg_contentto see that error for debugging. Try$compressed_jpg_content = shell_exec("gm mogrify -quality 85 - < .escapeshellarg($image_path)." $filename.jpg 2>&1"); echo $compressed_jpg_content;