how to resize 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
zxsz4084
Posts: 25
Joined: 2015-03-31T01:31:44-07:00
Authentication code: 6789

how to resize gif ?

Post by zxsz4084 »

I have a gif called game.gif 1.8mb,size 1024 × 768 ,can view at http://vi4.6rooms.com/live/chenlongtest/game.gif

Code: Select all

-bash-3.2$ identify game.gif
game.gif[0] GIF 1024x768 1024x768+0+0 PseudoClass 256c 1.7mb 
game.gif[1] GIF 293x244 1024x768+36+222 PseudoClass 256c 1.7mb 
game.gif[2] GIF 299x272 1024x768+36+198 PseudoClass 256c 1.7mb 
game.gif[3] GIF 337x350 1024x768+41+187 PseudoClass 256c 1.7mb 
game.gif[4] GIF 395x373 1024x768+26+184 PseudoClass 256c 1.7mb 
game.gif[5] GIF 396x373 1024x768+26+184 PseudoClass 256c 1.7mb 
game.gif[6] GIF 501x404 1024x768+25+184 PseudoClass 256c 1.7mb 
game.gif[7] GIF 525x442 1024x768+25+184 PseudoClass 256c 1.7mb 
game.gif[8] GIF 615x553 1024x768+2+124 PseudoClass 256c 1.7mb 
game.gif[9] GIF 646x558 1024x768+2+124 PseudoClass 256c 1.7mb 
game.gif[10] GIF 620x500 1024x768+28+184 PseudoClass 256c 1.7mb 
game.gif[11] GIF 602x500 1024x768+35+184 PseudoClass 256c 1.7mb 
game.gif[12] GIF 596x498 1024x768+41+185 PseudoClass 256c 1.7mb 
game.gif[13] GIF 254x113 1024x768+220+321 PseudoClass 256c 1.7mb 
game.gif[14] GIF 291x246 1024x768+287+219 PseudoClass 256c 1.7mb 
game.gif[15] GIF 297x272 1024x768+287+195 PseudoClass 256c 1.7mb 
game.gif[16] GIF 337x476 1024x768+289+184 PseudoClass 256c 1.7mb 
game.gif[17] GIF 394x474 1024x768+276+181 PseudoClass 256c 1.7mb 
game.gif[18] GIF 394x478 1024x768+277+181 PseudoClass 256c 1.7mb 
game.gif[19] GIF 500x479 1024x768+275+181 PseudoClass 256c 1.7mb 
game.gif[20] GIF 553x479 1024x768+275+181 PseudoClass 256c 1.7mb 
game.gif[21] GIF 623x553 1024x768+252+121 PseudoClass 256c 1.7mb 
game.gif[22] GIF 645x558 1024x768+252+121 PseudoClass 256c 1.7mb 
game.gif[23] GIF 621x500 1024x768+276+181 PseudoClass 256c 1.7mb 
game.gif[24] GIF 604x499 1024x768+284+182 PseudoClass 256c 1.7mb 
game.gif[25] GIF 594x498 1024x768+294+182 PseudoClass 256c 1.7mb 
game.gif[26] GIF 89x208 1024x768+426+143 PseudoClass 256c 1.7mb 
game.gif[27] GIF 293x244 1024x768+326+40 PseudoClass 256c 1.7mb 
game.gif[28] GIF 299x272 1024x768+326+16 PseudoClass 256c 1.7mb 
game.gif[29] GIF 337x350 1024x768+331+5 PseudoClass 256c 1.7mb 
game.gif[30] GIF 395x373 1024x768+316+2 PseudoClass 256c 1.7mb 
game.gif[31] GIF 396x373 1024x768+316+2 PseudoClass 256c 1.7mb 
game.gif[32] GIF 501x404 1024x768+315+2 PseudoClass 256c 1.7mb 
game.gif[33] GIF 530x458 1024x768+315+2 PseudoClass 256c 1.7mb 
game.gif[34] GIF 615x496 1024x768+292+0 PseudoClass 256c 1.7mb 
game.gif[35] GIF 646x500 1024x768+292+0 PseudoClass 256c 1.7mb 
game.gif[36] GIF 620x500 1024x768+318+2 PseudoClass 256c 1.7mb 
game.gif[37] GIF 602x500 1024x768+325+2 PseudoClass 256c 1.7mb 
I want to resize it to 980x735 ,so run like this:
convert -resize '980x735' +profile "*" -strip +repage game.gif game6.gif

can view at http://vi4.6rooms.com/live/chenlongtest/game6.gif

game6 is bigger than the old。
5.9M -rw-r--r-- 1 www www 5.9M Mar 31 15:22 game6.gif
1.8M -rw-r--r-- 1 www www 1.8M Mar 31 12:54 game.gif

Code: Select all

-bash-3.2$ identify game6.gif
game6.gif[0] GIF 980x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[1] GIF 883x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[2] GIF 808x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[3] GIF 708x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[4] GIF 778x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[5] GIF 780x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[6] GIF 911x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[7] GIF 873x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[8] GIF 817x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[9] GIF 851x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[10] GIF 911x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[11] GIF 885x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[12] GIF 880x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[13] GIF 980x436 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[14] GIF 869x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[15] GIF 803x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[16] GIF 520x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[17] GIF 611x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[18] GIF 606x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[19] GIF 767x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[20] GIF 849x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[21] GIF 828x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[22] GIF 850x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[23] GIF 913x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[24] GIF 890x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[25] GIF 877x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[26] GIF 314x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[27] GIF 883x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[28] GIF 808x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[29] GIF 708x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[30] GIF 778x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[31] GIF 780x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[32] GIF 911x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[33] GIF 851x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[34] GIF 911x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[35] GIF 950x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[36] GIF 911x735 980x735+0+0 PseudoClass 256c 5.9mb 
game6.gif[37] GIF 885x735 980x735+0+0 PseudoClass 256c 5.9mb
I don't know what the third column main? but it seems to be bigger than the old ,so the full gif become so big。
I want dashen help me to resolve this problem。thanks。。。
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to resize gif ?

Post by snibgo »

I'm not sure what you want.

See "animation" under http://www.imagemagick.org/Usage/

Each image in a gif file is typically a delta, just showing differences. Any operation on each delta is almost certainly not what you really want. You want to operate on each image as a proper, standalone image, like a real photograph.

To convert from deltas to "real" images, use "-layers coalesce" after reading the gif. To convert back to deltas, use "-layers optimize" before writing it.

Does that help?
snibgo's IM pages: im.snibgo.com
zxsz4084
Posts: 25
Joined: 2015-03-31T01:31:44-07:00
Authentication code: 6789

Re: how to resize gif ?

Post by zxsz4084 »

snibgo wrote:I'm not sure what you want.

See "animation" under http://www.imagemagick.org/Usage/

Each image in a gif file is typically a delta, just showing differences. Any operation on each delta is almost certainly not what you really want. You want to operate on each image as a proper, standalone image, like a real photograph.

To convert from deltas to "real" images, use "-layers coalesce" after reading the gif. To convert back to deltas, use "-layers optimize" before writing it.

Does that help?
Dear Dashen,
I am weak in english, I am very eggache even want to die when I see the documention about animation。
I just want to resize gif to a small size for preview 。
If you can help me ko this problem , I am very grateful。
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to resize gif ?

Post by snibgo »

Code: Select all

convert game.gif -layers Coalesce -resize 980x725 -layers Optimize g.gif
snibgo's IM pages: im.snibgo.com
zxsz4084
Posts: 25
Joined: 2015-03-31T01:31:44-07:00
Authentication code: 6789

Re: how to resize gif ?

Post by zxsz4084 »

snibgo wrote:

Code: Select all

convert game.gif -layers Coalesce -resize 980x725 -layers Optimize g.gif
Dear snibgo:
Maybe you are the hero I need。

