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
  • Save Taisho/260794feb72caad6d3a7bf186efcbfe2 to your computer and use it in GitHub Desktop.
Save Taisho/260794feb72caad6d3a7bf186efcbfe2 to your computer and use it in GitHub Desktop.

Revisions

  1. @sleepless-se sleepless-se created this gist May 9, 2019.
    8 changes: 8 additions & 0 deletions image_to_byte_array.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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