How to remove white frames from animated GIF?

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
pacificocean
Posts: 2
Joined: 2011-05-22T09:10:29-07:00
Authentication code: 8675308

How to remove white frames from animated GIF?

Post by pacificocean »

Hello!

I have been searching around for a while to an answer to this question.
I am trying to merge an animated gif and watermark and sometimes i get gif with white frames, like this:

Image

Other gifs are obtained normally, like this:

Image

Does anybody know how to make them without this white frames?
Thanks a lot!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to remove white frames from animated GIF?

Post by fmw42 »

What version of IM and what platform? Can you post a link to your cat animation gif and the watermark image? What is your exact command line?

It is very hard to know what the problem is without such information.
Last edited by fmw42 on 2011-05-22T16:48:51-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to remove white frames from animated GIF?

Post by anthony »

Your second animation looks fine to me. The first however...

It looks like an existing "transparency optimised" animation was incorrectly processed causing the optimization to become white!
OR the transparency index information was lost!

If the pure white is a unique color you could map that color to transparency,
Try this...
convert bad.gif -transparent white fixed.gif

Or use a lowlevel program like giftrans
http://www.ict.griffith.edu.au/~anthony ... /#giftrans
to find the white index and specify it as being transparent.

the latter will make the least impact on the animation but is harder to do

Hmmm that did not work right! the color is not always pure white, and the timings in the animation is horrible, relying on the web browser's minimal time sequence (bad idea). Display this in IM "animate" or some other GIF animator and you get the animation zipping through so fast it is all a blur!

The best idea is probably to unpack the animation into individual frames and animation meta-data using say "gif2anim"
http://www.imagemagick.org/Usage/scripts/gif2anim
fix each frame so the 'white' parts become transparent, the repack using the reverse "anim2gif"
http://www.imagemagick.org/Usage/scripts/anim2gif
examples of using this script is in IM examples, Animation Basics
http://www.imagemagick.org/Usage/anim_basics/#sequence
But is also used in Animation Modifications.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
pacificocean
Posts: 2
Joined: 2011-05-22T09:10:29-07:00
Authentication code: 8675308

Re: How to remove white frames from animated GIF?

Post by pacificocean »

anthony
Thank you very much! I'll try this!

fmw42
IM Version is 3.0.0, here is the code:

Code: Select all

       $im = new Imagick($filename);
       $im_width = $im->getImageWidth();
       $im_height = $im->getImageHeight();

       $wm = new Imagick(PATH.'/pikabu_logo.png');
       $wm_width = $wm->getImageWidth();
       $wm_height = $wm->getImageHeight();

       $x_offset = $im_width  - $wm_width;
       $y_offset = $im_height - $wm_height;

       foreach ($im as $frame) {
               $frame->compositeImage($wm, imagick::COMPOSITE_OVER,
$x_offset, $y_offset);
       }
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to remove white frames from animated GIF?

Post by fmw42 »

Still need your original cat animation and the watermark image as separate links, so that I or someone else can test in command line to regenerate you final animation.
Post Reply