Page 1 of 1

Problem converting PNG with transparent background to GIF

Posted: 2012-08-03T09:26:33-07:00
by masterofnone
Using ImageMagick-6.7.8-7-Q16-windows-dll

I have been trying to convert a small PNG image with a transparent background to a GIF image with a transparent background. I used this command structure:

convert -background none img.png img.gif

The result is a GIF image with a black background. However, if I reduce the color palette using:

convert -colors 4 -background none img.png img2.gif

I get the correct result, a GIF image with a transparent background.

Am I doing something wrong? Why would ImageMagick fill the background? And also, are there automatic settings to save the GIF with the indexed color palette? The quantization settings documentation specifies many options. Is there a shortcut or predefined group of settings?

Original PNG
Image

GIF with black background
Image

Correct result
Image

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-03T09:50:40-07:00
by fmw42
This indeed fails even with proper syntax:

convert 1emnwi.png 1emnwi.gif
convert 1emnwi.png -type palettealpha 1emnwi.gif

But this works fine for me on IM 6.7.8.7 Mac OSX Snow Leopard:

convert 1emnwi.png PNG8:1emnwi.gif

EDIT: the above command is nonsense and makes a png though labelled as gif suffix as pointed out by Glennrp below. So ignore this. I am not sure if any method works. I seem to recall a problem reported earlier about GIF smaller than 16x16, but cannot be sure.

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-03T10:49:11-07:00
by glennrp
But this works fine for me on IM 6.7.8.7 Mac OSX Snow Leopard:

convert 1emnwi.png PNG8:1emnwi.gif
But doesn't that end up with a PNG not a GIF? (use "identify -verbose 1emnwi.gif" to find out).

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-03T11:13:50-07:00
by fmw42
glennrp wrote:
But this works fine for me on IM 6.7.8.7 Mac OSX Snow Leopard:

convert 1emnwi.png PNG8:1emnwi.gif
But doesn't that end up with a PNG not a GIF? (use "identify -verbose 1emnwi.gif" to find out).
Glenn,

DOH! :oops: Sorry I must not have been fully awake. That was nonsense and I don't know what I was thinking.

Is the original issue related to a problem I seem to recall about GIFs smaller than 16x16?

Fred

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-03T11:18:58-07:00
by glennrp
fmw42 wrote: Is this related to a problem I seem to recall about GIFs smaller than 16x16?
Fred
Yes, it's very likely the same bug. If I do -sample 200% then the transparency is preserved in the GIF. ../glennrp

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-03T11:25:30-07:00
by fmw42
glennrp wrote:
fmw42 wrote: Is this related to a problem I seem to recall about GIFs smaller than 16x16?
Fred
Yes, it's very likely the same bug. If I do -sample 200% then the transparency is preserved in the GIF. ../glennrp

It is likely in the GIF writing. I tried converting to miff and piping to gif with the same bad results.

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-03T11:41:44-07:00
by glennrp
Interestingly, the GIF actually has one transprent pixel, at position 0,3. That doesn't help the original poster much,
but might give us something to think about while debugging this.

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-06T00:32:14-07:00
by masterofnone
glennrp wrote:
fmw42 wrote: Is this related to a problem I seem to recall about GIFs smaller than 16x16?
Fred
Yes, it's very likely the same bug. If I do -sample 200% then the transparency is preserved in the GIF. ../glennrp
So there is a pre-existing issue with images less than 16x16? That is good to know.

I suppose in the short term I could use GIMP to batch convert my files as it saves the ouput correctly and reduces the color pallette. It's just that in the long term I'd like to build a process that will do this and ImageMagick is defintely the right tool for the job.

Thanks for the help guys!

Re: Problem converting PNG with transparent background to GI

Posted: 2012-08-06T01:52:49-07:00
by masterofnone
I've found other, older, threads with the same issue.


Possible bug writing small .gif images
viewtopic.php?f=3&t=18463

Losing transparency while resizing GIF image
viewtopic.php?f=3&t=19787