猫史档案馆


【Python作品分享】照片墙【作业帖】

用户:yj皓月当空yj皓月当空查看:0 回复:0 评论:0 创建时间:2020-03-18T11:08:12


【作品展示】

center_image

 

【作品介绍】

照片墙

 

【作品源代码】

import os 
from PIL import Image
import matplotlib.pyplot as plt

myDir = 'BCM'
files = os.listdir('BCM')
print(files)

# 常见的图片类型
images_ext = [".png",'.jpg','.bmp','.jpeg','.gif']
images = []
for file in files:
    name,ext = os.path.splitext(file)
    if ext in images_ext and 'bcm' in name:
        img = Image.open(myDir+os.sep+file)
        _img = img.resize((300,300))
        images.append(_img)

#print(images)

style = [[1, 0, 0, 0, 1],
         [0, 1, 0, 1, 0],
         [0, 0, 1, 0, 0],
         [0, 1, 0, 1, 0],
         [1, 0, 0, 0, 1]]

col = 5
row = 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))

plt.imshow(board)
plt.show()

# 保存
board.save("heart.png")

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页