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

Cool program! I keep getting "broken data stream" error, though. #65

Closed
harold opened this issue Dec 19, 2019 · 7 comments · Fixed by #66
Closed

Cool program! I keep getting "broken data stream" error, though. #65

harold opened this issue Dec 19, 2019 · 7 comments · Fixed by #66

Comments

@harold
Copy link

harold commented Dec 19, 2019

Hi! Thanks for this program, it looks really neat and seems to do what I want. I really appreciate your efforts.

Every time I try to make a collage, I get this error:

image

I am able to open the images in eog and display them in the browser, so I think they're good. But it'd be cool if there was an option (or by default) to simply ignore images that aren't working for photocollage.

Thanks again, hope you have a nice day.

@adrienverge
Copy link
Owner

adrienverge commented Dec 21, 2019

Hey @harold, I'm glad you like it.

Do you have the problem on all types of images? Even with 2 or 3 small JPEG images?

Could you run photocollage from the command line, and change the code so that it displays the exact problem?

--- a/photocollage/render.py
+++ b/photocollage/render.py
@@ -260,7 +260,7 @@ class RenderingTask(Thread):
         return canvas
 
     def run(self):
-        try:
+        if True:
             canvas = PIL.Image.new(
                 "RGB", (int(self.page.w), int(self.page.h)), "white")
 
@@ -303,6 +303,3 @@ class RenderingTask(Thread):
 
             if self.on_complete:
                 self.on_complete(canvas)
-        except Exception as e:
-            if self.on_fail:
-                self.on_fail(e)

@harold
Copy link
Author

harold commented Dec 21, 2019

Hey @harold, I'm glad you like it.

Hey @adrienverge I'm glad you're glad I like it. Really neat program.

I'm away from the machine with the program and the images at the moment, but thanks for the pointer on where to disable the exception swallowing.

I imagine the program would indeed work with 2 or 3 small known-good images. The images I was trying to use are from various american government webcams (and so are likely to be without izzat). Knowing precisely what about the images is making the program sad would be interesting, so I will try again with the suggested patch.

I won't be able to try until Monday, or perhaps the Monday of the following week, as we're on holiday at the moment, but I'll let you know the results when I do.

Thanks again for your efforts and this great program; they're both much appreciated.

@harold
Copy link
Author

harold commented Dec 26, 2019

Ok, narrowed this down a bit today.

With the patch you suggested, the following stack trace is printed:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3/dist-packages/photocollage/render.py", line 279, in run
    img = self.resize_photo(c, use_cache=True)
  File "/usr/lib/python3/dist-packages/photocollage/render.py", line 224, in resize_photo
    int(round(cell.h))), method)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1804, in resize
    self.load()
  File "/usr/lib/python3/dist-packages/PIL/ImageFile.py", line 260, in load
    raise_ioerror(err_code)
  File "/usr/lib/python3/dist-packages/PIL/ImageFile.py", line 58, in raise_ioerror
    raise IOError(message + " when reading image file")
OSError: broken data stream when reading image file

eog and identify work fine w/ the image, however:

$ identify 2019-12-19T12_30_27Z__39546__-105005.jpg
2019-12-19T12_30_27Z__39546__-105005.jpg JPEG 800x450 800x450+0+0 8-bit sRGB 49687B 0.000u 0:00.000

I'll attach the image here as well:
2019-12-19T12_30_27Z__39546__-105005

Adding this single image to photocollage is enough to produce the errors mentioned above.

Hope that helps; I am not a python or PIL expert by any means, so I'm not quite sure what's going on.

Take care, and thanks again for this rad program.

@harold
Copy link
Author

harold commented Dec 26, 2019

Happily, right click -> save as... on the image from here and adding it to photocollage still produces the error. 🎄

@adrienverge
Copy link
Owner

Hey @harold,

I can confirm the bug, even without running PhotoCollage:

$ python3 -c "import PIL.Image; PIL.Image.open('/tmp/image.jpg').resize((400, 225))"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.7/site-packages/PIL/Image.py", line 1890, in resize
    self.load()
  File "/usr/lib64/python3.7/site-packages/PIL/ImageFile.py", line 272, in load
    raise_ioerror(err_code)
  File "/usr/lib64/python3.7/site-packages/PIL/ImageFile.py", line 58, in raise_ioerror
    raise IOError(message + " when reading image file")
OSError: broken data stream when reading image file

By searching the error on Pillow issues it seems that we can tell the lib PIL to continue, even if the input image is corrupted, using LOAD_TRUNCATED_IMAGES.
I'll create a PR, please give feedback if it works for you 😉

adrienverge added a commit that referenced this issue Dec 27, 2019
Avoid "OSError: broken data stream when reading image file" on truncated
files; instead, try to continue reading the file if possible.

Fixes #65.
@harold
Copy link
Author

harold commented Dec 27, 2019

Just tried this patch out on my local install and it works!

image

👏

adrienverge added a commit that referenced this issue Dec 27, 2019
Avoid "OSError: broken data stream when reading image file" on truncated
files; instead, try to continue reading the file if possible.

Fixes #65.
@harold
Copy link
Author

harold commented Dec 27, 2019

One more for fun. 😄

road-collage-2

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

Successfully merging a pull request may close this issue.

2 participants