The 'PIL.Image.new()' function is used to create a new image object with a specified mode and size.

Syntax:

PIL.Image.new(mode, size, color=None)

Parameters:

  • 'mode' (string): The mode of the image, such as 'RGB' or 'L'. See the PIL documentation for a complete list of modes.
  • 'size' (tuple or int): The size of the image, specified as a tuple (width, height) or a single integer for a square image.
  • 'color' (tuple or int, optional): The color to fill the image with. If not provided, the image will be transparent.

Example:

from PIL import Image

# Create a new RGB image with size 500x300 and fill it with white color
image = Image.new('RGB', (500, 300), (255, 255, 255))

This example creates a new image object with an RGB mode, size of 500x300 pixels, and fills it with white color.

Python PIL Image.new() Function: Create New Images

原文地址: https://www.cveoy.top/t/topic/lxhU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录