Problems converting PNG to ICO

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dw415
Posts: 3
Joined: 2012-06-03T08:46:21-07:00
Authentication code: 13

Problems converting PNG to ICO

Post by dw415 »

I've been trying to convert a 16x16 PNG to ICO for use as a website favicon, but it never comes out right.

Code: Select all

convert favicon.png -colors 256 favicon.ico
Here is the input image file:
http://cure.org/img/favicon.png

The above command produces an ICO that shows as a solid-color green square in IE. So I thought maybe it is some sort of transparency or channels issue. I tried adding -flatten then -transparent white to no avail.

Code: Select all

$ convert -version
Version: ImageMagick 6.2.8 05/07/12 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems converting PNG to ICO

Post by fmw42 »

I don't know much about ico files, but try


convert 1favicon.png +matte -type palette 1favicon.ico


P.S it could be a bug in your version of IM. Version 6.2.8 is ancient. (Nearly 500 versions old).
dw415
Posts: 3
Joined: 2012-06-03T08:46:21-07:00
Authentication code: 13

Re: Problems converting PNG to ICO

Post by dw415 »

No luck with the suggested command. I tried all of the following commands under a newer ImageMagick:

Code: Select all

convert favicon.png favicon.ico
convert favicon.png -colors 256 favicon.ico
convert favicon.png -colors 256 -flatten favicon.ico
convert favicon.png -colors 256 -transparent white favicon.ico
convert favicon.png +matte -type palette favicon.ico
The ICO displays in popular web browsers either garbled or solid green.

Code: Select all

$ convert -version
Version: ImageMagick 6.6.9-7 2012-04-30 Q16 http://imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
dw415
Posts: 3
Joined: 2012-06-03T08:46:21-07:00
Authentication code: 13

Re: Problems converting PNG to ICO

Post by dw415 »

Actually it looks as though the last round of commands all worked. I was being fooled when testing by browser caching behaviors apparently. The ImageMagick version (CentOS 5 release) appears to have been the problem.

So the following command produced an ICO which displayed correctly in popular web browsers after using the newer ImageMagick 6.6.9-7:

Code: Select all

convert favicon.png favicon.ico
AlexMorse2016
Posts: 2
Joined: 2016-01-07T10:17:09-07:00
Authentication code: 1151

Re: Problems converting PNG to ICO

Post by AlexMorse2016 »

Ive got the ICO being output, but when I add in "-color 8", or "-color 16", it immediately starts showing a solid garbled background and bad aliasing. the icon looks good with this output, but I want to reduce the colors a bit more, to save file-size:

convert /icons/newstimes-01.png -define icon:auto-resize=16 /icons/new_favicon.ico

Any suggestions for how I can keep the transparency and aliasing looking good, but to also then reduce colors a bit?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems converting PNG to ICO

Post by fmw42 »

try -colors not -color
Post Reply