Imagemagick VS PHP : Create animated GIF much faster

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
badabou
Posts: 54
Joined: 2008-06-23T06:12:24-07:00

Imagemagick VS PHP : Create animated GIF much faster

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick VS PHP : Create animated GIF much faster

Post 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.
badabou
Posts: 54
Joined: 2008-06-23T06:12:24-07:00

Re: Imagemagick VS PHP : Create animated GIF much faster

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick VS PHP : Create animated GIF much faster

Post 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.
badabou
Posts: 54
Joined: 2008-06-23T06:12:24-07:00

Re: Imagemagick VS PHP : Create animated GIF much faster

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Imagemagick VS PHP : Create animated GIF much faster

Post 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
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Re: Imagemagick VS PHP : Create animated GIF much faster

Post 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.
Post Reply