Page 1 of 1

Imagemagick VS PHP : Create animated GIF much faster

Posted: 2011-11-22T10:59:44-07:00
by badabou
Hello,

Why Imagemagick is so long to create GIF animations ?

I use a parallel class coded in PHP that is much much faster to produce animated GIFs. While PHP is an interpreted language !

Is there an option when compiling Imagemagick ? A parameter to pass in the command line ? Some version of imagemagick, which would be faster ?

Thank you for your answers.

Re: Imagemagick VS PHP : Create animated GIF much faster

Posted: 2011-11-22T11:12:00-07:00
by magick
ImageMagick emphasizes the quality of the results over speed. ImageMagick uses a sophisticated color reduction algorithm (see http://www.imagemagick.org/script/quantize.php) which looks for an optimal color palette to best represent the colors in a GIF animation sequence. In general you get better results but with a cost in processing speed.

Post a URL to your GIF animation sequence. We'll download it and do some timing tests to see if the color reduction algorithm is the source of the slow-down.

Re: Imagemagick VS PHP : Create animated GIF much faster

Posted: 2011-11-22T14:21:41-07:00
by badabou
Here's an animated GIF created with imagemagick (its size is intentionally large -> 4 jpg):

# time convert -delay 20 -loop 0 *. jpg out_imagemagick.gif

real 0m12.793s
user 0m11.325s
sys 0m0.784s

The time to create this GIF is very long (the server uses is a 16 x 2Ghz AMD !).

Result: http://www.myspot.fr/test/out_imagemagick.gif

Even if I created this gif with class written in PHP is much faster, creating almost instant.

If I search only the rapid creation of GIF is there a way to speed up the treatment with imagemagick ?

Thank you

Re: Imagemagick VS PHP : Create animated GIF much faster

Posted: 2011-11-22T17:47:44-07:00
by magick
We get 2 seconds on our Intel 3GHZ chip. You can speed-up the results by reducing the quality with +dither -treedepth. For example, try +dither or -treedepth 4 -colors 256. If that is still too slow, consider a solution other than ImageMagick.

Re: Imagemagick VS PHP : Create animated GIF much faster

Posted: 2011-11-23T15:57:29-07:00
by badabou
Here are the original photos if you want to run a test: http://www.myspot.fr/test/photos.7z

I do not understand why this is so long, I use this version of imagemagick:
Version: ImageMagick 6.5.9-3 2011-11-23 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP
Is there a way to improve performance with multiple processor cores ? May be the compilation of a program option ? Allow the program to use more memory ?

Thank you

Re: Imagemagick VS PHP : Create animated GIF much faster

Posted: 2011-11-23T17:46:29-07:00
by fmw42
OpenMP is allowing IM to use multiple cores.

Did you try Magick's suggestion of adding either +dither or -treedepth 4 -colors 256 to your command line?

On my Mac mini OSX Tiger with 1 processor and IM 6.7.3.7 Q16 I get:


time convert 3.jpg 3.gif

real 0m16.957s
user 0m15.907s
sys 0m0.188s


time convert 3.jpg -treedepth 4 -colors 256 3c.gif

real 0m1.772s
user 0m1.642s
sys 0m0.077s


Thus a factor 8x speed improvement.

Also no obvious significant visual differences.


compare -metric rmse 3.gif 3c.gif null:
1982.75 (0.0302548)

So 3% rmse

Re: Imagemagick VS PHP : Create animated GIF much faster

Posted: 2011-12-03T10:24:21-07:00
by dognose
With OpenMP enabled i've found significant slowness as well. My workaround was to DOWNGRADE a package called libgomp from 4.4 to 4.1

I think that there is just something wrong with the thread scheduling in the newer version.... but, I really don't know.