6 examples of 'how to use rgb in python' in Python

Every line of 'how to use rgb in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
60def tune_rgb(rgb, contrast=0, brightness=0):
61 if contrast:
62 rgb = (rgb - 127.5) * (contrast + 1) + 127.5
63 if brightness:
64 rgb += brightness * 255.0
65 return rgb
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

180@staticmethod
181def _int_to_rgb(color):
182 return (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF
17@filter_method(BaseFilter.Number, BaseFilter.Number, BaseFilter.Number)
18def rgb(self, r, g, b):
19 mode, data = self.engine.image_data_as_rgb()
20 imgdata = _rgb.apply(mode, r, g, b, data)
21 self.engine.set_image_data(imgdata)
111def test_color_from_rgb_bytes():
112 verify_color(Color.from_rgb_bytes(1, 1, 1).rgb_bytes, (1, 1, 1))
113 verify_color(Color.from_rgb_bytes(255, 255, 255), (1.0, 1.0, 1.0))
114 verify_color(Color.from_rgb_bytes(r=255, g=255, b=255), (1.0, 1.0, 1.0))
69def color_rgb(r, g, b):
70 return int(((r & 255) << 16) |
71 ((g & 255) << 8) |
72 (b & 255))
13def test_rgb(self):
14 test = self.color.rgb
15 for r, g, b, v in [
16 (255, 255, 255, '#ffffff'),
17 (100, 100, 100, '#646464'),
18 (0, 0, 0, '#000000'),
19 ('70%', '70%', '70%', '#b2b2b2'),
20 ('1%', '1%', '1%', '#020202'),
21 ('100%', '100%', '100%', '#ffffff'),
22 ('0%', '0%', '0%', '#000000'),
23 ]:
24 self.assertEqual(test(r, g, b), v)
25 for r, g, b, a, v in [
26 (255, 255, 255, 0.5, '#ffffff'),
27 (100, 100, 100, 0.9, '#646464'),
28 (0, 0, 0, 100, '#000000'),
29 ]:
30 self.assertEqual(test(r, g, b, a), v)
31 for args in [
32 (255, 255, 256),
33 (0, -1, 0),
34 ('100%', '100%', 200),
35 ('100%', '100%', '200%'),
36 ]:
37 self.assertRaises(ValueError, test, args)

Related snippets