我想写我的第一个真正的Python真正的功能。我想要完成的是搜索给定的文件夹,然后打开所有图像并将它们合并在一起,以便制作幻灯片图像。想象一下,将5幅图像叠加在彼此之上。如何完成这个python函数来保存在同一个文件夹中?
我现在有这样的代码,这应该是非常好的,但propably需要做一些修改:
import os
import Image
def filmstripOfImages():
imgpath = '/path/here/'
files = glob.glob(imgpath + '*.jpg')
imgwidth = files[0].size[0]
imgheight = files[0].size[1]
totalheight = imgheight * len(files)
filename = 'filmstrip.jpg'
filmstrip_url = imgpath + filename
# Create the new image. The background doesn't have to be white
white = (255,255,255)
filmtripimage = Image.new('RGB',(imgwidth, totalheight),white)
row = 0
for file in files:
img = Image.open(file)
left = 0
right = left + imgwidth
upper = row*imgheight
lower = upper + imgheight
box = (left,upper,right,lower)
row += 1
filmstripimage.paste(img, box)
try:
filmstripimage.save(filename, 'jpg', quality=90, optimize=1)
except:
filmstripimage.save(miniature_filename, 'jpg', quality=90)")
如何修改这一点,以便它保存在同一目录新filmstrip.jpg我加载图像?它可能有一些缺失或错误的东西,任何人都有线索?
相关问题:How to generate a filmstrip image in python from a folder of images?
您忘记导入水珠(或忘了粘贴import语句) – Jiaaro 2008-12-03 00:37:10
你忘了尝试运行代码至少一次 – nosklo 2008-12-03 01:24:18