How to speed up GIF creation.

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
gfilkov
Posts: 4
Joined: 2019-07-25T11:49:45-07:00
Authentication code: 1152

How to speed up GIF creation.

Post by gfilkov »

Dear,

I am using Magick.NET-Q16-AnyCPU.dll version 7.12.0.0 in web app hosted in IIS
The app generates GIF using provided background image superimposed with number of smaller images (assets).
Assets are being scaled, rotated and positioned over background.
Typical background: 340x520 jpg.
Typical asset: 250x250 png.
Approximate number of assets - 100
Approximate number of frames - 60-80

Generation of GIF takes up to 2 minutes on the Azure app service.
I need to cut that time down al least to 30 seconds.

Please advise.
Thank you

User avatar
fmw42
Posts: 26261
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to speed up GIF creation.

Post by fmw42 »

GIFs take time to generate, since they have to be quantized to 256 colors or less. You might consider using one common color table for all frames.

Imagemagick's color quantization is slow but does a good job. You might be able to speed it up by using a different tree-depth. See https://imagemagick.org/script/command- ... #treedepth

gfilkov
Posts: 4
Joined: 2019-07-25T11:49:45-07:00
Authentication code: 1152

Re: How to speed up GIF creation.

Post by gfilkov »

Thank you for the prompt reply.
Yes, I am applying Quantize():

web.config
<add key="QuantizeColors" value="256" />

ImageMagick.QuantizeSettings settings = new ImageMagick.QuantizeSettings();
settings.Colors = quantizeColors; // from config
image.Quantize(settings);

Question:
I am compiling each frame by composing each asset on the frame.
Initially the frame is the clone of bkg image.

Will it be faster if the frame is initially set to transparent (empty) rectangle, and at the end, when all assets are placed on the frame, i compose the background image placing transparent-background frame on top of the background image?

User avatar
fmw42
Posts: 26261
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to speed up GIF creation.

Post by fmw42 »

Sorry, I cannot answer that. I do not use Magick.Net

gfilkov
Posts: 4
Joined: 2019-07-25T11:49:45-07:00
Authentication code: 1152

Re: How to speed up GIF creation.

Post by gfilkov »

Anybody around who knows Magick.NET ins and outs?

snibgo
Posts: 12894
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to speed up GIF creation.

Post by snibgo »

gfilkov wrote:Will it be faster if the frame is initially set to transparent (empty) rectangle, and at the end, when all assets are placed on the frame, i compose the background image placing transparent-background frame on top of the background image?
Why would it be faster? Placing the assets on a background image needs the same processing as on a transparent image, and then you would need an extra operation to place the result on the background. But you can test it to find out.

If you use the same assets and background on every frame, I assume you are not re-reading them. And I assume you are doing no other superfluous work.

EDIT to add: And I suppose you don't need floating-point, so have built IM without HDRI. Perhaps Q8 is sufficient.
snibgo's IM pages: im.snibgo.com

gfilkov
Posts: 4
Joined: 2019-07-25T11:49:45-07:00
Authentication code: 1152

Re: How to speed up GIF creation.

Post by gfilkov »

> Perhaps Q8 is sufficient
This is important, thank you!
I am still using Magick.NET-Q16-AnyCPU.dll, by inertia.

I have started with that lib, then had to cut down the size and color depth, trying to speed up my app, but did not change DLL.
I will change the lib and see how much it helped.

Thanks

Post Reply