Python PIL putdata() method
Python PIL putdata() Method
PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The image module provides a class of the same name to represent a PIL image. The module also provides factory functions for loading images from files and creating new images.
putdata() copies pixel data to this image. This method copies the data from a sequence object to the image, starting at the top-left corner (0, 0) and continuing to the end of the image or sequence. The scale and offset values are used to adjust the sequence values: pixels = value * scale + offset.
Syntax: Image.putdata(data, scale=1.0, offset=0.0)
Parameters:
data – A sequence object.
scale – An optional scale value. Defaults to 1.0.
offset – An optional offset value. Defaults to 0.0.
Returns: An image
# from pure python list data
from PIL import Image
img = Image.new("L", (104, 104)) # single band
newdata = list(range(0, 256, 4)) * 104
img.putdata(newdata)
img.show()
Output:
Another example: Here, we change the parameters.
# from pure python list data
from PIL import Image
img = Image.new("L", (224, 224))
newdata = list(range(0, 256, 4)) * 224
img.putdata(newdata)
img.show()
Output: