我有代码:
class Gallery():
def __init__(self, directory = '.'):
self.imgnames = []
self.directory = directory
def get_files(self):
self.filenames = os.listdir(self.directory)
logging.debug("Directory files: %s" % self.filenames)
def generate_thumbnails(self):
counter = 0
for name in self.filenames:
logging.debug("Trying to open %s" % name)
counter+= 1
if name == "loading.gif":
continue
try:
im = Image.open(name)
self.imgnames.append(name)
im.thumbnail( (300,300) )
logging.debug("Saving thumb-%s" % name)
im.save("thumb-%s" % name)
sys.stdout.write("\r%f%%" % (counter*100.0/len(self.filenames)))
sys.stdout.flush()
except IOError:
logging.debug("File %s cannot be parsed by PIL, ignoring" % name)
def integrate_bootstrap(self):
logging.info("Generating index.html")
head = open("./gallery_files/index.html.head", 'r').read()
tail = open("./gallery_files/index.html.tail", 'r').read()
final = open("index.html", 'w')
,我想更改图像缩略图目录以保存到./gallery_files/thumbs /
当我将im.save(“ thumb-%s”%name)更改为im.save(“ ./ gallery_files / thumbs / thumb-%s”%name)时。
有什么想法吗?谢谢
答案 0 :(得分:1)
很遗憾,我无法评论您的问题。因此,我想给您一个答案:
怎么了?
文件夹./gallery_files/thumbs/
是否存在?如果没有,那么需要先创建它,然后再保存。