Page 1 of 1

Converting different sized images into animated .gif

Posted: 2013-06-13T12:40:06-07:00
by deimos1090
Hi All,

I'm still pretty new to command line IM but have successfully used it for several projects already.

I am currently attempting to pull apart an existing animated gif, make some photo manipulations, and stitch it back together. In theory this should be easy. The problem that I am having is that I can successfully export all of the individual frames by using:

Code: Select all

convert c:/biggif/wip/fallingfromtop.gif c:/biggif/wip/wip2/%d.gif
but I cannot convert it back to a .gif with the below code without the below error:

Code

Code: Select all

convert -geometry 200% +repage -fuzz 3% +dither -colors 256 -despeckle -delay 6 -loop 0 c:/biggif/wip/wip2/wip3/*.gif -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/wip3_topfall.gif
Error
convert.exe: images are not the same size `' @ error/layer.c/OptimizeLayerFrames
/1020.
I have limited success if I simplify the convert back to animated gif but on playback each frame jumps around and appears to not be centered.

Code used with some sucess:

Code: Select all

convert canvas: c:/biggif/wip/wip2/wip3/*.gif -resize 500 -size 500x289 c:/biggif/wip/falling_processed.gif
I don't really understand what the problem is. The original animated gif that I took the frames from appears to play just fine. I ran an identify against the original gif and noticed that some frames within are different sizes:
c:/biggif/wip/falltobottom.gif[4] GIF 300x225 300x225+0+0 8-bit sRGB 128c 1.6
07MB 0.000u 0:00.069
c:/biggif/wip/falltobottom.gif[5] GIF 300x225 300x225+0+0 8-bit sRGB 128c 1.6
07MB 0.000u 0:00.083
c:/biggif/wip/falltobottom.gif[6] GIF 299x224 300x225+0+1 8-bit sRGB 128c 1.6
07MB 0.000u 0:00.093
c:/biggif/wip/falltobottom.gif[7] GIF 300x225 300x225+0+0 8-bit sRGB 128c 1.6
07MB 0.000u 0:00.099
c:/biggif/wip/falltobottom.gif[8] GIF 300x225 300x225+0+0 8-bit sRGB 128c 1.6
07MB 0.000u 0:00.104
c:/biggif/wip/falltobottom.gif[9] GIF 300x225 300x225+0+0 8-bit sRGB 128c 1.6
07MB 0.000u 0:00.110
c:/biggif/wip/falltobottom.gif[10] GIF 298x225 300x225+2+0 8-bit sRGB 128c 1.
607MB 0.000u 0:00.115
c:/biggif/wip/falltobottom.gif[11] GIF 300x225 300x225+0+0 8-bit sRGB 128c 1.
I'm pretty sure this is why I'm having trouble but nothing that I've been able to come up with has worked. I've tried to force the image size to be the same as all of the other images but the difference in px on the off frames are still there.

My brain is a bit fried, but does anyone have some ideas or help? Thank you,

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T13:07:28-07:00
by fmw42
convert c:/biggif/wip/fallingfromtop.gif c:/biggif/wip/wip2/%d.gif

but I cannot convert it back to a .gif with the below code without the below error:

convert -geometry 200% +repage -fuzz 3% +dither -colors 256 -despeckle -delay 6 -loop 0 c:/biggif/wip/wip2/wip3/*.gif -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/wip3_topfall.gif
I am not a Windows user, so others should feel free to correct my comments.


Several issues that I see:

1) your animation may already be optimized so each frame is not the same size. You need to separate them using -coalesce

2) When processing, the images need to be specified first in the command line and then processed. Also -geometry by itself does nothing and you are not even specifying its arguments properly. -geometry is a setting for an offset when compositing. You need to use -resize. Also -fuzz is a setting and has no operator to use it. I do not believe that -colors utilizes a fuzz value.

3) Windows needs % to be escaped as %%

Personally I would despeckle the image before resizing. But you can try both ways.

try something like this

Code: Select all

convert -delay 6 c:/biggif/wip/fallingfromtop.gif -coalesce ^
-resize 200%% +dither -colors 256 -despeckle ^
-layers OptimizePlus -layers OptimizeTransparency -loop 0 c:/biggif/wip/wip3_topfall.gif
or

Code: Select all

convert c:/biggif/wip/fallingfromtop.gif -coalesce ^
-resize 200%% +dither -colors 256 -despeckle MIFF:- | ^
convert -delay 6 - -layers OptimizePlus -layers OptimizeTransparency -loop 0

However, note that -delay 6 will probably be too small. Most browsers and other viewers put minimum limits on the delay that may be larger than 6.

See http://www.imagemagick.org/Usage/windows/

Also it is best to provide your version of IM and platform when asking questions, because answer may vary depending upon the IM version and/or platform. Also it would be a good idea to provide a link to your input image, so that others can test with it to be sure to give you a proper solution.

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T13:26:51-07:00
by deimos1090
Thanks fmw42.

I was actually just coming back to say I figured out the image sizing issue.

The working code ended up being:

Code: Select all

convert c:/biggif/wip/falltobottom.gif -coalesce c:/biggif/wip/wip2/wip3/%ddd.gif
I'll take a look at your other suggestions and see if I can bypass the sizing error. I've been using the same snippet of code because it gives me an expected result. I have no doubt that some of them are piped incorrectly. I'll move some stuff around as you outlined and let everyone know my progress.

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T13:37:22-07:00
by GreenKoopa
fmw42 wrote: I am not a Windows user, so others should feel free to correct my comments.

3) Windows needs % to be escaped as %%
When I was beginning with IM, I hated this one the most. Windows will try to do a variable expansion. The error is always different. Often there is no error, only unintended results. Also, this is only for batch files. On the command line or other type of script, only one % is needed. Now I'm wondering if IM minds there being an extra %. It probably depends on context.

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T14:19:15-07:00
by deimos1090
deimos1090 wrote:Thanks fmw42.

I was actually just coming back to say I figured out the image sizing issue.

The working code ended up being:

Code: Select all

convert c:/biggif/wip/falltobottom.gif -coalesce c:/biggif/wip/wip2/wip3/%ddd.gif
I'll take a look at your other suggestions and see if I can bypass the sizing error. I've been using the same snippet of code because it gives me an expected result. I have no doubt that some of them are piped incorrectly. I'll move some stuff around as you outlined and let everyone know my progress.
Running: 6.8.3-Q16

So I made more progress. With the coalesce and the images not freaking out anymore I properly stitched together an animated gif that fits my requirements. Below is the successful code with some changes as per fwm42:

Code: Select all

convert canvas:none -size 490x375 +repage -fuzz 3%% +dither -colors 256 -despeckle -delay 7 -loop 0 c:/biggif/wip/wip2/*.gif -resize 490 -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/AAAAA_Fall.gif
Although my result is "good enough" I still get an error:
convert.exe: images are not the same size `none' @ error/layer.c/OptimizeLayerFr
ames/1020.
The processing time for the .gif is also very quick, which leads me to believe that it is not optimizing properly. Other gifs take 3-4 minutes to process, in this instance it was only seconds.

I did make a change in my process flow however, I am now stitching together two different sized .gifs. One has a size of 500x289 while the other is 300x225. My code successfully resizes the both to a width of 490 (this is to keep size under 2MB, otherwise I wouldnt have touched it) but the heights are still different (aspect ratio was kept the same). I added the bit of canvas code to allow it to process both images together. Without it, only the frames with the smaller height would stitch into the final animated .gif.

Is the difference in heights the problem or is my image already super optimized? I can't believe it is since I coalesced them out of the original gif.

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T14:19:47-07:00
by deimos1090
GreenKoopa wrote:
fmw42 wrote: I am not a Windows user, so others should feel free to correct my comments.

3) Windows needs % to be escaped as %%
When I was beginning with IM, I hated this one the most. Windows will try to do a variable expansion. The error is always different. Often there is no error, only unintended results. Also, this is only for batch files. On the command line or other type of script, only one % is needed. Now I'm wondering if IM minds there being an extra %. It probably depends on context.
I used a single % and a %% with the same results.

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T14:25:21-07:00
by fmw42
convert canvas:none -size 490x375 +repage -fuzz 3%% +dither -colors 256 -despeckle -delay 7 -loop 0 c:/biggif/wip/wip2/*.gif -resize 490 -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/AAAAA_Fall.gif
I am not sure what you are trying to do, but specifying an background canvas here is not going to work. That image will be then includeing in your resulting gif animation. Furthermore you must specify -size before canvas. Also I said before -fuzz will do nothing here. Also the input image should be specified before the processing. Go back to my earlier post and review that again.

If you provide a link to your input image, perhaps we can be more specific in correcting your command line.

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T19:43:56-07:00
by deimos1090
fmw42 wrote:
convert canvas:none -size 490x375 +repage -fuzz 3%% +dither -colors 256 -despeckle -delay 7 -loop 0 c:/biggif/wip/wip2/*.gif -resize 490 -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/AAAAA_Fall.gif
I am not sure what you are trying to do, but specifying an background canvas here is not going to work. That image will be then includeing in your resulting gif animation. Furthermore you must specify -size before canvas. Also I said before -fuzz will do nothing here. Also the input image should be specified before the processing. Go back to my earlier post and review that again.

If you provide a link to your input image, perhaps we can be more specific in correcting your command line.
Fuzz actually does quite a bit to reduce my image size and the percentage modifies how aggressively it modifies the picture. If I set it to an extreme amount you cant even tell what is going on in the picture. Without fuzz my .gif is 3.6MB. With Fuzz at 3% it is 1.87 MB.

Putting the size before canvas had no visible impact on the output of the image. I will however continue to use it the way you outlined.

CODE FOR 3.6MB FILE

Code: Select all

convert -size 490x375 canvas:none +repage +dither -colors 256 -despeckle -delay 7 -loop 0 c:/biggif/wip/wip2/*.gif -resize 490 -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/AAAAA_CatFall.gif
CODE FOR 1.87MB FILE

Code: Select all

convert -size 490x375 canvas:none +repage -fuzz 3%% +dither -colors 256 -despeckle -delay 7 -loop 0 c:/biggif/wip/wip2/*.gif -resize 490 -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/AAAAA_CatFall.gif
Canvas also has to do something because if I do not include it, half of the .gif does not work.

CODE THAT CAUSES ONLY HALF OF THE GIF TO APPEAR

Code: Select all

convert -size 490x375 +repage -fuzz 3%% +dither -colors 256 -despeckle -delay 7 -loop 0 c:/biggif/wip/wip2/*.gif -resize 490 -layers OptimizePlus -layers OptimizeTransparency c:/biggif/wip/AAAAA_CatFall_withFuzzNoCanvas.gif
I'll add links to the pictures tomorrow, I can't do it right now.

Re: Converting different sized images into animated .gif

Posted: 2013-06-13T19:49:22-07:00
by fmw42
Did you use -coalesce? If not, then add that and remove the -size ... canvas: ...

Did you try this:

Code: Select all

convert -delay 7 c:/biggif/wip/fallingfromtop.gif -coalesce ^
-resize 200%% +dither -colors 256 -despeckle ^
-layers OptimizePlus -layers OptimizeTransparency -loop 0 c:/biggif/wip/fallingfromtop_new.gif
or

Code: Select all

convert c:/biggif/wip/fallingfromtop.gif -coalesce ^
-resize 490 +dither -colors 256 -despeckle MIFF:- | ^
convert -delay 7 - -layers OptimizePlus -layers OptimizeTransparency -loop 0 c:/biggif/wip/fallingfromtop_new.gif
Apparently, according to http://www.imagemagick.org/Usage/anim_opt/#color_fuzz, -fuzz affects -layers Optimize. Therefore, I stand corrected and you can put the -fuzz XX% in before the -layers command

You may also want to review this about the correct IM 6 syntax. http://www.imagemagick.org/Usage/basics/#why