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?".
cssEXp

Animated gif

Post by cssEXp »

consider the following.

exec("montage -geometry +0+0 -background blue \( $image -resize {$width}x{$height}\! \) $save");

It's alright and well on all images except animated gif file. its not saving correctly. What could be the problem? and the above code has to be like that for a reason. i know i can resize with convert -resize. But as i said it has to be montage for a reason.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Animated gif

Post by fmw42 »

I am not an expert in this regard, but might it be more correct to use -resize ${width}x${height}? Note where the {} are located.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated gif

Post by anthony »

Also GIF animations are thought of as a image sequence. a montage of this will expand that sequence to the individual frames.
See http://imagemagick.org/Usage/anim_basics/#coalesce

Then -resize resizes images with little regard to animation optimizations. Unless an animation is at least coalesced to remove any frame optimizations that animation may have, -resize will have a very detrimental effect.
http://imagemagick.org/Usage/anim_mods/#resize

Finally you may like to look at my gif_anim_montage script
http://imagemagick.org/Usage/anim_basics/#montage
download from
http://imagemagick.org/Usage/scripts/gif_anim_montage
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cssEXp

Re: Animated gif

Post by cssEXp »

alright, now i have another problem regarding watermarking an animated gif with an image and/or another animated gif?

exec("composite -disolve 75% -gravity north-east -geometry +5+5 \"$watermark\" $image $watermarked_image");

the above doesn't seem to work right, any ideas?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated gif

Post by anthony »

You misspelt -dissolve ;-)
You may like to do some error output redirection so you can see what is going on. The RubbleWeb Examples PHP pages detail techniques for doing this.

Examples of using dissolve for watermarking can be found in IM examples, Annotating Images, watermarking...
http://imagemagick.org/Usage/annotating/#wmark_image

Other examples and methods are also shown.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cssEXp

Re: Animated gif

Post by cssEXp »

sorry i did use -dissolve in actual script, i made mistake when i retyped it here. Its working file with normal images, only problem with animated gif, i read somewhere composite can't handle animated images, i wonder if that's the problem?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated gif

Post by anthony »

yes it would be. Only one very new and recent addition (by me) allows multi-image composition either with two image lists, or with a static source or destination image.

For that you will need to pre-definine and pre-dissolve the overlay source image...

See IM examples, Animation Modifications, Layered Composition.
http://imagemagick.org/Usage/anim_mods/#composite

Actually a number of items in that page deails with overlaying watermark type images, either individually to each frame ,one and a time, or over all the whole animation sequence.

It really needs only a 'time disjoint animation merger' section to be completed for that whole set of example to be complete, but that requires another addition to the IM core library.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cssEXp

Re: Animated gif

Post by cssEXp »

great i can now watermark an animated image with another image, though can't watermark image with an another image animated image. But i can live with that :) here -dissolve doesn't seem to work.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated gif

Post by anthony »

As you will need to do the dissolve yourself, and you are probably watermarking a fully opaque image, I don't see why not.

Sure a GIF animation only allows boolean transparency, bu the -layers composition does not have that restriction. You just need to adjust the alpha channel of the GIF overlay in-memory (dissolve it), before composing it.

Something like this...

Code: Select all

convert image.jpg  null: \
     \( watermark_anim.gif  -coalease \
          -channel A -evaluate multiply .5 \) \
     -gravity SouthEast -layers composite   -layers Optimize \
     image_anim_wmark.gif
I have verified that this works, but do not have a good animated watermark to use. If you have a nice simple watermark to use, I would love it to use it to add an IM Example! Hey I don't even mind a small logo if you like a link to your site as a contributor!

A animated copyright symbol would be perfect!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cssEXp

Re: Animated gif

Post by cssEXp »

wait i want to make something clear, the "watermark_anim.gif" in your script, it is the overlaying image, yes? so can i watermark an image with an animated image? cause it didn't work that doing the following.

Code: Select all

exec("convert animated.gif -coalesce -gravity north-west -draw 'image over 5,5 0,0 \"animated_watermark.gif\"' watermarked_image.gif");
the above resulted in the animated image watermarked with the first frame of the animated watermark image, i figured can't watermark an image with an animated image, but reading your example here seems to suggest something else and more over you haven't said "no you can't watermark with an animated image" as a response to my question. So i assume I'm doing something wrong?

Anyway has the following to be done prior to watermarking or can it be done along with it?

Code: Select all

convert image.jpg  null: \( watermark_anim.gif  -coalease -channel A -evaluate multiply .5 \) -gravity SouthEast -layers composite   image_anim_wmark.gif
anyway to implement the above in to the following

Code: Select all

exec("convert animated.gif -coalesce -gravity north-west -draw 'image over 5,5 0,0 \"watermark.gif\"' watermarked_image.gif");
and don't forget to mention firmly whether if it's possible to watermark image with an animated watermark image. :)

