diff options
author | José Fonseca <jfonseca@vmware.com> | 2013-04-18 20:30:49 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2013-04-18 20:30:49 +0100 |
commit | c9573b5be65ea1f5159b9ccc21d8fe9768a28fcd (patch) | |
tree | 90a2aaeead26014e16f8e6bfe1451b044300dee4 /scripts | |
parent | 10d04a2027fa6431ea69238e236f6ca75562e985 (diff) |
snapdiff: Zoom in small images.
Often used in tests.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/snapdiff.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/scripts/snapdiff.py b/scripts/snapdiff.py index 68989851..aa65f51c 100755 --- a/scripts/snapdiff.py +++ b/scripts/snapdiff.py @@ -42,7 +42,7 @@ from PIL import ImageEnhance 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) @@ -119,7 +119,18 @@ def surface(html, image): 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 |