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

Aline Manera alinefm at linux.vnet.ibm.com
Thu Dec 19 12:44:54 UTC 2013


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 12/19/2013 01:37 AM, lvroyce at linux.vnet.ibm.com wrote:
> 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")
>




More information about the Kimchi-devel mailing list