Python PIL | ImageOps.expand() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 ImageOps 模块包含许多“现成的”图像处理操作。这个模块有点实验性,大多数运算符只处理 L 和 RGB 图像。
ImageOps.expand()为调用或使用此函数的图像添加边框。
Syntax: PIL.ImageOps.expand(image, border = 0, fill = 0)
Parameters:
image : The image to size and crop.
border : The border to be applied to the image in pixels.
fill: This defines the pixel fill value or color value to be applied. The default value is 0 which means the color is black.
Returns: An image with the required border.
下面是ImageOps.expand()的实现
使用的图像:
Python3
# Importing Image and ImageOps module from PIL package
from PIL import Image, ImageOps
# creating a image1 object
im1 = Image.open(r"C:\Users\System-Pc\Desktop\a.jpg")
# applying expand method
# using border value = 20
# using fill = 50 which is brown type color
im2 = ImageOps.expand(im1, border = 20, fill = 50)
im2.show()
输出: