close

[Solved] Python PIL “IOError: image file truncated” with big images

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python PIL “IOError: image file truncated” with big images in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python PIL “IOError: image file truncated” with big images Error Occurs?

Today I get the following error Python PIL “IOError: image file truncated” with big images in python.

How To Solve Python PIL “IOError: image file truncated” with big images Error ?

  • 1. How To Solve Python PIL “IOError: image file truncated” with big images Error ? To Solve Python PIL “IOError: image file truncated” with big images Error It turns out that you can ask PIL to be tolerant of files that are truncated (missing some file from the block) by changing a setting.
  • 2.Python PIL “IOError: image file truncated” with big images To Solve Python PIL “IOError: image file truncated” with big images Error It turns out that you can ask PIL to be tolerant of files that are truncated (missing some file from the block) by changing a setting. Add Image

Add A Question

Solution 1

Here is what I did:

  • Edit LOAD_TRUNCATED_IMAGES = False line from /usr/lib/python3/dist-packages/PIL/ImageFile.py:40 to LOAD_TRUNCATED_IMAGES = True.

Editing the file requires root access though. I encountered this error while running some pytorch which was maybe using the PIL library.

Do this fix only if you encounter this error, without directly using PIL.

Else please do

Solution 2


I’m a little late to reply here, but I ran into a similar problem and I wanted to share my solution. First, here’s a pretty typical stack trace for this problem:

If we look around line 220 (in your case line 201—perhaps you are running a slightly different version), we see that PIL is reading in blocks of the file and that it expects that the blocks are going to be of a certain size. It turns out that you can ask PIL to be tolerant of files that are truncated (missing some file from the block) by changing a setting.

Somewhere before your code block, simply add the following:

…and you should be good.

EDIT: It looks like this helps for the version of PIL bundled with Pillow (“pip install pillow”), but may not work for default installations of PIL

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read