I am using the Python Imaging Library to turn a photo into a byte array. This can be done by
im = Image.open("hello.jpg")
myImageArray = im.tobytes()
From the documentation, the tobytes
function is defined by
def tobytes(self, encoder_name="raw", *args):
"""
Return image as a bytes object
:param encoder_name: What encoder to use. The default is to
use the standard "raw" encoder.
:param args: Extra arguments to the encoder.
:rtype: A bytes object.
"""
In this answer, Jon Skeet says "In order to convert an image to a byte array you have to specify an image format". Is the encoder the image format?
When tobytes
defaults to raw, does this mean it is encoded as .raw and would need to be decoded as a .raw to be interpreted correctly, or do they mean something else by raw? Would it be nonsensical to try to encode a JPEG file as a bitmap byte array (i.e.
im = Image.open("hello.jpg")
myImageArray = im.tobytes('not jpg encoder')