Page 1 of 1

PNG to ICO preserve image depth

Posted: 2019-08-07T10:08:12-07:00
by 0x1
I'm currently struggling with convert function of ImageMagick.
I have a folder with various PNG files.
By various I mean each of them has different image bit depth and dimensions. Pretty standard for making a Windows ICO file.
In my command I specify this folder with my images and convert all to one PNG file.
On the output I get one ICO file with all the PNG files in it.

Everything is good except one crucial moment:
The image bit depth is not preserved. It becomes 32 bit on all the images inside the ICO.
This is a serious problem since Windows requires to have multiple similar icons with different image bit-depths.



What I want to do is to preserve original image bit depth and make all icons inside of the ouput .ico have their original depth. I have all the files with necessary bit depths, I just need to tell to IM to keep the original depths. The -depth does not work because:

ImageMagick has different "views" on the depth. The bit depth in Windows which is needed to be considered for ICO files is depth per image (I suppose), but in ImageMagick the bit depth is depth per channel.



I have found some relevant solutions but they all imply to manually set the necessary depth. This won't work because I need to avoid the manual changes and would like have a simple automation because I often work with extracting and packing ICO files and simply wanted to save time.

My current command works pretty well except the aforementioned issue that IM upconverts all different depths to 32 bit:

Code: Select all

convert Prepare\*.png Export\icon.ico
Is there a simple way to tell ImageMagick to take all properties of the source image and convert the image keeping the source properties? Or maybe there is some other way? I saw some recommendations to use "identify" but in my case probably multiple parameters are needed to be identified because as I said all the images I give to IM it considers them as 8 bit but in fact they are not. I probably just need to somehow keep all the source parameters and have all images in the converted ICO keep the same parameters.

If somebody could help to solve this issue I would really appreciate.


To see the bit depth, if you use Windows, click right mouse button, choose properties, open details tab.

I uploaded sample image. There are three same images with different image bit depths.
https://drive.google.com/drive/folders/ ... sp=sharing
0.png is 4 bit.
6.png is 8 bit.
13.png is 32 bit.

(If you think it would be a lot of work let me know as well.)