mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
Added getrgb hsb color string
This commit is contained in:
parent
b50f63430f
commit
3d82672404
|
@ -82,6 +82,10 @@ class TestImageColor(PillowTestCase):
|
||||||
self.assertEqual((255, 0, 0), ImageColor.getrgb("hsv(360,100%,100%)"))
|
self.assertEqual((255, 0, 0), ImageColor.getrgb("hsv(360,100%,100%)"))
|
||||||
self.assertEqual((0, 255, 255), ImageColor.getrgb("hsv(180,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
|
# floats
|
||||||
self.assertEqual((254, 3, 3), ImageColor.getrgb("hsl(0.1,99.2%,50.3%)"))
|
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%)"))
|
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%)"))
|
ImageColor.getrgb("hsl(0,100%,50%)"))
|
||||||
self.assertEqual(ImageColor.getrgb("HSV(0,100%,50%)"),
|
self.assertEqual(ImageColor.getrgb("HSV(0,100%,50%)"),
|
||||||
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
|
# space agnosticism
|
||||||
self.assertEqual((255, 0, 0),
|
self.assertEqual((255, 0, 0),
|
||||||
|
|
|
@ -34,7 +34,9 @@ The ImageColor module supports the following string formats:
|
||||||
* Hue-Saturation-Value (HSV) functions, given as ``hsv(hue, saturation%,
|
* Hue-Saturation-Value (HSV) functions, given as ``hsv(hue, saturation%,
|
||||||
value%)`` where hue and saturation are the same as HSL, and value is between
|
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
|
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
|
* 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
|
140 standard color names, based on the colors supported by the X Window
|
||||||
|
|
|
@ -101,7 +101,7 @@ def getrgb(color):
|
||||||
int(rgb[2] * 255 + 0.5)
|
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:
|
if m:
|
||||||
from colorsys import hsv_to_rgb
|
from colorsys import hsv_to_rgb
|
||||||
rgb = hsv_to_rgb(
|
rgb = hsv_to_rgb(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user