From adda3b7473be722f6bdbe81bbd9907795a137994 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 May 2018 21:00:44 +1000 Subject: [PATCH] Allow float values in getrgb hsl color string --- Tests/test_imagecolor.py | 4 ++++ src/PIL/ImageColor.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/test_imagecolor.py b/Tests/test_imagecolor.py index 64e88cf9c..81ad179e6 100644 --- a/Tests/test_imagecolor.py +++ b/Tests/test_imagecolor.py @@ -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)")) diff --git a/src/PIL/ImageColor.py b/src/PIL/ImageColor.py index 4a1c90b27..0e9702228 100644 --- a/src/PIL/ImageColor.py +++ b/src/PIL/ImageColor.py @@ -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(