ImageOps.expand
时间: 2023-05-18 18:05:26 浏览: 139
pytorch中tensor.expand()和tensor.expand_as()函数详解
ImageOps.expand is a method in the Python Imaging Library (PIL) that is used to expand an image by adding borders around it. The method takes in an image and a border size as parameters and returns a new image with the specified border size.
Syntax:
ImageOps.expand(image, border, fill=None)
Parameters:
- image: The image to be expanded.
- border: The size of the border to be added around the image. It can be a single integer value or a tuple of four integers representing the left, top, right, and bottom borders respectively.
- fill: The color to be used for the border. It can be a single integer value or a tuple of three integers representing the RGB color values.
Example:
```
from PIL import Image, ImageOps
# Open the image
image = Image.open('image.jpg')
# Add a 20-pixel border around the image
border_size = 20
border_color = (255, 255, 255)
new_image = ImageOps.expand(image, border_size, fill=border_color)
# Save the new image
new_image.save('new_image.jpg')
```
In this example, we open an image and add a 20-pixel white border around it using the ImageOps.expand method. The new image is then saved as a new file.
阅读全文