开发者

Python: reduce lightness of a RGB color

开发者 https://www.devze.com 2023-02-15 21:34 出处:网络
Is there a simple way to change the lightness of a color given as RGB string? E.g. in_RGB = \'#FF0000\'-开发者_运维百科-> out_RGB = \'#CC0000\'

Is there a simple way to change the lightness of a color given as RGB string?

E.g.

in_RGB = '#FF0000'  -开发者_运维百科-> out_RGB = '#CC0000'


It's not that hard to convert a hex string to an RGB 3-tuple.

Once you've done that, you can use the colorsys module (or if you prefer to implement it yourself, the equations here) to convert from RGB to HSL, then do the manipulation you want, and then convert back from HSL to RGB.

Then just convert back to hex, add the # sign again, and you're good to go.

0

精彩评论

暂无评论...
验证码 换一张
取 消