Python PIL Image.new(): Create New Images with Specified Mode and Size
The PIL.Image.new() function in Python is used to create a new image with a specified mode and size.
Syntax:
PIL.Image.new(mode, size, color)
Parameters:
mode: The mode of the image. Examples include 'RGB' for a 3-channel color image, 'L' for a grayscale image, 'RGBA' for a color image with transparency, etc.size: The size of the image, specified as a tuple of (width, height) in pixels.color(optional): The base color of the image. This parameter is only used for certain modes like 'RGB' and 'RGBA'. The default value is black (0, 0, 0).
Example usage:
from PIL import Image
# Create a new RGB image with size 500x300
image = Image.new('RGB', (500, 300))
# Create a new grayscale image with size 200x200
gray_image = Image.new('L', (200, 200))
# Create a new RGBA image with size 800x600 and fill it with white color
transparent_image = Image.new('RGBA', (800, 600), (255, 255, 255, 0))
Note: After creating a new image, you can manipulate and save it using various methods provided by the PIL.Image module.
原文地址: https://www.cveoy.top/t/topic/jSCj 著作权归作者所有。请勿转载和采集!