An example of converting an image format to ico using python

  • 2020-12-26 05:48:35
  • OfStack

Because python needs to use ico image format when packaging, and there is no ico for the popular images on the Internet, so I find 1 python image format conversion method, completely solve this problem, I can easily achieve their own conversion in the future.

The code is as follows:


"""
Author : Robin , QI
Notes : Convert the image to ico format 
"""
 
# PythonMargick Packages can be to Unofficial Windows Binaries for Python Extension Packages download 
import PythonMagick
 
img = PythonMagick.Image('robin.jpg')
#  I'm going to set that 1 Size it, or it will be reported ico Size exception error 
img.sample('128x128')
img.write('robin.ico')

Related articles: