我爱Avril Lavigne
from PIL import Image
import os
def function5():
for y in range(1, 13):
if y == 1:
for x in range(1, 7):
yield (x, y)
elif 1 < y < 6:
x = 1
yield (x, y)
elif y == 6:
for x in range(1, 7):
yield (x, y)
elif 6 < y < 12:
x = 6
yield (x, y)
elif y == 12:
for x in range(1, 7):
yield (x, y)
def function2():
for y in range(1, 13):
if y == 1:
for x in range(8, 14):
yield (x, y)
elif 1 < y < 6:
x = 13
yield (x, y)
elif y == 6:
for x in range(8, 14):
yield (x, y)
elif 6 < y < 12:
x = 8
yield (x, y)
elif y == 12:
for x in range(8, 14):
yield (x, y)
def function0():
for y in range(1, 13):
x = 20
yield (x, y)
if y == 1:
for x in range(15, 21):
yield (x, y)
elif 1 < y < 12:
x = 15
yield (x, y)
elif y == 12:
for x in range(15, 20):
yield (x, y)
def image_view(path):
filelist = os.listdir(path) # 该文件夹下所有的文件(包括文件夹)
for file in filelist:
if file is not os.path.isdir(path):
yield os.path.join(path, file)
def attach_image_to_Background(x, y, image):
fromImage = Image.open(image)
fromImage = fromImage.resize((100, 100), Image.ANTIALIAS)
toImage.paste(fromImage, (x * MW, y * MW))
def main():
try:
image_list = image_view(path)
t = function5()
for i in t:
attach_image_to_Background(i[0], i[1], image_list.__next__())
t = function2()
for i in t:
attach_image_to_Background(i[0], i[1], image_list.__next__())
t = function0()
for i in t:
attach_image_to_Background(i[0], i[1], image_list.__next__())
except IOError:
pass
toImage.show()
toImage.save(r'C:/Users/mm/Desktop/girls/avril.jpg')
if __name__ == '__main__':
MW = 100
MS = 22
MSize = MW * MS
toImage = Image.new('RGB', (2200, 2200))
path = r"C:/Users/mm/Desktop/girls/"
main()
网友评论