Watermarking Animated Gifs

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
Ackergaul

Watermarking Animated Gifs

Post by Ackergaul »

Hello,
I just installed IMagick and was wondering if there is a way to watermark and resize animated gifs.

Best,
Ackergaul
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Watermarking Animated Gifs

Post by mkoppanen »

Hello,

sure! you just need to execute the operations on every frame:

Code: Select all


$im = new Imagick("test.gif");

foreach ($im as $frame) {
  
  // resize and watermark $frame here

}

$im->writeImages( ...

Mikko Koppanen
My blog: http://valokuva.org
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Watermarking Animated Gifs

Post by anthony »

If you want to compose on every frame you should be able to use the multi-image
CompositeLayers() function. This should take two images lists whcih it alpha composes together. if one of the images is only a single image that image is applied to ALL the images of the other list.

I implemented this for Command Line (-layers composite), but it should be available for other API's by this time.

WARNING: for GIF animations be sure to Coalesce the animation to remove any optimizations thet may be present, or unexpected results may occur.

After processing you can use the functions OptimizeImageLayers() for frame disposal optimization, and then OptimizeImageTransparency() for to make it compress better.

See the three sections on GIF Animations, in the Command Line API usage guide, IM Examples. They are recommended reading for anyone doing GIF animation work.
http://www.imagemagick.org/Usage/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply