Question

We have an in-house tool that does some operations on windows icon files. Turns out that it only really supports the type of .ico files that are generated by ImageMagick. Should be no big deal because we currently use ImageMagick anyway to generate sizes not supplied in the original image. My plan was to always use ImageMagick to generate images, even when the original .ico file contained an image with the correct resolution, to ensure the image was of the correct format.

So far, so good. However in practice this does not seem to work the way I expect it to. Specifically I'm after a 256x256 icon. The original file contains (I believe) a 256x256 version as it looks high res when viewed from the browser. However, the output file from ImageMagick is obviously a low-resolution one scaled up.

The command line I'm using is:

convert.exe orig.ico -background #FFFFFFFFFFFF0101 -compose Copy \
-gravity Center -scale 256x256! -depth 8 temp2.ico

Question: is there some better set of commands to use, which might start from the 256x256 icon?

Was it helpful?

Solution

Your orig.ico file probably contains multiple dimensions. They will also be stored in the output file. This means a dimension of 16x16 will be upscaled to 256x256 and that produces an ugly image. The 256x256 resolution is most likely the first dimension. You can see all the dimensions with the following command:

identify.exe orig.ico

With the command below you can get a specific dimension/image by specifying the index (starts at zero):

convert.exe orig.ico[0] -background #FFFFFFFFFFFF0101 -compose Copy ^
-gravity Center -scale 256x256! -depth 8 temp2.ico

If the 256x256 dimension is the last image you should set the index to -1:

convert.exe orig.ico[-1] -background #FFFFFFFFFFFF0101 -compose Copy ^
-gravity Center -scale 256x256! -depth 8 temp2.ico
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top