PIL is the most common image processing library in Python, the PIL module in Python 2.x, replaced with pillow module in Python 3.x, installing Pil:pip install Pillow
1, Python view some properties of the picture
#!/usr/bin/env python#-*-coding:utf-8-*-From PILImportImageimage= Image.Open("dora.jpg")#open a Picture objectPrint(Image.format)#view the format of the image with the result ' JPEG 'Print(image.size)#View the size of the picture, and the result is (800,450) pixels of width and height, respectivelyPrint(Image.mode)#View the mode of the picture, the result is ' RGB ', other modes are bitmap mode, grayscale mode, Duotone mode, etc.
2. Python Resize Image
# !/usr/bin/env python#-*-coding:utf-8-*- import= Image. Open ("dora.jpg") # Open a Picture object = Image.resize ((+)) # Adjust the picture to a width of 128 pixels, 128 pixels high
Out.show () # view pictures
:
3. Python Rotate Picture
# !/usr/bin/env python#-*-coding:utf-8-*- import= Image. Open ("dora.jpg") # open a Picture object out = image.rotate # rotate the picture counterclockwise 45 degrees out.show () # View pictures
:
4. Python Flip Picture
# !/usr/bin/env python#-*-coding:utf-8-*- import= Image. Open ("dora.jpg") # open a Picture object out = Image.transpose (image.flip_left_right) # Flip the picture around if you want to flip the argument up and down to ' Image.flip_top_bottom 'out.show () # View pictures
:
Python Processing Pictures