Spaces:
Running
on
Zero
Running
on
Zero
Image Utils error handling update
Browse files- utils/image_utils.py +13 -7
utils/image_utils.py
CHANGED
@@ -214,19 +214,22 @@ def change_color(image, color, opacity=0.75):
|
|
214 |
Returns:
|
215 |
PIL.Image.Image: The image with the color changed.
|
216 |
"""
|
217 |
-
if
|
218 |
image = open_image(image)
|
|
|
|
|
|
|
219 |
try:
|
220 |
# Convert the color to RGBA format
|
221 |
rgba_color = detect_color_format(color)
|
222 |
rgba_color = update_color_opacity(rgba_color, opacity)
|
223 |
-
|
224 |
-
# Convert the image to RGBA mode
|
225 |
-
image = image.convert("RGBA")
|
226 |
-
|
227 |
# Create a new image with the same size and mode
|
228 |
new_image = Image.new("RGBA", image.size, rgba_color)
|
229 |
-
|
|
|
|
|
|
|
230 |
# Composite the new image with the original image
|
231 |
result = Image.alpha_composite(image, new_image)
|
232 |
except Exception as e:
|
@@ -235,6 +238,9 @@ def change_color(image, color, opacity=0.75):
|
|
235 |
return result
|
236 |
|
237 |
def blur_image(input_path, radius=5, blur_type="gaussian"):
|
|
|
|
|
|
|
238 |
input_path, _ = get_image_from_dict(input_path)
|
239 |
directory, _, name, _, new_ext = get_file_parts(input_path)
|
240 |
# If the extension changes, rename the file
|
@@ -925,7 +931,7 @@ def apply_lut_to_image_path(lut_filename: str, image_path: str, intensity: int =
|
|
925 |
|
926 |
img_lut = None
|
927 |
if image_path is None:
|
928 |
-
raise UserWarning("No image provided.")
|
929 |
return None, None
|
930 |
|
931 |
# Split the path into directory and filename
|
|
|
214 |
Returns:
|
215 |
PIL.Image.Image: The image with the color changed.
|
216 |
"""
|
217 |
+
if isinstance(image, (dict, str)):
|
218 |
image = open_image(image)
|
219 |
+
if image is None:
|
220 |
+
print("Image to color is None")
|
221 |
+
return None
|
222 |
try:
|
223 |
# Convert the color to RGBA format
|
224 |
rgba_color = detect_color_format(color)
|
225 |
rgba_color = update_color_opacity(rgba_color, opacity)
|
226 |
+
|
|
|
|
|
|
|
227 |
# Create a new image with the same size and mode
|
228 |
new_image = Image.new("RGBA", image.size, rgba_color)
|
229 |
+
|
230 |
+
# Convert the image to RGBA mode
|
231 |
+
image = image.convert("RGBA")
|
232 |
+
|
233 |
# Composite the new image with the original image
|
234 |
result = Image.alpha_composite(image, new_image)
|
235 |
except Exception as e:
|
|
|
238 |
return result
|
239 |
|
240 |
def blur_image(input_path, radius=5, blur_type="gaussian"):
|
241 |
+
if input_path is None:
|
242 |
+
print("There is no Image to Blur")
|
243 |
+
return None
|
244 |
input_path, _ = get_image_from_dict(input_path)
|
245 |
directory, _, name, _, new_ext = get_file_parts(input_path)
|
246 |
# If the extension changes, rename the file
|
|
|
931 |
|
932 |
img_lut = None
|
933 |
if image_path is None:
|
934 |
+
raise UserWarning("No image provided for LUT.")
|
935 |
return None, None
|
936 |
|
937 |
# Split the path into directory and filename
|