Page 1 of 1

Losing transparency while resizing GIF image

Posted: 2011-11-08T08:38:54-07:00
by chru
With the current Version 6.7.3-4 a GIF image with a transparent background has a black background after resizing to 16x16. It worked well with Version 6.6.9-10 and also seems to work for dimensions larger than 16x16.

Can be verified with the image here: http://www.imagemagick.org/Usage/images/hand_point.gif

Code: Select all

convert hand_point.gif -resize 16x16 hand_point_16.gif
Thanks

Re: Losing transparency while resizing GIF image

Posted: 2011-11-08T10:46:45-07:00
by fmw42
I can confirm this problem with your image and others on IM 6.7.3.4 Q16 Mac OSX Tiger.

Resizing to 32x32 works fine on other images, but fails as described for 16x16 or 8x8.


convert logo: -transparent white logot.gif
convert logot.gif -resize 32x32 logot_32.gif
convert logot.gif -resize 16x16 logot_16.gif

Re: Losing transparency while resizing GIF image

Posted: 2012-07-18T06:54:41-07:00
by wolverime
I can confirm this behaviour in Versions 6.7.7-5/6.7.6-4 (gentoo) and 6.6.2-6 (ubuntu).
Converting a gif with transparency to a gif with less then 17px width/height results in a black gif.

convert 1x1.gif -resize 16x16 converted.gif -> Fails
convert 1x1.gif -resize 17x17 converted.gif -> Success

Re: Losing transparency while resizing GIF image

Posted: 2012-07-18T07:40:25-07:00
by glennrp
Using -sample instead of -resize works.

Re: Losing transparency while resizing GIF image

Posted: 2012-07-18T08:25:52-07:00
by wolverime
Thanks for the hint. I have to compare the results of resize and sample first before fixing our application.
Are there any well-known-but-poor-documented pitfalls when switching from resize to sample?

Re: Losing transparency while resizing GIF image

Posted: 2012-07-18T09:13:20-07:00
by fmw42
wolverime wrote:Thanks for the hint. I have to compare the results of resize and sample first before fixing our application.
Are there any well-known-but-poor-documented pitfalls when switching from resize to sample?
-sample will be faster but it just skips pixels to reduce the image. So it does not take into account all the pixels.

-scale will be faster, but it just averages blocks of pixels

Both the above can show artifacts, the latter showing blurring and the former aliasing or moire.

-resize does an interpolated resizing with various filter options. It will give the best looking results, but will be a bit slower.

see (esp. the last link below for greater detail)
http://www.imagemagick.org/script/comma ... f54#sample
http://www.imagemagick.org/script/comma ... .php#scale
http://www.imagemagick.org/script/comma ... php#resize
http://www.imagemagick.org/Usage/resize/

Re: Losing transparency while resizing GIF image

Posted: 2012-07-18T12:28:15-07:00
by glennrp
I didn't intend to recommend "-sample" as a permanent solution but just as a workaround and a clue as to what is going wrong with -resize and transparency.

Re: Losing transparency while resizing GIF image

Posted: 2012-07-19T01:40:02-07:00
by wolverime
Thanks, I already took a look at the docu.
I think, I'm going to choose a very pragmatic way and use -sample for all gif manipulations having a width < 17 px and leave the other transformations untouched :)
Maybe I can remove this workaround one day if this behaviour is fixed in newer IM versions.

Re: Losing transparency while resizing GIF image

Posted: 2012-07-19T07:21:46-07:00
by glennrp
Writing as PNG or TXT instead of GIF retains the transparency. Therefore the bug is probably in the GIF encoder.
I also tried converting to PNG8 and then converting the PNG8 to GIF. The PNG8 has GIF-style transparency but again it's
lost in the GIF.