Skip to content

Instantly share code, notes, and snippets.

@krossford
Created July 23, 2020 07:55
Show Gist options
  • Save krossford/3ef98c7af9ecb7882ca42fd40d86ab31 to your computer and use it in GitHub Desktop.
Save krossford/3ef98c7af9ecb7882ca42fd40d86ab31 to your computer and use it in GitHub Desktop.
Python Pillow 图像操作
from PIL import Image
img = Image.open("cat.jpg")
# 图片尺寸
print(img.size)
img.size[0] # 宽度
img.size[1] # 高度
# 操作像素
bitmap = img.load()
bitmap[x, y] = (255, 0, 0)
# 遍历每个像素点
for x in range(img.size[0]):
for y in range(img.size[1]):
# do something
# 显示
img.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment