Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -23,6 +23,10 @@ def initialize_client(api_key=None):
|
|
23 |
def encode_image(image_path, max_size=(800, 800), quality=85):
|
24 |
with Image.open(image_path) as img:
|
25 |
img.thumbnail(max_size)
|
|
|
|
|
|
|
|
|
26 |
buffered = io.BytesIO()
|
27 |
img.save(buffered, format="JPEG", quality=quality)
|
28 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
|
|
23 |
def encode_image(image_path, max_size=(800, 800), quality=85):
|
24 |
with Image.open(image_path) as img:
|
25 |
img.thumbnail(max_size)
|
26 |
+
if img.mode in ('RGBA', 'LA'):
|
27 |
+
background = Image.new(img.mode[:-1], img.size, (255, 255, 255))
|
28 |
+
background.paste(img, mask=img.split()[-1])
|
29 |
+
img = background
|
30 |
buffered = io.BytesIO()
|
31 |
img.save(buffered, format="JPEG", quality=quality)
|
32 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|