0

I have an image that I converted to bytes using the method below:

import io
from PIL import Image

def image_to_byte_array(image:Image):
  imgByteArr = io.BytesIO()
  image.save(imgByteArr, format=image.format)
  imgByteArr = imgByteArr.getvalue()
  return imgByteArr

Here is how I called the above method PIL Image.read() to covert it to bytes

 im = Image.read('mam.JPG")
 im_bytes = image_to_byte_array(im)

Now I want to reverse the process and convert the image back to a PIL Image. How do I do this ?

codigomonstruo
  • 1,081
  • 1
  • 11
  • 45
  • 2
    You can use the following syntax: `image = Image.open(io.BytesIO(im_bytes))`. See: [PIL: Convert Bytearray to Image](https://stackoverflow.com/questions/18491416/pil-convert-bytearray-to-image) – Rotem Jan 09 '21 at 14:15
  • Thank you. I got it. – codigomonstruo Jan 10 '21 at 22:26

0 Answers0