imagemagickpngimagemagick-convertico

ICO file with PNG data


Looking at some ICO files that have PNG data instead of ICO and I am trying to create the same. Example:

$ identify sample.ico 

sample.ico[0] PNG 32x32 32x32+0+0 8-bit sRGB 884B 0.000u 0:00.000
sample.ico[1] PNG 16x16 16x16+0+0 8-bit sRGB 884B 0.000u 0:00.000

$ file sample.ico
sample.ico: MS Windows icon resource - 2 icons, 
32x32, 16 colors withPNG image data, 32 x 32, 8-bit/color RGBA, non-interlaced, 4 bits/pixel, 
16x16, 16 colors withPNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced, 4 bits/pixel

Playing around I have found I can do something like this to get PNG ICO:

$ convert icon-32x32.png png8:test1.ico
$ identify test1.ico

test1.ico PNG 32x32 32x32+0+0 8-bit sRGB 934B 0.000u 0:00.000

But if I use multiple input files I get multiple output files:

$ convert icon-16x16.png icon-32x32.png png8:test2.ico
$ ls -1 test2*

test2-0.ico
test2-1.ico

Not prefixing with png8: converts the data to ICO.

$ convert icon-16x16.png icon-32x32.png test3.ico
$ identify test3.ico 

test3.ico[0] ICO 16x16 16x16+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000
test3.ico[1] ICO 32x32 32x32+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000

If the file is too big for the ICO format, the PNG is "preserved":

$ convert ../icon-32x32.png ../icon-512x512.png test4.ico
$ identify test4.ico

test3.ico[0] ICO 32x32 32x32+0+0 32-bit sRGB 53.4KB 0.000u 0:00.000
test3.ico[1] PNG 512x512 512x512+0+0 8-bit sRGB 53.4KB 0.000u 0:00.000

How can I create a ICO file with PNG data for all sizes in ImageMagick?


Solution

  • Have not found any solution with imagemagick but one can use GIMP.

    Just create a layer for each size and export as file.ico.

    In options dialogue that appear check off Compress (PNG).

    One can also set bpp etc. For lower resolutions one can use for example: