-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong color conversion from HSV string #7225
Comments
The documentation for
This is your problem. When creating RGB images. So |
Aha, I just read source code of getrgb() and I see it indeed returns RGB code only. However, that makes it a bit bad developer experience. It would be nice if the string was interpreted according to the mode I set. So this would create a blue image: im = Image.new("HSV", (200, 200), color="hsv(240, 100%, 100%)")
# would print: (170, 255, 255)
print(im.getpixel((0, 0)))
# would show blue image, it would need to convert it to RGB color space before, of course
im.show() I would say this can be a feature request for getcolor(), that would call |
I've created PR #7226 to resolve this. |
Nice, thank you! |
What did you do?
I tried to create an image with
HSV
mode and set its color to blue with following kwargscolor=(170, 255, 255) # 170 == 255 * (2/3)
color="hsv(240, 100%, 100%)"
What did you expect to happen?
To get a blue image with both approaches.
What actually happened?
The
color="hsv(240, 100%, 100%)"
kwarg created a white image.What are your OS, Python and Pillow versions?
I tried converting to
RGB
first, but that has the same result.Something weird is also happening with
getpixel()
method.When a tuple is used to set a color it works. The image is still in
HSV
mode, so 170 is 240 hue, and 255 is 100% saturation and value.The pixel bytes have expected values.
However, when a string is used, then the pixel bytes are totally off. It looks like it is returning
RGB
mode, since this is blue color in RGB code.So I tried using
RGB
mode for the image and that works as expected.The text was updated successfully, but these errors were encountered: