Page 1 of 1

Trim gif image

Posted: 2009-10-25T10:16:39-07:00
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

Re: Trim gif image

Posted: 2009-10-25T19:54:52-07:00
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

Re: Trim gif image

Posted: 2009-10-26T00:47:04-07:00
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

Re: Trim gif image

Posted: 2009-10-26T09:39:40-07:00
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)

Re: Trim gif image

Posted: 2009-10-26T09:51:21-07:00
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

Re: Trim gif image

Posted: 2009-10-26T15:02:30-07:00
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

Re: Trim gif image

Posted: 2009-10-26T15:18:27-07:00
by double
Hi fmw42,

:D
Thank you very much!
It works!

Marcus

Re: Trim gif image

Posted: 2009-10-26T19:02:09-07:00
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