PHP Image Benchmarks, GD Vs. Image Magick

    Earlier this week I ran into an issue resizing bitmap images inside of WorkXpress. We currently use GD for our image resizing needs. Unknown to us, GD has plenty of issues resizing bitmaps, and all of our bitmap files we becoming corrupted. I modified our resize code to use Image Magick if the image is a bitmap and continue using GD for other image types. The next step of course is to do some research and testing to see if we should switch over to Image Magick completely, leaving GD behind.

    After doing some research, I found plenty of claims that GD is faster than Image Magick. But how much faster? I was on a quest to find out. I took a rather large jpeg image (3504 x 2336 pixels) and converted it to three other popular formats, png, gif, and bitmap. I then wrote a script that resizes each one to 300 x 200 pixels (png shown below) using both GD and Image Magick. The script performs each resize 100 times and prints out the averages. I wanted to provide a working link to each format's resize code in action, but GoDaddy does not support Image Magick. The benchmark results were quite interesting, as seen below (results are in seconds).

Resized PNG

PNG
GD: 0.572078313828
Image Magick: 0.851119382381

JPEG
GD: 0.524123055935
Image Magick: 0.873931562901

GIF
GD: 0.497557456493
Image Magick: 1.15288033009

Bitmap
GD: 0.00230557203293 (Image Corrupted)
Image Magick: 0.523070528507

As you can see, GD out performed Image Magick by 48-131%, not including the bitmap results. So it looks like we'll be sticking with GD for now, with the exception of bitmaps.

Comments

Interesting results Jimmy; I did some similar tests and although I didn't run the images 100 times my results were opposite to yours.
Imagick can be faster than ImageMagick as it is built into php now.
GD failed with a memory error on images over a certain size but this could have been my server setup.

You can speed up resizing to jpg with a "hint"; depending on your IM version try:
convert -size 300x200 input_image -resize 300x200 output_image.jpg

Or ( I have not tried this )

convert -define jpeg:size=300x200 input_image -resize 300x200 output_image.jpg