mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Allow float values in getrgb hsl color string
This commit is contained in:
parent
e06e2777bc
commit
adda3b7473
|
@ -78,6 +78,10 @@ class TestImageColor(PillowTestCase):
|
||||||
self.assertEqual((255, 0, 0), ImageColor.getrgb("hsl(360,100%,50%)"))
|
self.assertEqual((255, 0, 0), ImageColor.getrgb("hsl(360,100%,50%)"))
|
||||||
self.assertEqual((0, 255, 255), ImageColor.getrgb("hsl(180,100%,50%)"))
|
self.assertEqual((0, 255, 255), ImageColor.getrgb("hsl(180,100%,50%)"))
|
||||||
|
|
||||||
|
# floats
|
||||||
|
self.assertEqual((254, 3, 3), ImageColor.getrgb("hsl(0.1,99.2%,50.3%)"))
|
||||||
|
self.assertEqual((255, 0, 0), ImageColor.getrgb("hsl(360.,100.0%,50%)"))
|
||||||
|
|
||||||
# case insensitivity
|
# case insensitivity
|
||||||
self.assertEqual(ImageColor.getrgb("RGB(255,0,0)"),
|
self.assertEqual(ImageColor.getrgb("RGB(255,0,0)"),
|
||||||
ImageColor.getrgb("rgb(255,0,0)"))
|
ImageColor.getrgb("rgb(255,0,0)"))
|
||||||
|
|
|
@ -87,7 +87,7 @@ def getrgb(color):
|
||||||
int((int(m.group(3)) * 255) / 100.0 + 0.5)
|
int((int(m.group(3)) * 255) / 100.0 + 0.5)
|
||||||
)
|
)
|
||||||
|
|
||||||
m = re.match(r"hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)$", color)
|
m = re.match(r"hsl\(\s*(\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*\)$", color)
|
||||||
if m:
|
if m:
|
||||||
from colorsys import hls_to_rgb
|
from colorsys import hls_to_rgb
|
||||||
rgb = hls_to_rgb(
|
rgb = hls_to_rgb(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user