Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error with truncated images #10

Open
jfolli1 opened this issue Oct 27, 2014 · 6 comments
Open

error with truncated images #10

jfolli1 opened this issue Oct 27, 2014 · 6 comments

Comments

@jfolli1
Copy link

jfolli1 commented Oct 27, 2014

Hi. I'll admit I am new to Ubuntu / Linux. But I appreciate the work you have done on this. I received the following error when trying to run your program as-is just with updated defaults and requirements.

Found name of image: helix_blancoHubble_6145.jpg
File exists, moving on
Opening local image
Resizing the image from 6145 x 6623 to 2560 x 1440
Traceback (most recent call last):
File "/home/jason/Documents/random-nasa-wallpaper.py", line 425, in
filename = create_desktop_background_scoll(filename)
File "/home/jason/Documents/random-nasa-wallpaper.py", line 319, in create_desktop_background_scoll
resize_image(seed_filename)
File "/home/jason/Documents/random-nasa-wallpaper.py", line 246, in resize_image
image = image.resize((RESOLUTION_X, RESOLUTION_Y), Image.ANTIALIAS)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1319, in resize
self.load()
File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 218, in load
raise IOError("image file is truncated (%d bytes not processed)" % len(b))
IOError: image file is truncated (3 bytes not processed)

After researching thie IOError some people recommended to change a setting in PIL as follows to allow the program to conintinue to run.

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

I added this after the import statements.

Doing so allows your script to run however some of the pictures are completed with black pixels/data due to the truncated image.

I am not sure of the root solution at this time I just did this quick fix to get it up and working. I will look more into it as I have time but maybe you will find the problem quicker.

Thanks

@randomdrake
Copy link
Owner

Hello @jfolli1 thanks for the report! I'm actually not running an Ubuntu box at this time.

Any additional information you could provide on this such as the versions of the OS and languages/libraries used would be appreciated. When I get time I can spin up a correct image and see if I can't fiddle with it or merge a possible pull request.

@jfolli1
Copy link
Author

jfolli1 commented Oct 28, 2014

Ah yes absolutely. It is the desktop version of ubuntu 14.04 LTS (64bit). I have not done much if anything at all besides a sudo apt-get upgrade and whatever ubuntu updates it asked to perform.

I will try and find the versions of dependancies I used and update to try and make this a bit more re-producable

@arturvsantos
Copy link

I found a very similar error whilst I'm running the python script. Check it out:

#️⃣ ./nasa_apod_desktop.py
Traceback (most recent call last):
File "./nasa_apod_desktop.py", line 422, in
filename = create_desktop_background_scoll(filename)
File "./nasa_apod_desktop.py", line 316, in create_desktop_background_scoll
resize_image(seed_filename)
File "./nasa_apod_desktop.py", line 243, in resize_image
image = image.resize((RESOLUTION_X, RESOLUTION_Y), Image.ANTIALIAS)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1536, in resize
self.load()
File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 229, in load
"(%d bytes not processed)" % len(b))
IOError: image file is truncated (1 bytes not processed)

I'm using Ubuntu 15.04 amd64 and my kernel is 3.19.0-25-generic

@Nasjoe
Copy link

Nasjoe commented Sep 17, 2017

Same here :


Traceback (most recent call last):
  File "./nasa_apod_desktop.py", line 422, in <module>
    filename = create_desktop_background_scoll(filename)
  File "./nasa_apod_desktop.py", line 316, in create_desktop_background_scoll
    resize_image(seed_filename)
  File "./nasa_apod_desktop.py", line 243, in resize_image
    image = image.resize((RESOLUTION_X, RESOLUTION_Y), Image.ANTIALIAS)
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1526, in resize
    self.load()
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFile.py", line 204, in load
    raise IOError("image file is truncated")
IOError: image file is truncated

@Nasjoe
Copy link

Nasjoe commented Sep 17, 2017

@jgieseler
Copy link

For me this solution from the stackoverflow discussion solved the problem:
https://stackoverflow.com/a/20068394

Just replace the line

image = image.resize((RESOLUTION_X, RESOLUTION_Y), Image.ANTIALIAS)

with the following:

try:
    image = image.resize((RESOLUTION_X, RESOLUTION_Y), Image.ANTIALIAS)
except IOError:
    pass # You can always log it to logger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants