Spaces:
Running
Running
Fix alpha
Browse files
app.py
CHANGED
@@ -239,33 +239,33 @@ def hex_to_rgb(color):
|
|
239 |
return (int(color[0:2], 16) / 255.0,
|
240 |
int(color[2:4], 16) / 255.0,
|
241 |
int(color[4:6], 16) / 255.0,
|
242 |
-
|
243 |
|
244 |
# HEX with alpha (8-digit HEX)
|
245 |
if len(color) == 8:
|
246 |
return (int(color[0:2], 16) / 255.0,
|
247 |
int(color[2:4], 16) / 255.0,
|
248 |
-
int(color[4:6], 16) / 255.0
|
249 |
-
|
250 |
|
251 |
# RGB format (rgb(r, g, b))
|
252 |
match_rgb = re.match(r"rgb\((\d+),\s*(\d+),\s*(\d+)\)", color)
|
253 |
if match_rgb:
|
254 |
r, g, b = map(int, match_rgb.groups())
|
255 |
-
return (r / 255.0, g / 255.0, b / 255.0
|
256 |
|
257 |
# RGBA format (rgba(r, g, b, a))
|
258 |
match_rgba = re.match(r"rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)", color)
|
259 |
if match_rgba:
|
260 |
r, g, b, a = match_rgba.groups()
|
261 |
-
return (int(r) / 255.0, int(g) / 255.0, int(b) / 255.0
|
262 |
|
263 |
# HSV format (hsv(h, s, v))
|
264 |
match_hsv = re.match(r"hsv\((\d+),\s*(\d+),\s*(\d+)\)", color)
|
265 |
if match_hsv:
|
266 |
h, s, v = map(int, match_hsv.groups())
|
267 |
r, g, b = colorsys.hsv_to_rgb(h / 360.0, s / 100.0, v / 100.0)
|
268 |
-
return (r, g, b
|
269 |
|
270 |
raise ValueError(f"Invalid color format: {color}")
|
271 |
|
|
|
239 |
return (int(color[0:2], 16) / 255.0,
|
240 |
int(color[2:4], 16) / 255.0,
|
241 |
int(color[4:6], 16) / 255.0,
|
242 |
+
)
|
243 |
|
244 |
# HEX with alpha (8-digit HEX)
|
245 |
if len(color) == 8:
|
246 |
return (int(color[0:2], 16) / 255.0,
|
247 |
int(color[2:4], 16) / 255.0,
|
248 |
+
int(color[4:6], 16) / 255.0
|
249 |
+
)
|
250 |
|
251 |
# RGB format (rgb(r, g, b))
|
252 |
match_rgb = re.match(r"rgb\((\d+),\s*(\d+),\s*(\d+)\)", color)
|
253 |
if match_rgb:
|
254 |
r, g, b = map(int, match_rgb.groups())
|
255 |
+
return (r / 255.0, g / 255.0, b / 255.0)
|
256 |
|
257 |
# RGBA format (rgba(r, g, b, a))
|
258 |
match_rgba = re.match(r"rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)", color)
|
259 |
if match_rgba:
|
260 |
r, g, b, a = match_rgba.groups()
|
261 |
+
return (int(r) / 255.0, int(g) / 255.0, int(b) / 255.0)
|
262 |
|
263 |
# HSV format (hsv(h, s, v))
|
264 |
match_hsv = re.match(r"hsv\((\d+),\s*(\d+),\s*(\d+)\)", color)
|
265 |
if match_hsv:
|
266 |
h, s, v = map(int, match_hsv.groups())
|
267 |
r, g, b = colorsys.hsv_to_rgb(h / 360.0, s / 100.0, v / 100.0)
|
268 |
+
return (r, g, b)
|
269 |
|
270 |
raise ValueError(f"Invalid color format: {color}")
|
271 |
|