How to create Windows icon with boolean transparency

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
eyebex
Posts: 10
Joined: 2012-06-16T12:33:28-07:00
Authentication code: 13

How to create Windows icon with boolean transparency

Post by eyebex »

Hi,

I'm using version 6.7.7-2 2012-06-15 Q16 on a Mac and am struggling to rasterize this vectors graphic to a 256x256 icon file with a color palette of 255 colors and 1 color reserved for boolean transparency. So far I'm using

Code: Select all

convert -colorspace sRGB -density 256x256 Git-Icon-1788C.eps -resize 256x256 -quantize transparent -colors 255 -transparent-color \#00000000 git.ico
but that results in a black background and rough edges of the logo. Also, some program (like Safari) only display the icon in black / white, so I suspect "-color 255" reduces the image to 2 instead of 255 colors (as there are only 2 distinct color in the image), and although there seems to be a palette, Safari cannot handle it.

I would not mind to get it working by converting to a GIF first (as IM seems to do the boolean transparency magic correctly in that case), however when doing

Code: Select all

convert -colorspace sRGB -density 256x256 Git-Icon-1788C.eps -resize 256x256 git.gif
convert git.gif git.ico
the GIF image looks fine, but the ICO file again has a black background (although the rough edges of the logo are gone).

Any hints how to get this right?

Note: I've edited my post to more correctly describe the behavior I'm seeing.
Last edited by eyebex on 2012-07-09T00:40:36-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to create Windows icon with boolean transparency

Post by fmw42 »

I am not an expert on ico, but try

convert -colorspace sRGB -density 256x256 Git-Icon-1788C.eps -resize 256x256 git.gif
convert git.gif -type palettematte git.ico
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to create Windows icon with boolean transparency

Post by whugemann »

At http://www.imagemagick.org/script/formats.php the ICON format is marked as read-only, thus I think that the writing support is very limited. I have tried to write icons with indexed colours with ImageMagick on my Windows computer, but failed too.
Wolfgang Hugemann
eyebex
Posts: 10
Joined: 2012-06-16T12:33:28-07:00
Authentication code: 13

Re: How to create Windows icon with boolean transparency

Post by eyebex »

whugemann wrote:At http://www.imagemagick.org/script/formats.php the ICON format is marked as read-only, thus I think that the writing support is very limited. I have tried to write icons with indexed colours with ImageMagick on my Windows computer, but failed too.
That's interesting because there's actually a tutorial on how to create favicons with IM.
eyebex
Posts: 10
Joined: 2012-06-16T12:33:28-07:00
Authentication code: 13

Re: How to create Windows icon with boolean transparency

Post by eyebex »

fmw42 wrote:convert -colorspace sRGB -density 256x256 Git-Icon-1788C.eps -resize 256x256 git.gif
convert git.gif -type palettematte git.ico
Thanks, that works, but I realized it in fact already worked before without "-type palettematte". It was my image viewer that was buggy and is not able to display boolean transparency for 1-bit icons correctly. Neither is Safari on Mac, is does not get the palette colors for 1-bit icons right and always assumes them to be black / white.

So, my remaining problem seems to be that a few programs cannot handle correctly the 1-bit color with indexed / boolean transparency ICO images that IM writes, and I'm searching for a way to force color depth to 8-bit. Will experiment with "-depth" and report back here later.
eyebex
Posts: 10
Joined: 2012-06-16T12:33:28-07:00
Authentication code: 13

Re: How to create Windows icon with boolean transparency

Post by eyebex »

eyebex wrote:Will experiment with "-depth" and report back here later.
It seems "-depth 8" has not effect when writing ICO files, they still are 32-bit :-(
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to create Windows icon with boolean transparency

Post by whugemann »

It seems "-depth 8" has not effect when writing ICO files, they still are 32-bit.
Well, that's what I said: I tried to write icons with indexed colours, but without success; -depth has no influence, neither has -colors 256. I have just tested the favicon example you mentioned, using rose: as the test image. It works, but also generates a full colour icon.
Wolfgang Hugemann
eyebex
Posts: 10
Joined: 2012-06-16T12:33:28-07:00
Authentication code: 13

Re: How to create Windows icon with boolean transparency

Post by eyebex »

Thanks for double-checking. I'm currently looking into using NConvert instead, and first tests seem to be promising.
Post Reply