PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The image module provides a class with the same name to represent the PIL image. The module also provides many features, including the ability to load images from files and create new images.

Image.resize () returns a resized copy of this Image.

Syntax: image. resize (size, resampling = 0)

Size – The size of the request, in pixels, is 2 tuples (width, height). Resampling – Optional resampling filter. This can be one of pil.image.nearest (using the NEAREST neighbor), Pil.image.bilinear (linear interpolation), Pil.image.bicubic (cubic spline interpolation) or Pil.image.lanczos (high quality downsampling filter). If omitted, or if the mode of the Image is “1” or “P”, set it to pil.image.nearest.

Return type: an Image object.

 

Input:

from PIL import Image  
im = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg")  
width, height = im.size  
  
left = 4
top = height / 5
right = 154
bottom = 3 * height / 5
im1 = im.crop((left, top, right, bottom)) 
newsize = (300, 300) 
im1 = im1.resize(newsize) 
im1.show()  
Copy the code

Output:

Welcome to pay attention to the official number: learning log of algorithm engineers, to obtain learning materials of algorithm engineers