Page 1 of 1

add background on animated gif

Posted: 2013-07-23T11:20:10-07:00
by PeterO
Banner:
Image

Worm:
Image

When i add them together, the resulting image has a lot of Kb. (527 Kb)

Code: Select all

convert banner.gif null: worm.gif -layers composite -set dispose background -layers optimizePlus result.gif
When i use a white background it has the expected Kb (32 Kb)

Code: Select all

convert ( banner.gif -bordercolor #ffffff -border 0 ) null: worm.gif -layers composite -set dispose backgroun
d -layers optimizePlus test_out.gif
Does anybody has a clue how can i get the image with a transparent background and about 32Kb size?

Peter

Re: add background on animated gif

Posted: 2013-07-24T15:35:25-07:00
by fmw42
PeterO wrote:
Does anybody has a clue how can i get the image with a transparent background and about 32Kb size?

Peter
I tried adding -layers optimizeTransparency, but that did not seem to help.

Re: add background on animated gif

Posted: 2013-07-24T17:39:31-07:00
by anthony
If adding a static color background (white, transparency etc) the image will compress (very very well), however a non-static background will not compress very well.

However with the example
1/ You should ensure the animation is 'coalasced' before composition to remove any existing optimisations
2/ Use -layers Optimize before saving. That should include both frame optimization, and transparency optimization
3/ you do not need to set dispose is you are optimizing as that assumes the image is already coalesced.

I do not believe OptimizePlus will help this animation very much.

Code: Select all

convert banner.gif null: \( worm.gif -coalesce \) \
            -layers composite -layers optimize result.gif
BUT something is failing somewhere! as it is setting a disposal of 'none' when it is clear that the disposal of a should be background for at least some of the frames.

So this is working, though it is not optimized

Code: Select all

convert banner.gif null: \( worm.gif -coalesce \) \
             -layers composite -set dispose background result.gif

Something in the low level functions is really going wrong!

however after a bit of play and simple image warping I get this..

Code: Select all

   convert worm_banner.gif -trim +repage -resize 220x220\! null: \
               \( worm.gif -coalesce -gravity south -chop 0x1 \
                   -background none -wave 13x200 -shear 0x-4 \) \
               -gravity center -geometry +1-16  -layers composite \
               -layers optimizeframe worm_result.gif
Image
No optimization problems due to clean (from resize) and static transparency.

More exact image warping can be done by using a hand created distortion map.

Or perhaps a different order of rotations, wave and shears will get the worm to follow the banner more closely.
To at wave applied at an angle, rotate the image then apply wave, and rotate shear into place. What I did was just a quick 'try until you get reasonably close' iteration.

Alturnativally, leave the background, and resize - distort and mask the work onto the banner (-compose ATop). that way edges of the banner is left as is, worm animation is clipped to the banner, and as it is not involving boolean transparency, you get good anti-aliased edges to the worm!

Re: add background on animated gif

Posted: 2013-07-24T17:54:38-07:00
by fmw42
Anthony wrote:If adding a static color background (white, transparency etc) the image will compress (very very well), however a non-static background will not compress very well.
This seems to work (IM 6.8.6.6 Q16 Mac OSX) and results in 45 KB file size down from 451 KB

convert banner.gif null: \( worm.gif -coalesce \) \
-gravity center -layers composite -background black -alpha background \
-layers optimize result.gif

Re: add background on animated gif

Posted: 2013-07-24T18:04:19-07:00
by anthony
Problem seem to happen when you did not 'fix' the hidden transparency color!
It should not depend on transparency color! But it is!!!

Also see the update to my previous post!

Re: add background on animated gif

Posted: 2013-07-24T18:12:19-07:00
by fmw42
anthony wrote:Problem seem to happen when you did not 'fix' the hidden transparency color!
It should not depend on transparency color! But it is!!!

Also see the update to my previous post!
Neat improvement!

On my Safari browser, it blinks black every full cycle.

But this animation is over 600 KB, so you should fix the base color under the transparency to fix this for now so a smaller file size.


convert banner.gif -background white -alpha remove -trim +repage -resize 220x220\! \
null: \
\( worm.gif -coalesce -gravity south -chop 0x1 -background none -wave 13x200 -shear 0x-4 \) \
-gravity center -geometry +1-16 -layers composite \
-set dispose background -background black -alpha background -layers optimize result.gif

Cuts the file size to 74 KB and does not seem to blink for me.