Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I save bytes as an image?

I was trying to save bytes as an image, but it doesn’t seem to be working.

here is what I tried:

from PIL import Image
from io import BytesIO
image = open('D:\pythonScreenshots\screenshot1.jpg', 'rb')
a = image.read()
stream = BytesIO(a)
image = Image.open(stream).convert("RGBA")
stream.close()
photo_path = 'D:\pythonScreenshots\screenshot2.jpg'
image.save(photo_path)

But I get an error saying that it cannot write mode RGBA as JPEG, so i guess this method works only with pngs? If so, is there any other way to do it with jpeg images?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try with "RGB" only, "RGBA" has a alpha channel that jpg not supports

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading