Update app.py
Browse files
app.py
CHANGED
|
@@ -149,8 +149,16 @@ def process_single_image(image, width, height, maintain_aspect, png_bg_option, c
|
|
| 149 |
except:
|
| 150 |
custom_color = (255, 255, 255) # Default to white if invalid
|
| 151 |
|
| 152 |
-
# Check if image is PNG
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
# Resize image
|
| 156 |
resized_image = resizer.resize_image(
|
|
@@ -192,8 +200,16 @@ def process_folder_images(files, width, height, maintain_aspect, png_bg_option,
|
|
| 192 |
# Open image
|
| 193 |
image = Image.open(file.name)
|
| 194 |
|
| 195 |
-
# Check if image is PNG
|
| 196 |
-
is_png = file.name.lower().endswith('.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
# Resize image
|
| 199 |
resized_image = resizer.resize_image(
|
|
@@ -252,8 +268,16 @@ def process_zip_file(zip_file, width, height, maintain_aspect, png_bg_option, cu
|
|
| 252 |
file_path = os.path.join(root, file)
|
| 253 |
image = Image.open(file_path)
|
| 254 |
|
| 255 |
-
# Check if image is PNG
|
| 256 |
-
is_png = file.lower().endswith('.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
# Resize image
|
| 259 |
resized_image = resizer.resize_image(
|
|
|
|
| 149 |
except:
|
| 150 |
custom_color = (255, 255, 255) # Default to white if invalid
|
| 151 |
|
| 152 |
+
# Check if image is PNG - improved detection
|
| 153 |
+
# In Gradio, uploaded images often lose format info, so we assume PNG if it has transparency
|
| 154 |
+
is_png = (hasattr(pil_image, 'format') and pil_image.format == 'PNG') or \
|
| 155 |
+
(pil_image.mode in ('RGBA', 'LA')) or \
|
| 156 |
+
(hasattr(pil_image, 'info') and 'transparency' in pil_image.info)
|
| 157 |
+
|
| 158 |
+
# For PNG background selection, we should always apply the background choice
|
| 159 |
+
# regardless of original format when PNG options are selected
|
| 160 |
+
if png_bg_option != "auto":
|
| 161 |
+
is_png = True # Force PNG treatment for non-auto options
|
| 162 |
|
| 163 |
# Resize image
|
| 164 |
resized_image = resizer.resize_image(
|
|
|
|
| 200 |
# Open image
|
| 201 |
image = Image.open(file.name)
|
| 202 |
|
| 203 |
+
# Check if image is PNG - improved detection
|
| 204 |
+
is_png = file.name.lower().endswith('.png') or \
|
| 205 |
+
(hasattr(image, 'format') and image.format == 'PNG') or \
|
| 206 |
+
(image.mode in ('RGBA', 'LA')) or \
|
| 207 |
+
(hasattr(image, 'info') and 'transparency' in image.info)
|
| 208 |
+
|
| 209 |
+
# For PNG background selection, we should always apply the background choice
|
| 210 |
+
# regardless of original format when PNG options are selected
|
| 211 |
+
if png_bg_option != "auto":
|
| 212 |
+
is_png = True # Force PNG treatment for non-auto options
|
| 213 |
|
| 214 |
# Resize image
|
| 215 |
resized_image = resizer.resize_image(
|
|
|
|
| 268 |
file_path = os.path.join(root, file)
|
| 269 |
image = Image.open(file_path)
|
| 270 |
|
| 271 |
+
# Check if image is PNG - improved detection
|
| 272 |
+
is_png = file.lower().endswith('.png') or \
|
| 273 |
+
(hasattr(image, 'format') and image.format == 'PNG') or \
|
| 274 |
+
(image.mode in ('RGBA', 'LA')) or \
|
| 275 |
+
(hasattr(image, 'info') and 'transparency' in image.info)
|
| 276 |
+
|
| 277 |
+
# For PNG background selection, we should always apply the background choice
|
| 278 |
+
# regardless of original format when PNG options are selected
|
| 279 |
+
if png_bg_option != "auto":
|
| 280 |
+
is_png = True # Force PNG treatment for non-auto options
|
| 281 |
|
| 282 |
# Resize image
|
| 283 |
resized_image = resizer.resize_image(
|