Every user will be able to upload 100 TIFF (black and white) images.
The process requires:
1.Convert tif to jpg.
2. Resize image to xx.
3. Crop image to 200px.
4. Add a text watermark.
Here is my PHP code:
move_uploaded_file($image_temp,$destination_folder.$image_name);
$image_name_only = strtolower($image_info["filename"]);
$name=$destination_folder.$image_name_only.".jpg";
$thumb=$destination_folder."thumb_".$image_name_only.".jpg";
$exec = '"C:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" '.$destination_folder.$image_name. ' '.$name.' 2>&1';
exec($exec, $exec_output, $exec_retval);
$exec = '"C:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" '.$name. ' -resize 1024x '.$name;
exec($exec, $exec_output, $exec_retval);
$exec = '"C:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" '.$name. ' -thumbnail 200x200! '.$thumb;
exec($exec, $exec_output, $exec_retval);
$exec = '"C:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" '.$name. " -background White label:ش.پ12355 -append ".$name;
exec($exec, $exec_output, $exec_retval);
This code works. But the average processing time for every image is 1 second. So for 100 images it will probably take around 100 seconds.
How can I speed up this whole process (convert, resize, crop, watermark)?
EDIT
I have a Server G8:Ram:32G,CPU:Intel Xeon E5-2650(4 Process)
version:ImageMagick 6.9.0-3 Q16 x64
FEATURES:OpenMP
convert logo: -resize 500% -bench 10 1.png
Performance[1]: 10i 0.770ips 1.000e 28.735u 0:12.992
Performance[2]: 10i 0.893ips 0.537e 26.848u 0:11.198
Performance[3]: 10i 0.851ips 0.525e 27.285u 0:11.756
Performance[4]: 10i 0.914ips 0.543e 26.489u 0:10.941
Performance[5]: 10i 0.967ips 0.557e 25.803u 0:10.341
Performance[6]: 10i 0.797ips 0.509e 27.737u 0:12.554
Performance[7]: 10i 0.963ips 0.556e 25.912u 0:10.389
Performance[8]: 10i 0.863ips 0.529e 26.707u 0:11.586
Resource limits:
Width: 100MP;Height: 100MP;Area: 17.16GP;Memory: 7.9908GiB;Map: 15.982GiB;Disk: unlimited;File: 1536;Thread: 8;Throttle: 0;Time: unlimited
How to speed up a complex image processing?
-
- Posts: 2
- Joined: 2015-02-24T21:37:30-07:00
- Authentication code: 6789
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to speed up a complex image processing?
Do all the command in one convert call. See http://www.imagemagick.org/Usage/basics/#parenthesis. There is no reason to convert to jpg until the end. Also why do you need to do -resize and then -thumbnail. You can do just one and either crop or pad to the size you want. See http://www.imagemagick.org/Usage/thumbnails/#pad and http://www.imagemagick.org/Usage/thumbnails/#cut
If I assume you want to crop, then:
Or just write the text over the bottom of the image:
Do not use ! when using -resize or thumbnail or it will distort your image. Use the ^ to with -thumbnail so that the image will be 200 on one dimension and a bit bigger on the other dimension. Then the extent to 200x200 will crop to that exact size. On Windows, you may need to escape the ^ with ^^.
Put the above command into your PHP exec() command. Try that and see if it is faster
If I assume you want to crop, then:
Code: Select all
convert image.tif -thumbnail 200x200^ -gravity center -extent 200x200 -fill yourfontcolor -font yourfont -pointsize yourpointsize -background white label:"yourtext" -append result.jpg
Code: Select all
convert image.tif -thumbnail 200x200^ -gravity center -extent 200x200 -fill yourfontcolor -font yourfont -pointsize yourpointsize -gravity south -annotate +0+0 "yourtext" result.jpg
Put the above command into your PHP exec() command. Try that and see if it is faster
-
- Posts: 2
- Joined: 2015-02-24T21:37:30-07:00
- Authentication code: 6789
Re: How to speed up a complex image processing?
thanks for replay
.
i want convert tif to jpg and then resize jpg to 733*x and set watermark on and then create new thumbnile 200*200 from jpg
but your code create a thumbnile 200 only
.
i want convert tif to jpg and then resize jpg to 733*x and set watermark on and then create new thumbnile 200*200 from jpg
but your code create a thumbnile 200 only
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to speed up a complex image processing?
If you convert to jpg first, you will lose quality, since you will convert again to jpg later.
Re: How to speed up a complex image processing?
So you want a larger jpg file and then a thumbnail that is watermarked?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to speed up a complex image processing?
If this is what you want, then do the resize and write to result.jpg, then continue the processing to get the thumbnailBonzo wrote:So you want a larger jpg file and then a thumbnail that is watermarked?
Code: Select all
convert image.tif -resize 1024x +write result.jpg -thumbnail 200x200^ -gravity center -extent 200x200 -fill yourfontcolor -font yourfont -pointsize yourpointsize -background white label:"yourtext" -append thumb.jpg