用户:
飒天查看:7 回复:1 评论:7 创建时间:2020-02-13T19:05:46
大家看一下这个点阵照片墙,报错显示被除数不能为零,那个大佬修改一下?
import os
from PIL import Image
myDir = 'gnx'
files = os.listdir(myDir)
# 常见的图片类型
images_ext = [".png", ".jpg", ".bmp", ".jpeg", ".gif"]
images = []
for file in files:
name, ext = os.path.splitext(file)
if ext in images_ext and 'gnx' in name:
img = Image.open(myDir+os.sep+file)
_img = img.resize((300, 300))
images.append(_img)
style =[[0, 1, 0, 1, 0],
[0, 1, 1, 1, 0],
[1, 1, 1, 1, 1],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0]]
row = 5
col = 5
# 创建空白图片
board = Image.new('RGBA', (300*col, 300*row))
# 粘贴图片
for i in range(row):
for j in range(col):
# 点阵判断
if style[i][j] == 1:
index = j + col*i
board.paste(images[index %len(images)], (j*300, i*300))
# 保存图片
board.save('wang.png')