Creating a Windows icon file for "Devices and Printers"

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
AzJazz
Posts: 4
Joined: 2016-08-03T10:26:48-07:00
Authentication code: 1151

Creating a Windows icon file for "Devices and Printers"

Post by AzJazz »

Hi - I am trying to create a Windows 7 - compatible .ICO file that will be used in the "Devices and Printers" window. I am using the Windows Metadata Authoring Wizard (https://msdn.microsoft.com/en-us/librar ... s.85).aspx) that requires the ICO file to have multiple resolutions and bit depths.

The following icon resolutions and depths are required in the ICO file:
  • 256x256 32bit + Alpha
  • 48x48: 32bit + Alpha
  • 48x48: 8bit 256
  • 48x48: 4bit 16
  • 32x32: 32bit + Alpha
  • 32x32: 8bit 256
  • 32x32: 4bit 16
  • 24x24: 32bit + Alpha
  • 24x24: 8bit 256
  • 24x24: 4bit 16
  • 16x16: 32bit + Alpha
  • 16x16: 8bit 256
  • 16x16: 4bit 16
I tried to create an ICO using ImageMagick from my source PNG file, but I couldn't figure out the proper -clone and -colors options. It seemed like -colors could not be used in the -clone section.

I don't know if this is even the right route, but this is what I tried:

Code: Select all

convert image.png  ( -clone 0 -resize 256x256 ) ( -clone 0 -resize 48x48 ) ( -clone 0 -resize 48x48 -colors 256) ( -clone 0 -resize 48x48 -colors 16) ( -clone 0 -resize 32x32 ) ( -clone 0 -resize 32x32 -colors 256) ( -clone 0 -resize 32x32 -colors 16) ( -clone 0 -resize 24x24 ) ( -clone 0 -resize 24x24 -colors 256) ( -clone 0 -resize 24x24 -colors 16) ( -clone 0 -resize 16x16 ) ( -clone 0 -resize 16x16 -colors 256) ( -clone 0 -resize 16x16 -colors 16) -delete 0 -alpha remove favicon.ico
This resulted in the following error:

convert: unbalanced parenthesis `favicon.ico' @ error/convert.c/ConvertImageCommand/3248

Can anyone help with the Windows command line that would get me all the icon resolutions and bit depths listed above?

Thanks,

AzJazz
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Creating a Windows icon file for "Devices and Printers"

Post by snibgo »

Every parenthesis needs a space before and after it.
snibgo's IM pages: im.snibgo.com
AzJazz
Posts: 4
Joined: 2016-08-03T10:26:48-07:00
Authentication code: 1151

Re: Creating a Windows icon file for "Devices and Printers"

Post by AzJazz »

snibgo wrote:Every parenthesis needs a space before and after it.
Ah, thanks, snibgo!

That fixed the parenthesis error that I was seeing. Unfortunately, the command line apparently isn't generating the image formats that I need: Image

I was just experimenting on the command line values, based on what I found in these forums and the web. I guess the experiment "failed". :D

Also, the ICO file I generated didn't contain a 256x256 image, which I thought my first clone would generate. That wasn't working, even though there wasn't an error message for that.

Can anyone suggest what I should have for the command line to generate the required images and resolutions?

Thanks,

AzJazz
AzJazz
Posts: 4
Joined: 2016-08-03T10:26:48-07:00
Authentication code: 1151

Re: Creating a Windows icon file for "Devices and Printers"

Post by AzJazz »

Update:

Some stuff is working. I fixed the transparency errors, and I do see a 256x256 image now.

I now have these errors:

Image

I think that the -colors switch is not changing the bit depth the way that I expected.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Creating a Windows icon file for "Devices and Printers"

Post by GeeMack »

AzJazz wrote:I think that the -colors switch is not changing the bit depth the way that I expected.
Maybe try something ike this to set the bit depths on the layers...

Code: Select all

convert input.png -write mpr:iconimg +delete ^
   ( mpr:iconimg -resize 256x256 ) ^
   ( mpr:iconimg -resize 48x48 ) ^
   ( mpr:iconimg -resize 48x48 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 48x48 -depth 4 -colors 16 ) ^
   ( mpr:iconimg -resize 32x32 ) ^
   ( mpr:iconimg -resize 32x32 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 32x32 -depth 4 -colors 16 ) ^
   ( mpr:iconimg -resize 24x24 ) ^
   ( mpr:iconimg -resize 24x24 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 24x24 -depth 4 -colors 16 ) ^
   ( mpr:iconimg -resize 16x16 ) ^
   ( mpr:iconimg -resize 16x16 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 16x16 -depth 4 -colors 16 ) ^
      output.ico
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Creating a Windows icon file for "Devices and Printers"

Post by snibgo »

Is the input.png image exactly square? If it isn't, crop it to make it square before GeeMack's command.
snibgo's IM pages: im.snibgo.com
AzJazz
Posts: 4
Joined: 2016-08-03T10:26:48-07:00
Authentication code: 1151

Re: Creating a Windows icon file for "Devices and Printers"

Post by AzJazz »

GeeMack wrote: Maybe try something ike this to set the bit depths on the layers...

Code: Select all

convert input.png -write mpr:iconimg +delete ^
   ( mpr:iconimg -resize 256x256 ) ^
   ( mpr:iconimg -resize 48x48 ) ^
   ( mpr:iconimg -resize 48x48 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 48x48 -depth 4 -colors 16 ) ^
   ( mpr:iconimg -resize 32x32 ) ^
   ( mpr:iconimg -resize 32x32 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 32x32 -depth 4 -colors 16 ) ^
   ( mpr:iconimg -resize 24x24 ) ^
   ( mpr:iconimg -resize 24x24 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 24x24 -depth 4 -colors 16 ) ^
   ( mpr:iconimg -resize 16x16 ) ^
   ( mpr:iconimg -resize 16x16 -depth 8 -colors 256 ) ^
   ( mpr:iconimg -resize 16x16 -depth 4 -colors 16 ) ^
      output.ico
Thanks, Geemack & snibgo! That worked!

The new device image now appears in my "Devices and Printers" window.

Cheers,

AzJazz
Post Reply