This article mainly introduces how to change the image size using Python, and analyzes how to change the image attributes using the Pillow package in the form of examples, for more information about how to change the image size in Python, see the following example. We will share this with you for your reference. The details are as follows:
1. Pillow is recommended for the PIL package.
2. source code:
# Encoding = UTF-8 # author: walker # date: # function: change the image size import osimport OS. pathfrom PIL import Image ''' filein: input Image fileout: output Image width height: output Image height type: output Image type (png, gif, jpeg ...) '''def ResizeImage (filein, fileout, width, height, type): img = Image. open (filein) out = img. resize (width, height), Image. ANTIALIAS) # resize image with high-quality out. save (fileout, type) if _ name _ = "_ main __": filein = r 'image \ test.png 'fileout = r'image \ testout.png' width = 60 height = 85 type = 'PNG 'ResizeImage (filein, fileout, width, height, type)
I hope this article will help you with Python programming.
For more information about how to change the image size in Python (based on the Pillow package), see PHP!