Convert PNG to ICO with Pillow for Python Beginners – Python Tutorial

By | August 30, 2020

There exist many online png to ico convertors, however, this functionality is very easy in python. In this tutorial, we will introduce how to conver a png file to a ico file with python pillow library, you can learn and do step by step.

python pillow logo

Install Pillow

pip install Pillow

Load pillow library

from PIL import Image

Open a png image file

filename = r'logo.png'
img =

Convert png to ico file with pillow'logo16.ico',format = 'ICO', sizes=[(32,32)])

To use to convert png to ico, you must notice:, format=None, **params)


fname: it is the name of new image file

format: such as JPEG, ICO. You can know more formats in here.

sizes: if the image is ico, the (width, height) size may be [(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (255, 255)]