Losing transparency while resizing GIF image

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
chru
Posts: 1
Joined: 2011-11-08T07:45:36-07:00
Authentication code: 8675308

Losing transparency while resizing GIF image

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Losing transparency while resizing GIF image

Post 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
wolverime
Posts: 3
Joined: 2012-07-18T06:41:59-07:00
Authentication code: 15

Re: Losing transparency while resizing GIF image

Post 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
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Losing transparency while resizing GIF image

Post by glennrp »

Using -sample instead of -resize works.
wolverime
Posts: 3
Joined: 2012-07-18T06:41:59-07:00
Authentication code: 15

Re: Losing transparency while resizing GIF image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Losing transparency while resizing GIF image

Post 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/
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Losing transparency while resizing GIF image

Post 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.
wolverime
Posts: 3
Joined: 2012-07-18T06:41:59-07:00
Authentication code: 15

Re: Losing transparency while resizing GIF image

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Losing transparency while resizing GIF image

Post 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.
Post Reply