]> git.cworth.org Git - apitrace/commitdiff
snapdiff: Zoom in small images.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 18 Apr 2013 19:30:49 +0000 (20:30 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 18 Apr 2013 19:30:49 +0000 (20:30 +0100)
Often used in tests.

scripts/snapdiff.py

index 689898512acd75ff1e23b06ce2af2f5b09352d24..aa65f51c036b3b871279ea8774b8f2d0d69a8584 100755 (executable)
@@ -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