diff --git a/Tests/test_imagecolor.py b/Tests/test_imagecolor.py index 22b0d1c73..0aac21278 100644 --- a/Tests/test_imagecolor.py +++ b/Tests/test_imagecolor.py @@ -82,6 +82,10 @@ class TestImageColor(PillowTestCase): self.assertEqual((255, 0, 0), ImageColor.getrgb("hsv(360,100%,100%)")) self.assertEqual((0, 255, 255), ImageColor.getrgb("hsv(180,100%,100%)")) + # alternate format + self.assertEqual(ImageColor.getrgb("hsb(0,100%,50%)"), + ImageColor.getrgb("hsv(0,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%)")) @@ -100,6 +104,8 @@ class TestImageColor(PillowTestCase): ImageColor.getrgb("hsl(0,100%,50%)")) self.assertEqual(ImageColor.getrgb("HSV(0,100%,50%)"), ImageColor.getrgb("hsv(0,100%,50%)")) + self.assertEqual(ImageColor.getrgb("HSB(0,100%,50%)"), + ImageColor.getrgb("hsb(0,100%,50%)")) # space agnosticism self.assertEqual((255, 0, 0), diff --git a/docs/reference/ImageColor.rst b/docs/reference/ImageColor.rst index caab6214a..187306f1b 100644 --- a/docs/reference/ImageColor.rst +++ b/docs/reference/ImageColor.rst @@ -34,7 +34,9 @@ The ImageColor module supports the following string formats: * Hue-Saturation-Value (HSV) functions, given as ``hsv(hue, saturation%, value%)`` where hue and saturation are the same as HSL, and value is between 0% and 100% (black=0%, normal=100%). For example, ``hsv(0,100%,100%)`` is - pure red. + pure red. This format is also known as Hue-Saturation-Brightness (HSB), and + can be given as ``hsb(hue, saturation%, brightness%)``, where each of the + values are used as they are in HSV. * Common HTML color names. The :py:mod:`~PIL.ImageColor` module provides some 140 standard color names, based on the colors supported by the X Window diff --git a/src/PIL/ImageColor.py b/src/PIL/ImageColor.py index 278bc21ba..08c00fd54 100644 --- a/src/PIL/ImageColor.py +++ b/src/PIL/ImageColor.py @@ -101,7 +101,7 @@ def getrgb(color): int(rgb[2] * 255 + 0.5) ) - m = re.match(r"hsv\(\s*(\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*\)$", color) + m = re.match(r"hs[bv]\(\s*(\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*\)$", color) if m: from colorsys import hsv_to_rgb rgb = hsv_to_rgb(