Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -347,10 +347,17 @@ def resize_and_save_worker(args):
|
|
| 347 |
img = img.convert('RGBA')
|
| 348 |
bg = Image.new('RGBA', img.size, (255,255,255,255))
|
| 349 |
img = Image.alpha_composite(bg, img)
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
img = resize_with_padding(img, w, h)
|
| 353 |
-
|
|
|
|
|
|
|
| 354 |
out_path = os.path.join(out_dir, out_name)
|
| 355 |
img.save(out_path, format=fmt.upper(), quality=90)
|
| 356 |
return out_path, None
|
|
|
|
| 347 |
img = img.convert('RGBA')
|
| 348 |
bg = Image.new('RGBA', img.size, (255,255,255,255))
|
| 349 |
img = Image.alpha_composite(bg, img)
|
| 350 |
+
fmt_upper = fmt.upper()
|
| 351 |
+
# map JPG to the PIL format name
|
| 352 |
+
save_fmt = 'JPEG' if fmt_upper in ('JPEG','JPG') else fmt_upper
|
| 353 |
+
# ensure RGB for JPEG
|
| 354 |
+
if save_fmt == 'JPEG':
|
| 355 |
+
img = img.convert('RGB')
|
| 356 |
+
img.save(out_path, format=save_fmt, quality=90)
|
| 357 |
img = resize_with_padding(img, w, h)
|
| 358 |
+
ext = fmt.lower()
|
| 359 |
+
ext = 'jpg' if ext in ('jpeg','jpg') else ext
|
| 360 |
+
out_name = f"{name}.{ext}"
|
| 361 |
out_path = os.path.join(out_dir, out_name)
|
| 362 |
img.save(out_path, format=fmt.upper(), quality=90)
|
| 363 |
return out_path, None
|