在 python 3.x 中创建、修改和保存图像

Create, Modify, and Save an image in python 3.x

我目前正在制作一个将信息呈现到缓冲区的程序,我想将信息作为某种图像文件保存到我的工作目录中。我看过一些使用 PIL 的示例,但是 python 3.x 不支持该库。有更好的选择吗?

先卸载 PIL 再安装 Pillow

它是 PIL 的克隆,适用于 python 3.x。

from PIL import Image
img = Image.open("test1.jpg") #jpg, png, etc.
pix = img.load()
print img.size #Get the width and height of the image for iterating over
print pix[15,15] #Get the RGBA Value of the a pixel of an image
pix[15, 15] = value # Set the RGBA Value of the image (tuple)
img.save("out.jpg") # Saves the modified pixels to image