Page 1 of 1

[SOLVED] PNG to ICO while preserving transparency

Posted: 2014-09-16T06:39:36-07:00
by rzn1986
Hello,

I'm trying to convert a PNG file to a ICO file (favicon) while keeping the PNG transparency intact. I'm doing this with the sample code provided at http://www.imagemagick.org/Usage/thumbnails/#favicon.

This is my source image, a PNG24 file with transparency: http://www.feitjevandedag.nl/logo.png

This is the code I'm using:

Code: Select all

"C:\Program Files\ImageMagick\convert.exe" "C:\Program Files\ImageMagick\logo.png" -bordercolor white -border 0 ^ 
^( -clone 0 -resize 16x16 ^) ^ 
^( -clone 0 -resize 32x32 ^) ^ 
^( -clone 0 -resize 48x48 ^) ^ 
^( -clone 0 -resize 64x64 ^) ^ 
-delete 0 -background none favicon.ico
The problem is that the background is always white.

I've tried a lot of parameters like "-alpha set", "-alpha background" and tried it without the "-background none" but the background always remains white, setting "-alpha copy" actually makes the black parts transparent. Looking around the web, people claim removing the "-alpha off" from the sample code mentioned above should do the trick but I haven't gotten it to work yet.

I'm using ImageMagick-6.8.9-7-Q16-x64-dll (for Windows).

Any help is appreciated. :D

Re: PNG to ICO while preserving transparency

Posted: 2014-09-16T07:12:41-07:00
by dlemstra
Why do you need the '-bordercolor white -border 0' option? Removing this parameters seems to fix the problem. And in nieuwere versies of ImageMagick you can do what you are trying to do much easier:

Code: Select all

convert logo.png -define icon:auto-resize=64,48,32,16 logo.ico

Re: PNG to ICO while preserving transparency

Posted: 2014-09-16T07:31:31-07:00
by rzn1986
Thanks a lot dlemstra! :D

I didn't think that would help, too bad I didn't try it. I'm new to ImageMagick so still need to learn a lot, the code you posted works perfectly and is a lot easier.

You got some Dutch in between the English btw, "nieuwere versies", good thing I am Dutch. :lol:

Re: [SOLVED] PNG to ICO while preserving transparency

Posted: 2014-09-16T07:37:49-07:00
by dlemstra
That was added by accident :P

Re: [SOLVED] PNG to ICO while preserving transparency

Posted: 2016-01-07T10:20:10-07:00
by AlexMorse2016
This does preserve the transparency (from png with alpha trans), but when I add -color 8, to reduce colors, the background color comes back and the image is degraded badly. Is there a way to also reduce .ico file size when converting form a png? The PNG is 300bytes, but when exported by ImageMagick its back to 1500bytes. any suggestions?