changeset 39:529598840f4b

py3
author Jeff Hammel <k0scist@gmail.com>
date Wed, 25 Nov 2020 10:58:02 -0800
parents 2ea5ec121763
children 77c3439e76bb
files montage/formatters.py
diffstat 1 files changed, 5 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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)
-