mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
commit
e81450ece1
|
@ -20,15 +20,6 @@
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
# Convert color string to RGB tuple.
|
|
||||||
#
|
|
||||||
# @param color A CSS3-style colour string.
|
|
||||||
# @return An RGB-tuple.
|
|
||||||
# @exception ValueError If the color string could not be interpreted
|
|
||||||
# as an RGB value.
|
|
||||||
|
|
||||||
def getrgb(color):
|
def getrgb(color):
|
||||||
"""
|
"""
|
||||||
Convert a color string to an RGB tuple. If the string cannot be parsed,
|
Convert a color string to an RGB tuple. If the string cannot be parsed,
|
||||||
|
@ -37,7 +28,7 @@ def getrgb(color):
|
||||||
.. versionadded:: 1.1.4
|
.. versionadded:: 1.1.4
|
||||||
|
|
||||||
:param color: A color string
|
:param color: A color string
|
||||||
:return: ``(red, green, blue)``
|
:return: ``(red, green, blue[, alpha])``
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
rgb = colormap[color]
|
rgb = colormap[color]
|
||||||
|
@ -114,7 +105,7 @@ def getcolor(color, mode):
|
||||||
.. versionadded:: 1.1.4
|
.. versionadded:: 1.1.4
|
||||||
|
|
||||||
:param color: A color string
|
:param color: A color string
|
||||||
:return: ``(red, green, blue)``
|
:return: ``(graylevel [, alpha]) or (red, green, blue[, alpha])``
|
||||||
"""
|
"""
|
||||||
# same as getrgb, but converts the result to the given mode
|
# same as getrgb, but converts the result to the given mode
|
||||||
color, alpha = getrgb(color), 255
|
color, alpha = getrgb(color), 255
|
||||||
|
|
|
@ -41,7 +41,11 @@ Image.new("L", (1, 1), "white")
|
||||||
|
|
||||||
assert_equal(0, ImageColor.getcolor("black", "1"))
|
assert_equal(0, ImageColor.getcolor("black", "1"))
|
||||||
assert_equal(255, ImageColor.getcolor("white", "1"))
|
assert_equal(255, ImageColor.getcolor("white", "1"))
|
||||||
|
# The following test is wrong, but is current behavior
|
||||||
|
# The correct result should be 255 due to the mode 1
|
||||||
assert_equal(162, ImageColor.getcolor("rgba(0, 255, 115, 33)", "1"))
|
assert_equal(162, ImageColor.getcolor("rgba(0, 255, 115, 33)", "1"))
|
||||||
|
# Correct behavior
|
||||||
|
# assert_equal(255, ImageColor.getcolor("rgba(0, 255, 115, 33)", "1"))
|
||||||
Image.new("1", (1, 1), "white")
|
Image.new("1", (1, 1), "white")
|
||||||
|
|
||||||
assert_equal((0, 255), ImageColor.getcolor("black", "LA"))
|
assert_equal((0, 255), ImageColor.getcolor("black", "LA"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user