1

I am reading a bytes file, convert that and then Open it. I need to convert this back to bytes in order to store it in the database in a blob column.

How is this possible to convert actual image to bytes?

img = Image.open(io.BytesIO(dfa.flal_file)).convert('RGB')
csandreas1
  • 2,026
  • 1
  • 26
  • 48
  • 1
    In pillow there is `Image.tobytes()`, see [here](https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=image#PIL.Image.Image.tobytes). – guidot Jan 26 '21 at 12:52
  • Possible duplicate of: https://stackoverflow.com/questions/33101935/convert-pil-image-to-byte-array – csandreas1 Jan 26 '21 at 12:54
  • 1
    Does this answer your question? [Convert PIL Image to byte array?](https://stackoverflow.com/questions/33101935/convert-pil-image-to-byte-array) – guidot Jan 26 '21 at 12:57
  • Surely, `dfa.flal_file` is a JPEG or PNG anyway, so just store that. And it has the height and width in it. If you just store bytes, you won't know the image dimensions or colourspace or EXIF data. – Mark Setchell Jan 26 '21 at 12:59
  • @guidot yes it did – csandreas1 Jan 26 '21 at 12:59

0 Answers0