Get binary image data from PIL.Image?

If you want to get the actual bytes of the image, just use i.tobytes(). This is with Pillow, I'm not sure if it's in the original PIL module, but from the docs it should be.


In PIL :

Image.open(path).convert('1')

As mentioned in doc

1 mode is for (1-bit pixels, black and white, stored with one pixel per byte)


you can see this answer python Image PIL to binary Hex

The img object needs to be saved again; write it to another BytesIO object:

output = io.BytesIO()
img.save(output, format='JPEG')

then get the written data with the .getvalue() method:

hex_data = output.getvalue()