This example describes how Python implements changing the size of a picture. Share to everyone for your reference, as follows:
1, PIL package recommended pillow.
2. Source code:
#encoding =utf-8#author:walker#date:2014-05-15#function: Change the picture size import osimport os.pathfrom PIL import image ' Filein: Input image fileout: Output image width: Output image height: Output image altitude type: Output picture 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 = height = = ' png ' Resizeimage (Filein, fileout, width, height, type)
I hope this article is helpful for Python program design.