PIL: Convert Bytearray to Image PIL: Convert Bytearray to Image arrays arrays

PIL: Convert Bytearray to Image


If you manipulate with bytearrays, then you have to use io.BytesIO. Also you can read a file directly to a bytearray.

import osimport ioimport PIL.Image as Imagefrom array import arraydef readimage(path):    count = os.stat(path).st_size / 2    with open(path, "rb") as f:        return bytearray(f.read())bytes = readimage(path+extension)image = Image.open(io.BytesIO(bytes))image.save(savepath)