Python image processing library PIL ImageOps notes

# 返回一个指定大小的裁剪过的图像。该图像被裁剪到指定的宽高比和尺寸。
# 变量size是要求的输出尺寸,以像素为单位,是一个(宽,高)元组
# bleed:允许用户去掉图像的边界(图像四个边界)。这个值是一个百分比数(0.01表示百分之一)。默认值是0(没有边界),最高0.5
# centering: 用于控制裁剪位置。
#     (0.5,0.5) 是裁剪中心(如果裁剪宽度,裁掉左侧50%(右侧50%),顶/底一样)。
#     (0.0,0.0) 将从左上角开始裁剪(如果裁剪宽度,将从右边裁剪掉所要裁剪的部分;如果裁剪高度,将从底部裁剪掉所要裁剪的部分)。
#     (1.0,0.0) 将从左下角开始裁剪(如果裁剪宽度,将从左边裁剪掉所要裁剪的部分;如果裁剪高度,将从底部裁剪掉所要裁剪的部分)




def fit(image, size, method=Image.Resampling.BICUBIC, bleed=0.0, centering=(0.5, 0.5)):
from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 上左
im0 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (0.0,0.0))
im0.save("./im0.png")

from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 下 右
im0 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (1.0,1.0))
im0.save("./im0.png")

from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 上右
im3 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (0.0,1.0))
im2.save("./im2.png")

 

from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 下左
im3 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (1.0,0.0))
im2.save("./im2.png")

reference:

Introduction to the ImageOps module of the Python image processing library PIL -----> Some basic image operations_The blog of the little turtle who practices monster fighting-CSDN blog

 PythonInformer - Image resizing recipes in Pillow

Guess you like

Origin blog.csdn.net/linzhiji/article/details/133016192