2

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?

natitati
  • 35
  • 4

1 Answers1

2

Try with "RGB" only, "RGBA" has an alpha channel that JPEG does not support.

Kenneth Eggering
  • 230
  • 3
  • 14
Pedro
  • 360
  • 3
  • 13