Allow float values in getrgb hsl color string

This commit is contained in:
Andrew Murray 2018-05-30 21:00:44 +10:00
parent e06e2777bc
commit adda3b7473
2 changed files with 5 additions and 1 deletions

View File

@ -78,6 +78,10 @@ class TestImageColor(PillowTestCase):
self.assertEqual((255, 0, 0), ImageColor.getrgb("hsl(360,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
self.assertEqual(ImageColor.getrgb("RGB(255,0,0)"),
ImageColor.getrgb("rgb(255,0,0)"))

View File

@ -87,7 +87,7 @@ def getrgb(color):
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:
from colorsys import hls_to_rgb
rgb = hls_to_rgb(