python PIL Image save grey scale png
Here's an example of how to save a grey scale PNG image using Python's PIL library:
from PIL import Image
# Open the image file
img = Image.open('image.jpg')
# Convert the image to grayscale
gray_img = img.convert('L')
# Save the grayscale image as a PNG
gray_img.save('gray_image.png')
In this example, we first open the image file using the Image.open() method. We then convert the image to grayscale using the convert() method and passing in 'L' as the argument. Finally, we save the grayscale image as a PNG using the save() method and passing in the file name as the argument.
原文地址: https://www.cveoy.top/t/topic/br6v 著作权归作者所有。请勿转载和采集!