-bash-3.2$ convert game.gif -layers Coalesce -resize 980x735 -layers Optimize g.gif
convert: geometry does not contain image `game.gif'.

warnning happen ?

2.8M -rw-r--r-- 1 www www 2.8M Mar 31 17:42 g.gif

still than the original pic and it works not well。

view at http://vi4.6rooms.com/live/chenlongtest/g.gif
clould you help me debug it ?thanks very much。
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to resize gif ?

Post by snibgo »

It works for me.

What version are you using? What does ...

Code: Select all

convert -version
... say?
snibgo's IM pages: im.snibgo.com
zxsz4084
Posts: 25
Joined: 2015-03-31T01:31:44-07:00
Authentication code: 6789

Re: how to resize gif ?

Post by zxsz4084 »

snibgo wrote:It works for me.

What version are you using? What does ...

Code: Select all

convert -version
... say?
Hi,snibgo:
Version: ImageMagick 6.2.8 05/07/12 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC

They are a litter different in animation effects。You can compare them。
http://vi4.6rooms.com/live/chenlongtest/game.gif
http://vi4.6rooms.com/live/chenlongtest/g.gif

if your result works well,can you give me “g.gif” to my email 200866700@qq.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to resize gif ?

Post by fmw42 »

ImageMagick 6.2.8 is ancient (very very very old). The current version is 6.9.1.0. So about 630 versions old. I expect that there have been many bug fixes and enhancements since then. I would recommend that you upgrade and keep current even if user snigbo's command works.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to resize gif ?

Post by snibgo »

I have renamed it and uploaded it to: http://snibgo.com/imforums/g_resized.gif

I agree with Fred: your version is very old. I suggest you upgrade.
snibgo's IM pages: im.snibgo.com
zxsz4084
Posts: 25
Joined: 2015-03-31T01:31:44-07:00
Authentication code: 6789

Re: how to resize gif ?

Post by zxsz4084 »

snibgo wrote:I have renamed it and uploaded it to: http://snibgo.com/imforums/g_resized.gif

I agree with Fred: your version is very old. I suggest you upgrade.
-rw-r--r-- 1 www www 2.1M Apr 1 10:26 g_resized.gif
You are all right。Your result is 2.1M ,but my result is 2.8M。I will upgrade it。

After reading documentation at “http://www.imagemagick.org/Usage/anim_mods/#resize” ,it says

Resize using Sample
To avoid generating extra colors when resizing the simplest way is to "-sample", the animation, rather than resizing it. This will preserve the current colors in the animation and allow you to easily re-optimize the animation at the new size.

convert script_k.gif -coalesce -sample 20x20 script_k_sample.gif

I use option sample instead of option resize。

convert game.gif -coalesce -resize 980x735 game_k.gif
convert game.gif -coalesce -resize 980x735 -layers Optimize game_k_op.gif
convert game.gif -coalesce -sample 980x735 -layers Optimize game_k_op_sample.gif
convert game.gif -coalesce -sample 234x176 -layers Optimize game_k_op_sample_s.gif

-rw-r--r-- 1 www www 1.8M Mar 31 12:54 game.gif
-rw-r--r-- 1 www www 2.6M Apr 1 09:59 game_k.gif
-rw-r--r-- 1 www www 2.2M Apr 1 10:11 game_k_op.gif
-rw-r--r-- 1 www www 1.7M Apr 1 10:22 game_k_op_sample.gif
-rw-r--r-- 1 www www 160K Apr 1 10:25 game_k_op_sample_s.gif

http://vi4.6rooms.com/live/chenlongtest ... sample.gif works well,even the smaller size http://vi4.6rooms.com/live/chenlongtest ... mple_s.gif

Maybe this solution is what I need that the resized picture is smaller than the original picture 。
Do you think so ?Maybe you have more better solution for me。Thanks。
zxsz4084
Posts: 25
Joined: 2015-03-31T01:31:44-07:00
Authentication code: 6789

Re: how to resize gif ?

Post by zxsz4084 »

to deal semi-transparent, I do like
"convert script_k.gif -coalesce \
-bordercolor LightSteelBlue -border 0 \
-resize 20x20 -layers Optimize script_k_thumbnail.gif"

convert game.gif -coalesce -bordercolor LightSteelBlue -border 0 -sample 234x176 -layers Optimize game_k_op_sample_s_t.gif

then it can works well show in emails or in safari browser.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to resize gif ?

Post by fmw42 »

GIFs do not support 9-bit (partial) transparency. They only support 1-bit transparency -- fully opaque or fully transparent pixels.

-border 0 means no border. Why are you doing that?
Post Reply