Skip to content

Instantly share code, notes, and snippets.

@shau-lok
Last active April 18, 2018 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shau-lok/e3e99abb61994a01df842190e5de2d01 to your computer and use it in GitHub Desktop.
Save shau-lok/e3e99abb61994a01df842190e5de2d01 to your computer and use it in GitHub Desktop.
python Pillow load image from bytes, Pillow 用法
from PIL import Image
import io
def load_image_from_bytes(image_data):
""" 从图片流中读取一张照片 """
im = Image.open(io.BytesIO(image_data))
print(im)
# >>> <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=300x240 at 0x102092B10>
def load_image_from_file_path(file_path):
""" 从路径中读取一张图片 """
im = Image.open(file_path)
print(im)
# >>> <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=300x240 at 0x102092B10>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment