Gif is generated slowly

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
dsl
Posts: 21
Joined: 2008-01-22T15:14:29-07:00

Gif is generated slowly

Post by dsl »

Hi,

My task is to generate gif animation from 3 images. Here they are:

http://www.picamatic.com/show/2011/08/0 ... 00x336.jpg
http://www.picamatic.com/show/2011/08/0 ... 00x336.jpg
http://www.picamatic.com/show/2011/08/0 ... 00x336.jpg

I use PerlMagick:

Code: Select all

my $gif = Image::Magick->new();
$gif->Set( page => "500x336", magick => "gif" );

for( my $i = 1; $i <= 3; $i++ ) {
 $gif->Read( "$i.jpg" );
}

for( my $i = 1; $i <= 3; $i++ ) {
 $gif->[$i-1]->Set( "dispose" => "Previous", "delay" => 10 );
}

$gif->Write("animation.gif");

And everything is fine except the writing file on disk.
"Write" function takes more than 5 sec, while everything else takes less than 1 sec.

Could you please help me with the advice is there any way to speedup writing on disk?
Or may be there is something wrong in code?

Thanks in advance!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Gif is generated slowly

Post by anthony »

The problem is you are going from a full color image (JPG), to a limited palette image (GIF).

That conversion needs a lot of work on IM's part to do a 'reasonable' job. That is read all the colors, reduce the number of colors to 256, recolor the image to use just those colors, in a way that visually simulates the larger variety of the original image.

The steps are looked at in detail in IM Examples, Quantization and Dithering
http://www.imagemagick.org/Usage/quantize/
and it is NOT a simple task, and even has a lot of options and methods that can improve things.

For GIF animations dithering individual images separately also produces extra problems of 'dither noise'!
see Video to GIF for a step-by-step guide...
http://www.imagemagick.org/Usage/video/#gif


From the look of these images, I would actually suggest a re-think on how you are generating the images!
The static frame in the middle can be dithered separately so that any dither noise remains static.
the outside frame can be drawn with limited colors and less gradient use, better suited to GIF images.

Does it have to be GIF? what is the final display mode?
A desktop digital frame could probably avoid the need for limit GIF all together.
A web page can use a java to cycle between the JPEG/PNG frames, to animate and again avoid GIF.

Finally the middle is not animated. You could split the animation into three parts. Left animations, static middle, right animation. That will reduce the complexity and let each part deal with the GIF limitations separately...
Also means you only need to generate the static middle (as a higher quality JPEG) for different images.
See splitting an animation
http://www.imagemagick.org/Usage/anim_mods/#split


PS: nice image of the Great Wall! I have a few myself, though I have not used them online, yet.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
dsl
Posts: 21
Joined: 2008-01-22T15:14:29-07:00

Re: Gif is generated slowly

Post by dsl »

Thank you, Anthony!

Your response is very detailed, as always
Though I still can't speed up the process of the gif generation.
But your response give me ideas to experiment.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Gif is generated slowly

Post by anthony »

I would like to go in and look at, and posibly expand the various methods and techniques used fro color quantization, and dithering. But I doubt I would have time any time soon.

On of the best pages I have seen on this problem, is
Joel Yliluoma's arbitrary-palette positional dithering algorithm
http://bisqwit.iki.fi/story/howto/dither/jy/

It goes into great details of the problems, though IM does have a harder task as it also looks at color reduction involving transparency, and more than 256 colors.

A small color table makes locating the nearest colors much faster, and is the source of much of the speed problems in IM. In fact by default IM does not do 'perfect color replacement' because of this speed problem.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply