I know for a fact that quite a lot of people are using the convert command line utility from PHP using exec or similar execution function. Here is some (micro)benchmarks of using exec convert vs imagick extension. My test directory had 13 jpg images in it.
Here is the script i used with Imagick:
And the script I used with convert:
The scripts produce about identical result images. But the difference is the execution time:
Here is the execution time of the imagick script:
real 0m1.292s
user 0m1.010s
sys 0m0.260s
And the execution time of the convert script:
real 0m2.695s
user 0m2.160s
sys 0m0.510s
I used time php script.php to run these scripts and linux time utility to get the times. The times are ten run averages. It looks like if used from PHP the Imagick extension is about twice as fast as using the convert utility via exec.
THESE ARE MICROBENCHMARKS AND MIGHT NOT REFLECT A REAL WORLD SITUATION!
#1 by Kae Verens on October 7, 2007 - 8:50 pm
Quote
I use the exec() ImageMagick method in my KFM project (http://kfm.verens.com/). One reason I use it is that built-in extensions suffer from the memory limitations that PHP imposes on them, whereas a shell command appears to be unconstrained.
It is interesting that the imagick extension is faster, but how does it compare for very large images in a limited memory environment?
#2 by Mikko Koppanen on October 7, 2007 - 8:56 pm
Quote
To be honest, Imagick does not honor PHP memory limits. The memory allocations are (currently) done outside the PHP mechanisms.
I also wrote about memory limiting earlier: http://valokuva.org/?p=11
I’ve tested memory usages with Imagick using external tools and noticed that peak memory usage is not much over the size of the images you’re reading in to the object.
#3 by dsp on October 7, 2007 - 10:20 pm
Quote
It’s pretty clear that the exec is slower. It exec call results in a syscall which forks the convert executable. I guess the extension uses a similar (maybe equal) library than convert. So the time difference is more or less the time needed to fork and context-switch the convert exectuable.
#4 by Mikko Koppanen on October 7, 2007 - 10:39 pm
Quote
You could propably easily benchmark plain convert vs php exec difference using a shell script like:
#!/bin/bash
for i in /path/to/images/*.jpg
do
convert -thumbnail 200 $i /tmp/th/`basename $i`
done
#5 by Mikko Koppanen on March 8, 2008 - 8:02 pm
Quote
From Felix:
Just wanted to add that comment on http://valokuva.org/?p=40 but your wordpress seems not to want it
“For websites that deal with user generated images one thing is usually very common: Generating thumbnails from source images. Normally one would generate 3,5 or even 10 thumbnails per source image which we could dramatically speed up using Imagick. Instead of performing an exec() for each thumbnail to generate we now load the source image once into an Imagick object and do a “clone,thumbnailImage,cropImage,getImageBlob” sequence per thumbnail to generate. With that technique we have to load and decode the source image only once which gives us huge performance gains.”
#6 by dominik on July 27, 2009 - 6:54 pm
Quote
Nice try, but You missed several things:
+ algorithm (there is huge difference in both end-quality and time)
+ quality level (have You tried just to compare sizes)
Set those and You will get almost same time for both operation. Pay attention at cache etc. – they are sometimes tricky!
#7 by Mikko Koppanen on July 27, 2009 - 6:59 pm
Quote
dominik,
I thought “thumbnail” uses same algorithm in both since it’s not much more than a wrapper to resize. Quality level is also default in both (which i assume matches as well).
Pingback: Imagick blog » Blog Archive » Microbenchmarks: exec convert vs imagick