Step 1:
I am using exec to call a shell script which uses Imagemagick to manipulate an image and save it.
Step 2:
I am then creating an Imagemagick command to put the image from Step 1 onto another image.
Step 3:
I am then using passthrough to process and display the image from step 2
The problems I am having are:
Some images are not displayed at all and I get the box with the red cross
Some images have the same Step 1 image on two or three images in step 3
I am processing about 20 images and I assumed that the code was not finishing before starting again.
I tried putting a sleep(3) in different places but it did not seem to have any effect.
Can somebody let me know where I am going wrong and what I need to do to sort this problem?
<?php
$art = '';
$art = escapeshellcmd ( $_GET['art']);
// Default values for shell script
$radius = '52';
$pitch = '10';
$background = 'none';
$vertual_pixel = 'transparent';
$length = '130';
// Run the shell script to create the label - a tmpory image created but we will delete it later
exec(" /home/user/cylinderize -r $radius -l $length -p $pitch -b $background -v $vertual_pixel $art label.miff");
// Composite the label onto the bottle
$cmd = "convert blank.jpg label.miff -trim -gravity center -geometry +0+50 -composite +repage JPG:-";
// Display the image
header("Content-type: image/jpeg");
passthru($cmd, $retval);
// Delete the tempory label
unlink("label.miff");
?>
If it’s possible for more than one instance of this php script to be executing at the same time, you will problems, because they all share the same temporary file. Think about what would happen if one script is reading the file while another is in the middle of writing to it.
If you really need to use a temp file for the label, see tempnam() to make a unique one. If Imagemagick doesn’t like the file extension created, then other solutions exist.
You might not even need a tmp file though. I have no experience with that IM from the command line, but It might be able to read from stdin instead of a file. Then you can just pipe the output from the first command into the second, avoiding a tmp file altogether.
Thanks for the ideas crmalibu; I tried porting but I had problems getting the images into the correct order.
I then changed the name of the tempory image and it seems to be working OK now.