用户:
雪球July查看:1 回复:3 评论:1 创建时间:2021-12-19T20:09:52
【作品展示】

【作品介绍】
style列表里面的数据只有0和1(0为无图片,1为有图片),按需要输入即可;列表也可以改,只要是一个二维列表(外层列表和内层列表长度要一至(列:外:5,内:5))。其他看注释。
【作品源代码】
import os
from PIL import Image
import matplotlib.pyplot as plt
# 请在下面的二维列表里输入图像
style = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0],
[0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
wide_x = 300
high_y = 300
def my_paste(style, myDir, save_name, wide_x, high_y):
files = os.listdir(myDir)
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((wide_x, high_y))
images.append(_img)
# print(images)
col = len(style)
row = len(style[1])
#
board = Image.new("RGBA", (high_y*col, wide_x*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*high_y, i*wide_x))
plt.imshow(board)
plt.show()
board.save(".png")
# 调用函数,请依次输入:style, 图片所在文件夹(与程序同目录下), 要保存的图片名,wide_x, high_y
my_paste(style, "BCM", "胡", wide_x, high_y)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn
全宇宙最酸的柠檬< p > 好好照顾自己,记得按时喝酒,不舒服就多抽烟,每天好好熬夜,天冷了多穿几件短袖,过马路别忘了玩手机,记得多吃宵夜,不要天天吃早饭,天冷了记得穿凉鞋。车多的时候记得反复横跳哦
点赞1
评论
雪球July这作者真屑imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E6%90%93%E5%A4%B4.gif"alt="emotion_编程猫_搓头"
点赞0
评论