Convert images to Icons is giving errors

Viewed 119

I'm converting images to icons using this code:

import PIL.image

img = PIL.Image.open ("imagepath.png")
img.save ("iconpath.ico")

This is giving me an icon file as desired, but when I try to open it an error pops up:
Paint:
Paint error
Microsoft photos error: Microsoft photos error

When I try to open other icons with the same programs they work perfectly, but it doesn't with the ones I made. Does anyone know any other way or library for doing this?

1 Answers

Try this:

img.save('iconpath.ico',format = 'ICO', sizes=[(32,32)])

You can change size to 16,16

First time I was converting image with PIL I've used this tutorial:

Tutorial

Everything worked fine.

The image that is being converted has to have a 1:1 proportion, if not, when trying to open the generated icon it will cause errors.

Related