Update app.py
Browse files
app.py
CHANGED
@@ -87,23 +87,23 @@ class ImageResizer:
|
|
87 |
resized_image = image.copy()
|
88 |
new_width, new_height = resized_image.size
|
89 |
|
90 |
-
#
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
108 |
# Calculate position to center the image
|
109 |
x = (width - new_width) // 2
|
@@ -157,8 +157,11 @@ def process_single_image(image, width, height, maintain_aspect, png_bg_option, c
|
|
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
|
161 |
-
is_png = True # Force PNG treatment for
|
|
|
|
|
|
|
162 |
|
163 |
# Resize image
|
164 |
resized_image = resizer.resize_image(
|
@@ -208,8 +211,8 @@ def process_folder_images(files, width, height, maintain_aspect, png_bg_option,
|
|
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
|
212 |
-
is_png = True # Force PNG treatment for
|
213 |
|
214 |
# Resize image
|
215 |
resized_image = resizer.resize_image(
|
@@ -276,8 +279,8 @@ def process_zip_file(zip_file, width, height, maintain_aspect, png_bg_option, cu
|
|
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
|
280 |
-
is_png = True # Force PNG treatment for
|
281 |
|
282 |
# Resize image
|
283 |
resized_image = resizer.resize_image(
|
|
|
87 |
resized_image = image.copy()
|
88 |
new_width, new_height = resized_image.size
|
89 |
|
90 |
+
# Determine background color based on user selection
|
91 |
+
if png_bg_option == "black":
|
92 |
+
bg_color = (0, 0, 0)
|
93 |
+
elif png_bg_option == "white":
|
94 |
+
bg_color = (255, 255, 255)
|
95 |
+
elif png_bg_option == "custom" and custom_color:
|
96 |
+
bg_color = custom_color
|
97 |
+
elif png_bg_option == "auto" and (is_png or (hasattr(image, 'format') and image.format == 'PNG')):
|
98 |
+
bg_color = self.get_background_color(image)
|
99 |
+
else:
|
100 |
+
bg_color = (255, 255, 255) # Default white
|
101 |
+
|
102 |
+
# Create canvas with the determined background color
|
103 |
+
canvas = Image.new('RGB', (width, height), bg_color)
|
104 |
+
|
105 |
+
# Debug info
|
106 |
+
print(f"Debug: Background color applied: {bg_color}, PNG option: {png_bg_option}")
|
107 |
|
108 |
# Calculate position to center the image
|
109 |
x = (width - new_width) // 2
|
|
|
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 in ["black", "white", "custom"]:
|
161 |
+
is_png = True # Force PNG treatment for specific background choices
|
162 |
+
|
163 |
+
# Debug info (will be removed in production)
|
164 |
+
print(f"Debug: PNG detection - format: {getattr(pil_image, 'format', 'None')}, mode: {pil_image.mode}, is_png: {is_png}, bg_option: {png_bg_option}")
|
165 |
|
166 |
# Resize image
|
167 |
resized_image = resizer.resize_image(
|
|
|
211 |
|
212 |
# For PNG background selection, we should always apply the background choice
|
213 |
# regardless of original format when PNG options are selected
|
214 |
+
if png_bg_option in ["black", "white", "custom"]:
|
215 |
+
is_png = True # Force PNG treatment for specific background choices
|
216 |
|
217 |
# Resize image
|
218 |
resized_image = resizer.resize_image(
|
|
|
279 |
|
280 |
# For PNG background selection, we should always apply the background choice
|
281 |
# regardless of original format when PNG options are selected
|
282 |
+
if png_bg_option in ["black", "white", "custom"]:
|
283 |
+
is_png = True # Force PNG treatment for specific background choices
|
284 |
|
285 |
# Resize image
|
286 |
resized_image = resizer.resize_image(
|