Skip to content

Instantly share code, notes, and snippets.

@Taisho
Forked from sleepless-se/image_to_byte_array.py
Created February 24, 2024 13:05
Show Gist options
  • Select an option

  • Save Taisho/260794feb72caad6d3a7bf186efcbfe2 to your computer and use it in GitHub Desktop.

Select an option

Save Taisho/260794feb72caad6d3a7bf186efcbfe2 to your computer and use it in GitHub Desktop.
PIL image convert to byte array
from PIL import Image
import io
def image_to_byte_array(image:Image)
imgByteArr = io.BytesIO()
image.save(imgByteArr, format=image.format)
imgByteArr = imgByteArr.getvalue()
return imgByteArr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment