-
Notifications
You must be signed in to change notification settings - Fork 3
/
pillowDemo.py
57 lines (46 loc) · 1.51 KB
/
pillowDemo.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#Use webcolors to convert color names to RGB values, and vice-versa.
'''
http://stackoverflow.com/questions/9694165/convert-rgb-color-to-english-color-name-like-green
'''
from PIL import Image
import webcolors
import numpy
#This is implemented
def magnify1DArray(theArray, scaleFactor):
theNewArray = []
for current in range(0, len(theArray)):
for current1 in range(0, scaleFactor):
theNewArray += [theArray[current]]
return theNewArray
print(magnify1DArray([1,3,2,2], 3))
def magnify2DArray(theArray, scaleFactor):
theNewArray = []
for current in theArray:
print(current)
print(magnify1DArray(current, scaleFactor))
for current1 in range(0, len(theArray)+1):
theNewArray += [magnify1DArray(current, scaleFactor)]
return theNewArray
print(magnify2DArray([[0,1],[9,2]], 3))
def makeImage(my_list, imageName):
listDimensions = numpy.array(my_list).shape
for i in range(0, len(my_list)):
for j in range(0, len(my_list[i])):
my_list[i][j] = webcolors.name_to_rgb(my_list[i][j])
new_list = []
for current in my_list:
new_list += current
img = Image.new('RGB', (listDimensions[1], listDimensions[0]))
img.putdata(new_list)
img.save(imageName)
makeImage([["green", "blue", "orange"], ["blue", "green", "orange"]], "my_image1.png")
newArray = []
for current in range(0, 10):
newArray += [[]]
for current1 in range(0, 10):
theColor = "red"
theNumber = (current*3 ** current1*5)%2
if(theNumber == 0):
theColor = "blue"
newArray[current] += [theColor]
makeImage(newArray, "checkerboardPattern.png")