批量生成找不同图片
父亲开始玩快手,要做这样的视频:一开始他都是手工输入文字,为了给他减轻一点工作量,我写了个简单的Python脚本,一次性把所有三位数全部搞定,代码如下,还望大家指点,给点改进意见
# -*- coding: utf-8 -*-
import random
import os
from PIL import Image, ImageFont, ImageDraw
def drawatcenter(data,text,y,color,fon):
w,h=data.textsize(text,font=fon)
data.multiline_text(((900-w)/2.0,y-h/2.0),text,fill=color,font=fon,
spacing=50)
#bcolor=random.randint(0,127),random.randint(0,127),random.randint(0,127))
bcolor=(51,102,204)
fontname="DFPHeiBold-B5.ttc" #要替换成你电脑上有的字体名
fcolor=(255,255,255)
for num in range(101,1000):
if not (num%100)//10==num%10:
text = u"找到"
print(num)
nmu=(num//100)*100+10*(num%10)+(num%100)//10
print(nmu)
a=
a=nmu
print(a)
text=text+str(nmu)
txt=""
for i in range(35):
txt=txt+str(a)
if i%5==4:
txt=txt+'\n'
else:
txt=txt+' '
im = Image.new("RGB", (900, 1600), bcolor)
dr = ImageDraw.Draw(im)
font = ImageFont.truetype(os.path.join("fonts", fontname), 144)
drawatcenter(dr,text,200,"orange",font)
font = ImageFont.truetype(os.path.join("fonts", fontname), 90)
drawatcenter(dr,txt,700,fcolor,font)
#im.show()
im.save(str(num)+"-0.png")
font = ImageFont.truetype(os.path.join("fonts", fontname), 160)
im = Image.new("RGB", (900,200), "orange")
dr = ImageDraw.Draw(im)
w,h=dr.textsize(text,font=font)
drawatcenter(dr,text,100,fcolor,font)
im.save(str(num)+"-1.png") #这个保存的是视频封面,也就是视频第一帧的字幕
兄弟,我感觉你复杂了,你整个EXCEL,写个VBA不简单吗? dcahptl 发表于 2021-9-1 17:06
兄弟,我感觉你复杂了,你整个EXCEL,写个VBA不简单吗?
如果用Excel+VBA,要怎样保存图片? yzhiyu 发表于 2021-9-1 19:30
如果用Excel+VBA,要怎样保存图片?
VBA可以截图
页:
[1]