Trim gif image

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
double
Posts: 14
Joined: 2009-10-25T10:12:06-07:00
Authentication code: 8675309

Trim gif image

Post by double »

Hello,

I can't trim a GIF image, the canvas remains 40x32 pixels. As a
result, all browsers show the image with 40x32 pixels.

What I did:
wget http://www.doppelbauer.name/test-40x32.gif
convert -trim +page test-40x32.gif /tmp/test.gif
identify /tmp/test.gif

Result:
test.gif GIF 30x28 40x32+0+4 8-bit PseudoClass 64c 7.8e+02b

Thanks
Marcus
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Trim gif image

Post by anthony »

You have hit a legacy option handling bug.
http://www.imagemagick.org/Usage/basics/#legacy

Read your image BEFORE trying to apply operations to it!

Code: Select all

   convert test-40x32.gif -trim +repage /tmp/test.gif
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
double
Posts: 14
Joined: 2009-10-25T10:12:06-07:00
Authentication code: 8675309

Re: Trim gif image

Post by double »

Hi Anthony,

Thank you very much for your answer.
But it does not work:

Code: Select all

wget http://www.doppelbauer.name/test-40x32.gif
convert smiley-monksmile-40x32.gif -trim +page test.gif

Code: Select all

identify test.gif
test.gif GIF 30x28 40x32+0+4 8-bit PseudoClass 64c 7.8e+02b
All browsers show the GIF 40x32 pixels, but not trimed.

Thanks
Marcus
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trim gif image

Post by fmw42 »

without seeing your image, it is hard to tell what is going on. can you post a link to an example of your images that do not trim.

if your image does not have a constant color along any given edge and inward, it will not trim. you need to add -fuzz to handle close colors.

see http://www.imagemagick.org/script/comma ... s.php#trim
also see http://www.imagemagick.org/Usage/crop/#trim

I believe to remove the virtual canvas, you need to add +repage per the above (not sure about +page)
double
Posts: 14
Joined: 2009-10-25T10:12:06-07:00
Authentication code: 8675309

Re: Trim gif image

Post by double »

Hi fmw42,

Thank you very much for your answer.
I have added an example, here again the link:

http://www.doppelbauer.name/test-40x32.gif

Thanks!
Marcus
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trim gif image

Post by fmw42 »

Your image has an alpha channel. So you have to enable that before trimming. try this.

convert test-40x32.gif -channel rgba -alpha on -trim +repage test-40x32_trim.gif
double
Posts: 14
Joined: 2009-10-25T10:12:06-07:00
Authentication code: 8675309

Re: Trim gif image

Post by double »

Hi fmw42,

:D
Thank you very much!
It works!

Marcus
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trim gif image

Post by fmw42 »

I stand corrected by Anthony, who says, the important thing is just the +repage. So this works fine for me

convert test-40x32.gif -trim +repage test-40x32_trim.gif
Post Reply