2

My goal is to take an ico-image, like this wikipedia.ico and flip it vertically. My first attempt was

$ convert -flip wikipedia.ico flipped.ico

And it works, except that the resulting file flipped.ico is larger than the original:

$ identify wikipedia.ico 
wikipedia.ico[0] ICO 48x48 48x48+0+0 4-bit sRGB 2734B 0.000u 0:00.000
wikipedia.ico[1] ICO 32x32 32x32+0+0 4-bit sRGB 2734B 0.000u 0:00.000
wikipedia.ico[2] ICO 16x16 16x16+0+0 4-bit sRGB 2734B 0.000u 0:00.000

$ identify flipped.ico 
flipped.ico[0] ICO 48x48 48x48+0+0 8-bit sRGB 15086B 0.000u 0:00.000
flipped.ico[1] ICO 32x32 32x32+0+0 8-bit sRGB 15086B 0.000u 0:00.000
flipped.ico[2] ICO 16x16 16x16+0+0 8-bit sRGB 15086B 0.000u 0:00.000

Adding the flag -depth 4 does not help.

How can I do I get the exact same image, simply flipped?

Edit:

Thanks to Paolo Gibellini's answer, it got a smaller file flipped.ico. However, using -colors 16 -depth 4 still results in a file, that is much larger than the original:

$ convert -flip -colors 16 -depth 4 wikipedia.ico flipped.ico
$ ls -l flipped.ico wikipedia.ico
[...] 10734 May 14 21:05 flipped.ico
[...]  2734 May 14 09:41 wikipedia.ico
$ identify flipped.ico 
flipped.ico[0] ICO 48x48 48x48+0+0 8-bit sRGB 10734B 0.000u 0:00.009
flipped.ico[1] ICO 32x32 32x32+0+0 4-bit sRGB 10734B 0.000u 0:00.000
flipped.ico[2] ICO 16x16 16x16+0+0 4-bit sRGB 10734B 0.000u 0:00.000

I am running this on a debian pc. In the first line, there still seems to be some 8-bit image. Is there a way to have flipped.ico exactly the same size? Dos this really work on windows, as mentioned in the answer?

3

In order to get the flag -depth 4 work, you should use also the flag -colors with the desired color depth (in your case 16).

The following command should generate an icon with the same size of the original:

$ convert -flip -colors 16 -depth 4 wikipedia.ico flipped.ico

I have tested it on Windows (ImageMagick version 7.0.3-Q16) and the flipped icon has the same size of the original.

See also this forum.

-- Update --

I've tested the command above on a Debian machine (ImageMagick version 6.3.7-Q16) and on a CentOS machine (ImageMagick version 6.7.8-9-Q16), and in both cases I obtained an icon with the same size of the original (2734 bytes).

Just as reference, the output of different versions of identify is different.

identify 6.3.7

identify wikipedia.ico
wikipedia.ico[0] ICO 48x48 48x48+0+0 DirectClass 8-bit 2.66992kb
wikipedia.ico[1] ICO 32x32 32x32+0+0 DirectClass 8-bit 2.66992kb
wikipedia.ico[2] ICO 16x16 16x16+0+0 DirectClass 8-bit 2.66992kb

identify 6.7.8-9

identify wikipedia.ico
wikipedia.ico[0] ICO 48x48 48x48+0+0 4-bit DirectClass 2.73KB 0.000u 0:00.000
wikipedia.ico[1] ICO 32x32 32x32+0+0 4-bit DirectClass 2.73KB 0.000u 0:00.000
wikipedia.ico[2] ICO 16x16 16x16+0+0 4-bit DirectClass 2.73KB 0.000u 0:00.000

identify 7.0.3

identify wikipedia.ico
wikipedia.ico[0] ICO 48x48 48x48+0+0 4-bit sRGB 2.73KB 0.000u 0:00.000
wikipedia.ico[1] ICO 32x32 32x32+0+0 4-bit sRGB 2.73KB 0.000u 0:00.000
wikipedia.ico[2] ICO 16x16 16x16+0+0 4-bit sRGB 2.73KB 0.000u 0:00.000

Are you using an updated version of ImageMagick?

  • thanks, that is already an improvement! On my debian box however, the size of flipped.ico is still much larger. I will edit the question.. – Moritz Firsching May 14 '18 at 18:59
  • This is odd. When is possible I will test on a Debian machine. – Paolo Gibellini May 15 '18 at 7:32
  • That would be great! Did the test lead to any conclusion? – Moritz Firsching May 16 '18 at 7:25
  • I have updated the answer. – Paolo Gibellini May 16 '18 at 8:38
  • 1
    I had used version 6.9.9-39 Q16 in my question above. Now I have tried a different machine with version 6.9.7-4 Q16 and it worked flawlessly. Seems to be some sort of bug in my particular version. Also not that the flag depth 4 isn't even necessary; colors 16 is enough. Great answer! And thank you for trying on different machines to get me on the right track! – Moritz Firsching May 16 '18 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.