pil 從內存中讀寫圖片

from io import StringIO, BytesIO
from PIL import Image

img_path = './car.jpg'
# 從內存中讀圖片
content = open(img_path, 'rb').read()
img = Image.open(BytesIO(content))
print(img.size, img.mode)

# 往內存中寫圖片
img = Image.open(img_path)
with BytesIO() as out:
    img.save(out, format='JPEG')
    with open('out_stream.jpg', 'wb') as fo:
        fo.write(out.getvalue())
發佈了170 篇原創文章 · 獲贊 46 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章