[Kimchi-devel] [project-kimchi][PATCHv2] screenshot: fix problem on Power of truncated picture

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Thu Dec 19 03:37:07 UTC 2013


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

PIL lib will report error because of picture information inconsistency,
this error may because of qemu screenshot generation,
work around this problem by load this image in advance
to prevent it raise error in thumbnail generation.
REF:
http://stackoverflow.com/questions/12984426/ \
    python-pil-ioerror-image-file-truncated-with-big-images

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/screenshot.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/kimchi/screenshot.py b/src/kimchi/screenshot.py
index b17a3ce..5cfea96 100644
--- a/src/kimchi/screenshot.py
+++ b/src/kimchi/screenshot.py
@@ -174,6 +174,12 @@ class VMScreenshot(object):
             self._create_black_image(thumbnail)
         else:
             im = Image.open(thumbnail)
+            try:
+                # Prevent Image lib from lazy load,
+                # work around pic truncate validation in thumbnail generation
+                im.load()
+            except Exception as e:
+                kimchi_log.warning("Image load with warning: %s." % e)
             im.thumbnail(self.THUMBNAIL_SIZE)
             im.save(thumbnail, "PNG")
 
-- 
1.8.1.2




More information about the Kimchi-devel mailing list