OSError: cannot write mode RGBA as JPEG at /usr/local/lib/python3.7/site-packages/PIL/JpegImagePlugin.py, line 617 called from /usr/local/lib/python3.7/site-packages/PIL/Image.py, line 2102 called from [ServerModule1, line 16](javascript:void(0)) called from [Form1, line 14](javascript:void(0))
here is my app:
Can you please let me know what I am missing?
Thanks!
I tried it before (and I tried it again), I got this error:
ValueError: conversion from RGB to JPEG not supported at /usr/local/lib/python3.7/site-packages/PIL/Image.py, line 1000 called from [ServerModule1, line 13](javascript:void(0)) called from [Form1, line 14](javascript:void(0))
I search different websites, some of them I didn’t understand their solution and others I got different errors
Forgive my ignorance, I have limited programing experience, what I am trying to do is to simply resize images captured by the user camera before uploading it to the anvil tables, so I doesn’t take too long to upload the images. I tried to use the code in the previous post, so, what I really need is to have this code to work:
from PIL import Image
import io
@anvil.server.callable
def resize(file):
# Convert the 'file' Media object into a Pillow Image
img = Image.open(io.BytesIO(file.get_bytes()))
# Resize the image to the required size
img = img.resize((800,600))
# Convert the Pillow Image into an Anvil Media object and return it
bs = io.BytesIO()
img.save(bs, format="JPEG")
return anvil.BlobMedia("image/jpeg", bs.getvalue(), name=name)
It works perfectly but you will have to copy it exactly as it is written (I belive you had your variable names wrong and you used “JPEG” instead of “RGB”).
You will also want to define “name” in your app since it is undefined at the moment.
@anvil.server.callable
def resize(file):
# Convert the 'file' Media object into a Pillow Image
img = Image.open(io.BytesIO(file.get_bytes()))
# Resize the image to the required size
img = img.resize((800,600))
img = img.convert("RGB")
# Convert the Pillow Image into an Anvil Media object and return it
bs = io.BytesIO()
img.save(bs, format="RGB")
return anvil.BlobMedia("image/RGB", bs.getvalue(), name="Name")
I got this error:
KeyError: ‘RGB’ at /usr/local/lib/python3.7/site-packages/PIL/Image.py, line 2091 called from [ServerModule1, line 19](javascript:void(0)) called from [Form1, line 14](javascript:void(0))