Not quite programming but... Shrink size of animated GIF ?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

Not quite programming but... Shrink size of animated GIF ?

#1 Post by sunburnt »

I have an animated GIF I`d like to use as an avatar, but it`s 12.55 KB and only 6 KB is allowed.

What package for Puppy can shrink the KB size and maybe it`s pixel dimensions?
I don`t know what the pixel size is ( it`s not very big ), but it`s probably not correct.
Just shrinking it to the allowed 80 x 80 pixels may lower the KB size to under 6 KB.

User avatar
AF Branden
Posts: 165
Joined: Tue 15 Sep 2009, 10:17
Location: United States, WA

#2 Post by AF Branden »

[img]http://i56.tinypic.com/nwymax.png[/img]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#3 Post by technosaurus »

gifsicle
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#4 Post by sunburnt »

Thanks guys, I`ll try gifsicle first as it`s most likely smaller than gimp.

I`ll let you know what luck I have... Terry

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#5 Post by technosaurus »

I just added it to my optimizer collection

using
gifsicle --optimize=3 --use-colormap web input_file > output_file
Attachments
gifsicle-1.63-i486.pet
(91.84 KiB) Downloaded 249 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#6 Post by sunburnt »

Thanks technosaurus; I tried the Deb package from the web site and no go...
This is the info I got about the gif file:

Code: Select all

# gifsicle -I "#0" < /mnt/sdb3/docs/pics/Quake1_Flames.gif
* <stdin> 10 images
  logical screen 72x80
  global color table [16]
  background 0
  end comment This GIF file was assembled with GIF Construction Set from:\r\n\r\nAlchemy Mindworks Inc.\r\nP.O. Box 500\r\nBeeton, Ontario\r\nL0G 1A0\r\nCANADA.\r\n\r\nThis comment block will not appear in files created with a registered version of GIF Construction Set
  loop forever
  extensions 1
  + image #0 72x80
    delay 0.01s
I`m no expert, but it looks like there`s not much room for improvement?
The pixel size is good, could be trimmed to 72x72 if needed.
Maybe go to 4 colors? I don`t know what else to do.

I tried your command and it went from 12.5 KB to 9.5 KB, not enough.
Any further suggestions? I`m almost half way there!

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#7 Post by technosaurus »

I remember doing little tricks back in the 90s, like only using the diff for each frame, playing with the palette or even going monochrome (flames could be monochrome red & yellow vs black & white)
Sometimes shifting the image around, can get better results if it starts at a different point... algorithms & such
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#8 Post by sunburnt »

Can it do cropping? I figured it could be made about 54x72. YES IT WILL...
Wil the crop command do all 10 images?

And what`s the diff you mentioned? Is it a delta type compression that it`ll do?

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#9 Post by technosaurus »

not a diff exactly, I guess ... well actuall I guess it is ... a 2 dimensional (3 if you include color)
since the next image in a gif overlays the previous... no need to redraw all of sponge bob if he only moves his leg ... just the background of where his leg used to be and where it is now

... also - stripping the comments may take up to a Kb

gifsicle can do all of this:

Code: Select all

'Gifsicle' manipulates GIF images. Its most common uses include combining
single images into animations, adding transparency, optimizing animations for
space, and printing information about GIFs.

Usage: gifsicle [OPTION | FILE | FRAME]...

Mode options: at most one, before any filenames.
  -m, --merge                   Merge mode: combine inputs, write stdout.
  -b, --batch                   Batch mode: modify inputs, write back to
                                same filenames.
  -e, --explode                 Explode mode: write N files for each input,
                                one per frame, to 'input.frame-number'.
  -E, --explode-by-name         Explode mode, but write 'input.name'.

General options: Also --no-OPTION for info and verbose.
  -I, --info                    Print info about input GIFs. Two -I's means
                                normal output is not suppressed.
      --color-info, --cinfo     --info plus colormap details.
      --extension-info, --xinfo --info plus extension details.
  -V, --verbose                 Prints progress information.
  -h, --help                    Print this message and exit.
      --version                 Print version number and exit.
  -o, --output FILE             Write output to FILE.
  -w, --no-warnings             Don't report warnings.
      --conserve-memory         Conserve memory at the expense of speed.
      --multifile               Support concatenated GIF files.

Frame selections:               #num, #num1-num2, #num1-, #name

Frame change options:
  --delete FRAMES               Delete FRAMES from input.
  --insert-before FRAME GIFS    Insert GIFS before FRAMES in input.
  --append GIFS                 Append GIFS to input.
  --replace FRAMES GIFS         Replace FRAMES with GIFS in input.
  --done                        Done with frame changes.

Image options: Also --no-OPTION and --same-OPTION.
  -B, --background COL          Make COL the background color.
      --crop X,Y+WxH, --crop X,Y-X2,Y2
                                Crop the image.
      --crop-transparency       Crop transparent borders off the image.
      --flip-horizontal, --flip-vertical
                                Flip the image.
  -i, --interlace               Turn on interlacing.
  -S, --logical-screen WxH      Set logical screen to WxH.
  -p, --position X,Y            Set frame position to (X,Y).
      --rotate-90, --rotate-180, --rotate-270, --no-rotate
                                Rotate the image.
  -t, --transparent COL         Make COL transparent.

Extension options: Also --no-OPTION and --same-OPTION.
  -x, --app-extension N D       Add an app extension named N with data D.
  -c, --comment TEXT            Add a comment before the next frame.
      --extension N D           Add an extension number N with data D.
  -n, --name TEXT               Set next frame's name.

Animation options: Also --no-OPTION and --same-OPTION.
  -d, --delay TIME              Set frame delay to TIME (in 1/100sec).
  -D, --disposal METHOD         Set frame disposal to METHOD.
  -l, --loopcount[=N]           Set loop extension to N (default forever).
  -O, --optimize[=LEVEL]        Optimize output GIFs.
  -U, --unoptimize              Unoptimize input GIFs.

Whole-GIF options: Also --no-OPTION.
      --careful                 Write larger GIFs that avoid bugs in other
                                programs.
      --change-color COL1 COL2  Change COL1 to COL2 throughout.
  -k, --colors N                Reduce the number of colors to N.
      --color-method METHOD     Set method for choosing reduced colors.
  -f, --dither                  Dither image after changing colormap.
      --resize WxH              Resize the output GIF to WxH.
      --resize-width W          Resize to width W and proportional height.
      --resize-height H         Resize to height H and proportional width.
      --scale XFACTOR[xYFACTOR] Scale the output GIF by XFACTORxYFACTOR.
      --transform-colormap CMD  Transform each output colormap by shell CMD.
      --use-colormap CMAP       Set output GIF's colormap to CMAP, which can
                                be 'web', 'gray', 'bw', or a GIF file.

Report bugs to <ekohler@gmail.com>.
Too much information? Try 'gifsicle --help | more'.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#10 Post by sunburnt »

Not to be a pest, I looked at the help but I don`t see how to do either thing you suggested.

To strip the "end comment" what would I do?

Code: Select all

  end comment This GIF file was assembled with GIF Construction Set from:\r\n\r\nAlchemy Mindworks Inc.\r\nP.O. Box 500\r\nBeeton, Ontario\r\nL0G 1A0\r\nCANADA.\r\n\r\nThis comment block will not appear in files created with a registered version of GIF Construction Set
I assume if there were other comments it would show them in the info.

The diff thing sounds like some pixel editing on the 10 GIFs, will mPaint do this?

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#11 Post by sunburnt »

Thanks again technosaurus; Got a sized version to fit under 6 KB.

But if you know how to delete the end comment, or edit the GIF please tell me.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#12 Post by technosaurus »

for whatever reason gifsicle cannot strip the comments, but convert from imagemagick can

the other part is a real PITA on all but the most basic images, I don't know of a program that will just show the differing pixels ... would be a handy too ... it is the way most modern video compression technologies work ... webm does this based on an initial webp image
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#13 Post by jpeps »

technosaurus wrote:for whatever reason gifsicle cannot strip the comments, but convert from imagemagick can

the other part is a real PITA on all but the most basic images, I don't know of a program that will just show the differing pixels ... would be a handy too ... it is the way most modern video compression technologies work ... webm does this based on an initial webp image
I use a script "scale" that works with exactimage

example: 'scale old.png new.png 16'

Code: Select all

#!/bin/sh

if [ "$1" = "-h" -o "$1" = "" ]; then
   echo "example: 'scale old.png new.png 16'"
 exit
fi
OldSize=`edentify $1 | cut -d" " -f3| cut -d"x" -f1` 
size=`dc $3 $OldSize / p`  
econvert -i $1 --scale $size -o $2

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#14 Post by sunburnt »

Thanks jpeps; It looks like it sizes the gif which gifsicle already did.
To strip the comment would allow it to be sized a little larger, that`d be nice...

To create a diff gif I`m not sure would save space.
If the transparent parts had no color data then maybe it would.
Most of this animated gif is black, so maybe some space could be saved.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#15 Post by technosaurus »

I've been meaning to compile exactimage again.

I wonder if converting the animated gif to Webm and back would automatically do the pixel diff (iirc the pframes are full compressed images, but the iframes are only the parts that are changed ... not sure if my terminology is correct )
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#16 Post by sunburnt »

I understand what you mean, even if your terminology may not be correct.

Delta encodes the changed parts frame to frame starting from a full key frame.

For my icon changing parts are just the flames which is 1/3 to 1/2 of the icon.
So as I said, if the color info is not there for the static parts then a smaller size.

Don`t know the icon format setup, I`d think a color for each pixel in a grid.
So then it`d be hard to see how a Delta encoding could be applied to it.
However the icon`s format may allow for many other possible methods.

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#17 Post by GatorDog »

Hi Sunburnt,

I grabbed you existing gif avatar. Googled a little and played with Imagemagick.
This converts the .gif to seperate .bmp frames. (.bmp doesn't support comments) ;)

Code: Select all

convert sunburnt.gif -scene 1 +adjoin  frame_%02d.bmp
This puts the frames back together.

Code: Select all

convert frame_*.bmp -depth 16 -colors 8 -delay 100 -loop 0 new.gif
Original: 6119B Converted: 3728B

Removing the comments didn't reduce size that much, but if you were really close
it might be the difference in coming in under the wire.

In a blindfold test, I don't think I could tell the difference between the two gifs. :P
rod

Also, "identify -verbose filename.gif" will give all sorts of info. Like the timing dalay,
show the comments, number of colors, etc...
Attachments
new.gif
(3.64 KiB) Downloaded 196 times

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#18 Post by sunburnt »

Thanks GatorDog; I didn`t think the comment took much space.

The gif is pretty good, but it`d be nice if it were bigger.

Only a different data encoding format will shrink the size now I think.

There may be other animated icon formats that this forum will accept.???

Post Reply