# HG changeset patch # User Jeff Hammel # Date 1606330682 28800 # Node ID 529598840f4b84437bbc7684fd569f2aa8e2c79a # Parent 2ea5ec12176366e2a9d73fc288e206c2aaefd73f py3 diff -r 2ea5ec121763 -r 529598840f4b montage/formatters.py --- a/montage/formatters.py Tue Nov 03 09:55:39 2020 -0800 +++ b/montage/formatters.py Wed Nov 25 10:58:02 2020 -0800 @@ -92,20 +92,14 @@ try: image = Image.open(filepath) thumbnail_image = crop_resize(image, (self.width, self.height)) - fd = file(thumbnail_file, 'w') - flag = True - thumbnail_image.save(fd) - fd.close() - + with open(thumbnail_file, 'w') as fd: + flag = True + thumbnail_image.save(fd) except Exception, e: # failure to create thumbnail - # cleanup file - if flag: - fd.close() - os.remove(thumbnail_file) - + pass + # fix the path to point to the thumbnail if os.path.exists(thumbnail_file): f['path'] = '%s/%s/%s' % (f['path'].rsplit('/', 1)[0], self.thumb_dir, thumbnail) -