i don't have any good animated image, I'm mainly doing this to learn about IM's functionality so that i'll be better prepared if i have to use it in future. So i'm just using some animated gif files found on google. :)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated gif

Post by anthony »

cssEXp wrote:wait i want to make something clear, the "watermark_anim.gif" in your script, it is the overlaying image, yes? so can i watermark an image with an animated image? cause it didn't work that doing the following.

Code: Select all

exec("convert animated.gif -coalesce -gravity north-west -draw 'image over 5,5 0,0 \"animated_watermark.gif\"' watermarked_image.gif");
ONLY the -layers composite method will handle proper multi-image composition, and that it does by using the 'trick' of seperating the two image lists with a special 'null:' image. ALL other composition methods are two images (+optional mask) alpha composition. The -draw is a special case which can only overlay a single 'source' image onto a list. It is thus LIMITED. (see later)

I added the -layers composite specifically to allow composition with animations, without needing a API to loop through each image pair one pair at a time!
Anyway has the following to be done prior to watermarking or can it be done along with it?
I assume the use of -evaluate to 'dissolve' a whole list of images.

All -dissolve is, is a function to multiply the alpha channel of the images being overlayed before they are overlaid. Similarly -blend, does that same thing but it then 'adds' the color channels of the images, rather than overlays them.

Neither image processing operation is particularly fancy, but are only available (historically) in the "composite" command, and that only deals with 2 images (+ optional mask), and never for a image sequence or animation.
anyway to implement the above in to the following

Code: Select all

exec("convert animated.gif -coalesce -gravity north-west -draw 'image over 5,5 0,0 \"watermark.gif\"' watermarked_image.gif");
and don't forget to mention firmly whether if it's possible to watermark image with an animated watermark image. :)
i don't have any good animated image, I'm mainly doing this to learn about IM's functionality so that i'll be better prepared if i have to use it in future. So i'm just using some animated gif files found on google. :)[/quote]

As I discuss on the IM examples, Animation Modification page, -draw can overlay a image against an image sequence, but only a single static 'source' image. Sure it can 'underlay' a source image under a list of images (see draw an image onto a list of images) BUT the animation will be the one to define the size of the final image, so will still need to be enlarged appropritally. This means it is not a particularly nice solution.

So the question comes down to. Are you IM version limited? that is can't you use -layers composite?

Also are you trying to watermark an animation?
Or use a animation as a watermark on a larger image?
Also do you have some SMALL examples I can use to demonstrate?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cssEXp

Re: Animated gif

Post by cssEXp »

Also are you trying to watermark an animation?
Or use a animation as a watermark on a larger image?
Also do you have some SMALL examples I can use to demonstrate?
I'm trying to watermark an animated image with another animated image, basically i want to be able to water mark an animated or static image with an animated or static image. also want to be able to set opacity of the watermark image.

these are the images I'm experimenting with.

Image

Image <--- water mark image

and windows xp default blue hills image. I believe i have the latest version of imagemagick, at least that's what hostgator claims.

i tried your script, doesn't seem work. Could you try it with the images i provided?
cssEXp

Re: Animated gif

Post by cssEXp »

kept experimenting and still not working.
cssEXp

Re: Animated gif

Post by cssEXp »

as i said before the following doesn't work,

Code: Select all

exec("convert $image null: \( \"$watermark\" -coalease -channel A -evaluate multiply .5 \) -gravity SouthEast -layers composite -layers Optimize $image");
setting that problem aside, how do i set opacity for the one with -draw, consider the following

Code: Select all

exec("convert $image -coalesce -gravity north-west -draw 'image over 0,0 0,0 \"$watermark\"' $image");
In the above case, you said i have to apply dissolve in memory, may i ask how? i'll be using the one with -draw if only the other doesn't work, in that case i'll settle for the non animated watermark image on static or animated image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animated gif

Post by anthony »

cssEXp wrote: I'm trying to watermark an animated image with another animated image, basically i want to be able to water mark an animated or static image with an animated or static image. also want to be able to set opacity of the watermark image.
Using a static image with a animated watermark, or a animaited image with a static watermark, is relativally easy.

however you will have a serious problem using an animated watermark with an animated image. That problem is time syncronization.

Unless the two animation has exactly the same timeing per frame the two will NOT merge together in a simple and easy way.

I discuss this problem in IM Examples, Animation modifications, at the very bottom of the page...
Merging Time Disjoint Animations
http://imagemagick.org/Usage/anim_mods/#merge

It also includes the basic solution that would be involved with such a problem, though this solution is, as yet, not built into IM.

After this, you then have a secondary problem I have only breifly touched on. Animation Optimization. such a time disjoint animation merger will likely cause the animation to have two seperate, part that are animating independantally from each other.

Splitting the Animation (resynchronization of the parts)
http://imagemagick.org/Usage/anim_mods/#split
is one solution.

The other is time synchronized split frame optimization, which I have also not looked at in IM examples, as yet.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply