from PIL import ImageFilter
-thumb_size = 320, 320
+thumbSize = 320
gaussian_kernel = ImageFilter.Kernel((3, 3), [1, 2, 1, 2, 4, 2, 1, 2, 1], 16)
and (not os.path.exists(thumb) \
or os.path.getmtime(thumb) < os.path.getmtime(image)):
im = Image.open(image)
- im.thumbnail(thumb_size)
+ imageWidth, imageHeight = im.size
+ if imageWidth <= thumbSize and imageHeight <= thumbSize:
+ if imageWidth >= imageHeight:
+ imageHeight = imageHeight*thumbSize/imageWidth
+ imageWidth = thumbSize
+ else:
+ imageWidth = imageWidth*thumbSize/imageHeight
+ imageHeight = thumbSize
+ html.write(' <td><img src="%s" width="%u" height="%u"/></td>\n' % (image, imageWidth, imageHeight))
+ return
+
+ im.thumbnail((thumbSize, thumbSize))
im.save(thumb)
else:
thumb = image