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

Invalid image kills thumbnail creation #134

Closed
kontza opened this issue Jan 3, 2015 · 6 comments
Closed

Invalid image kills thumbnail creation #134

kontza opened this issue Jan 3, 2015 · 6 comments

Comments

@kontza
Copy link

kontza commented Jan 3, 2015

Hi,

I was running sigal build and noticed that it died on thumbnail creation when the image file was not a valid image file. What had happened, was that the offending image was accidentally replaced with a text file, only the with the name of the original image file.

The failure occurred in image.py's generate_thumbnail-function when it ran the line
img = PILImage.open(source)

I think that a simple try-exceptaround that area would be OK, no need for a fancy rollback, just log the offending file name, or something alone those lines.

@saimn
Copy link
Owner

saimn commented Jan 3, 2015

Hi,
Which version of sigal are you running ? This case should be handled in the latest version at least.
If you are using the latest and still have the error, can you run in debug mode and paste the full log ?
Thanks

@kontza
Copy link
Author

kontza commented Jan 4, 2015

Hi,

I have an Ubuntu 14.04.1 LTS system, and sigal 0.9.1 was installed via sudo pip install sigal.

Here's the log. When I try-excepted the offending PILImage.open(source) and just returned from there, after a image failed -message, the processing went fine.

INFO - Reading settings ...
DEBUG - Settings file: sigal.conf.py
DEBUG - Rewrite source : torpantie -> /raid/home/juruotsa/Pictures/torpantie
DEBUG - Rewrite destination : _build -> /raid/home/juruotsa/Pictures/_build
DEBUG - Settings:
{'albums_sort_reverse': False,
 'autorotate_images': True,
 'colorbox_column_size': 4,
 'copy_exif_data': False,
 'destination': u'/raid/home/juruotsa/Pictures/_build',
 'files_to_copy': (),
 'google_analytics': '',
 'ignore_directories': [],
 'ignore_files': [],
 'img_processor': 'ResizeToFit',
 'img_size': (800, 600),
 'index_in_url': False,
 'jpg_options': {'optimize': True, 'progressive': True, 'quality': 85},
 'keep_orig': True,
 'links': '',
 'locale': '',
 'make_thumbs': True,
 'medias_sort_attr': 'filename',
 'medias_sort_reverse': False,
 'orig_dir': 'original',
 'orig_link': False,
 'output_filename': 'index.html',
 'plugin_paths': [],
 'plugins': [],
 'source': u'/raid/home/juruotsa/Pictures/torpantie',
 'theme': 'galleria',
 'thumb_dir': 'thumbnails',
 'thumb_fit': True,
 'thumb_prefix': '',
 'thumb_size': (280, 210),
 'thumb_suffix': '',
 'title': '',
 'use_orig': True,
 'video_size': (480, 360),
 'webm_options': ['-crf', '10', '-b:v', '1.6M', '-qmin', '4', '-qmax', '63'],
 'write_html': True,
 'zip_gallery': False,
 'zip_media_format': 'resized'}
INFO -       Source : /raid/home/juruotsa/Pictures/torpantie
INFO -  Destination : /raid/home/juruotsa/Pictures/_build
INFO -        Theme : galleria
DEBUG - Plugin paths: []
INFO - Using 1 cores
DEBUG - Albums:
[<Album>(path='.', title=u'torpantie')]
INFO - Processing /raid/home/juruotsa/Pictures/torpantie/./empty.jpg
Traceback (most recent call last):
  File "/usr/local/bin/sigal", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 610, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 590, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 936, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 782, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 416, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sigal/__init__.py", line 133, in build
    gal.build(force=force)
  File "/usr/local/lib/python2.7/dist-packages/sigal/gallery.py", line 601, in build
    process_file(media_item)
  File "/usr/local/lib/python2.7/dist-packages/sigal/gallery.py", line 638, in process_file
    ret = processor(*args[3:])
  File "/usr/local/lib/python2.7/dist-packages/sigal/image.py", line 156, in process_image
    fit=settings['thumb_fit'], options=options)
  File "/usr/local/lib/python2.7/dist-packages/sigal/image.py", line 119, in generate_thumbnail
    img = PILImage.open(source)
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 2028, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

@saimn
Copy link
Owner

saimn commented Jan 5, 2015

Hmm interesting, if I understand correctly your traceback, the exception is raised in https://github.com/saimn/sigal/blob/master/sigal/image.py#L155, but it should have failed a few lines before (https://github.com/saimn/sigal/blob/master/sigal/image.py#L149) and the exception would be catched in this case.
I cannot reproduce this behavior, maybe you can take a look to see why it isn't failing in generate_image (L149) ? Do you have an empy.jpg file generated in the output directory ?

@kontza
Copy link
Author

kontza commented Jan 8, 2015

Hi,

Sure I can test this tonight when I get back home from work.

@kontza
Copy link
Author

kontza commented Jan 9, 2015

Have you run with use_orig=Trueand orig_link=True?

When I ran build with those flags in their default mode, processing went fine, apart from error messages when processing empty.jpg. The empty file was not created into the output directory.
Here's the tail of build log when running with both flags set to their default values:

ERROR: Some files have failed to be processed:
ERROR:   - ./empty.jpg
ERROR: You can run sigal in verbose (--verbose) or debug (--debug) mode to get more details.

INFO: Theme  : /home/user/virtual_envs/sigal/local/lib/python2.7/site-packages/sigal-0.9.1-py2.7.egg/sigal/themes/galleria
INFO: Output album : <Album>(path='.', title=u'torpantie')
Done.
Processed 7 images (1 failed) and 0 videos in 1.97 seconds.

It looks fine: processed some files, and notes that one file failed.

But when use_origand orig_link are true, processing dies as I've described in the issue description.

P.s. I ran the tests on a virtualenv with git cloned sigal.

@saimn
Copy link
Owner

saimn commented Jan 11, 2015

Ah indeed, with these options the image is not read in generate_image and that's why it fails after inside generate_thumbnail. I saw your pr, thanks for your time to have worked on this, but I will push another fix soon.

@saimn saimn closed this as completed in 506ad36 Jan 11, 2015
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

2 participants