Skip to content

3.2.0 DIB saving on Windows fails "image file is truncated" error #1810

Description

@techtonik

What did you do?

1 open mspaint
2 alt+prtscr
3 run the code

#!/usr/bin/env python

import os, sys
from PIL import ImageGrab

im = ImageGrab.grabclipboard()

if im is None:
  sys.exit('Error: No image data in clipboard')

im.show()

What did you expect to happen?

The image from clipboard is shown on the screen:

image

What actually happened?

Traceback (most recent call last):
  File "savebmp.py", line 13, in <module>
    im.show()
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 1730, in show
    _show(self, title=title, command=command)
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 2480, in _show
    _showxv(image, **options)
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 2485, in _showxv
    ImageShow.show(image, title, **options)
  File "C:\Python27\lib\site-packages\PIL\ImageShow.py", line 51, in show
    if viewer.show(image, title=title, **options):
  File "C:\Python27\lib\site-packages\PIL\ImageShow.py", line 75, in show
    image = image.convert(base)
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 846, in convert
    self.load()
  File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 218, in load
    "(%d bytes not processed)" % len(b))
IOError: image file is truncated (1312 bytes not processed)

What versions of Pillow and Python are you using?

Python 2.7, Pillow 3.2.0

Activity

  1. hugovk commented on Apr 6, 2016

    @hugovk
    Member

    With same Python/Pillow on Win7, I get a similar result when running the code as a script.

    Edit: also get similar result in IDLE.

  2. techtonik commented on Apr 6, 2016

    @techtonik
    ContributorAuthor

    @hugovk im == None can only be shown in one case - when you don't have any data in clipboard. Otherwise you should get Traceback.

  3. hugovk commented on Apr 6, 2016

    @hugovk
    Member

    @techtonik Yes, see my edit. (I'd run the test incorrectly.)

  4. techtonik commented on Apr 6, 2016

    @techtonik
    ContributorAuthor

    /cc @artscoop - do you know why it thinks the image file is truncated? Here is the image __dict__:

    {
        'info': {'compression': 3, 'dpi': (0, 0)},
        'category': 0,
        'palette': None,
        'pyaccess': None,
        'decoderconfig': (),
        'filename': None,
        'fp': < _io.BytesIO object at 0x023397E0 > ,
        'readonly': 1,
        'im': None,
        'mode': 'RGBA',
        'decodermaxblock': 65536,
        'tile': [
          ('raw', (0, 0, 329, 423), 56L, ('BGRA', 1316, -1)),
        ],
        'size': (329, 423),
    }
  5. hugovk commented on Apr 6, 2016

    @hugovk
    Member

    PR #1813 is merged, so this should be fixed too.

  6. techtonik commented on Apr 7, 2016

    @techtonik
    ContributorAuthor

    In https://ci.appveyor.com/project/techtonik/pillow/build/3.3.pre.11/artifacts wheel I am not getting the image file is truncated message anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions