point of knowledge (math.)
- Image Module ()
Functions of the Image module
Methods of the Image module
- ImageChops module
- ImageColor module
Basic use
image module
Load an image object, rotate it 90 degrees and display it
from PIL import Image #Display Image im = ('') () # Convert the image 90 degrees (90).show()
Create Thumbnail 128x128
from PIL import Image import glob, os size = 128, 128 for infile in ('D:\code\gitee\pydata\python3-example\pillow_demo\*.jpg'): print(infile) filename = (infile)[-1] im = (infile) (size, ) ("D:\code\gitee\pydata\python3-example\pillow_demo\\" + filename)
Create a new image with a resolution of 1920*1080
from PIL import Image im = ('RGB', (1920, 1080), (255, 0, 0)) im1 = ('RGB', (1920, 1080), 'red') im2 = ('RGB', (1920, 1080), '#FF0000') ()
Convert images to PNG
im = ('', 'r') ('') () im_png = ('', 'r') print(im_png.format)
ImageChops module
The ImageChops module contains several arithmetic image operations, called channel operations, which enable, among other things, special effects, image compositing, algorithmic painting, and more!
It functions Most channel operations use one or two image parameter comparisons to return a new image, and only some common methods are listed below:
(image1,image2): compares the two images pixel by pixel and returns the new image containing the brighter values
from PIL import Image from PIL import ImageChops im1=('') im2=('') IC_image=(im1,im2) IC_image.show()
ImageColor module
ImageColor module is used to implement the RGB color table conversion, it supports is the color format includes:
- Hexadecimal color descriptor, e.g., "#ff0000" specifies solid red.
- RGB functions, given as "rgb(red, green, blue)", where the color value is an integer in the range 0 to 255, e.g., "rgb(255,0,0)" and "rgb(100%, 0%, 0%)". 0%, 0%)
- Common HTML color names, e.g., "red" designates solid red
getrgb(color): convert color string to RGB tuple
from PIL import ImageColor IC_image=('red') print(IC_image) # (255, 0, 0)
The above is the basic use of python pillow library tutorial details, more information about the use of python pillow library please pay attention to my other related articles!