English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article describes the method of changing the size of images in Python. Shared for everyone's reference, as follows:
1、Recommended PIL packagePillow 。
2、Source code:
#encoding=utf-8 #author: walker #date: 2014-05-15 #function: Change the size of the image import os import os.path from PIL import Image ''' filein: The input image fileout: The output image width: The output image width height: The output image height type: The 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)
Readers who are interested in more content related to Python can check the special topics on this site: 'Summary of Python Image Operation Skills', 'Python Data Structures and Algorithms Tutorial', 'Summary of Python Socket Programming Skills', 'Summary of Python Function Usage Skills', 'Summary of Python String Operation Skills', 'Classic Tutorial of Python入门与进阶', and 'Summary of Python File and Directory Operation Skills'.
I hope the content described in this article will be helpful to everyone in designing Python programs.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not undergo manual editing, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)