-
Notifications
You must be signed in to change notification settings - Fork 0
/
numRGB.py
26 lines (24 loc) · 876 Bytes
/
numRGB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from PIL import Image
image =Image.open("") #put file path here
siz = [, ] #put xy image size here
s = []
def hex_to_rgb(value):
"""Return (red, green, blue) for the color given as #rrggbb."""
value = value.lstrip('#')
lv = len(value)
return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
def rgb_to_hex(red, green, blue):
"""Return color as #rrggbb for the given color values."""
return '#%02x%02x%02x' % (red, green, blue)
hex_to_rgb("#ffffff") #==> (255, 255, 255)
hex_to_rgb("#ffffffffffff") #==> (65535, 65535, 65535)
rgb_to_hex(255, 255, 255) #==> '#ffffff'
rgb_to_hex(65535, 65535, 65535) #==> '#ffffffffffff'
for i in range(siz[1]):
for j in range(siz[0]):
col = image.getpixel((i,j))
r = col[0]
g = col[1]
b = col[2]
s.append(rgb_to_hex(r, g, b))
print(s)