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

Thumbnails gets recreated unrotated #211

Closed
bazuchan opened this issue Jul 12, 2016 · 6 comments
Closed

Thumbnails gets recreated unrotated #211

bazuchan opened this issue Jul 12, 2016 · 6 comments
Milestone

Comments

@bazuchan
Copy link
Contributor

Steps to reproduce:

  1. Generate album with autorotate_images = True and photoswipe theme. Thumbnails are generated as it should.
  2. Remove thumbnails folder leaving everything else intact.
  3. Generate album again. Thumbnails now are unrotated.

Reason seems to be that first time thumbnails was generated from output images and second time from source images.

@saimn
Copy link
Owner

saimn commented Jul 12, 2016

Hmm this should not happen, unless you put the build directory inside the source one ? Can you post the output in debug mode for the two runs (with a small test gallery) ?

@bazuchan
Copy link
Contributor Author

Problem doesn't happen when sigal runs in debug mode. So I quickpached image.py:

--- /usr/lib/python2.7/dist-packages/sigal/image.py.orig        2016-07-13 11:25:36.497287232 +0300
+++ /usr/lib/python2.7/dist-packages/sigal/image.py     2016-07-13 11:25:16.053322630 +0300
@@ -130,6 +130,7 @@

     outformat = img.format or original_format or 'JPEG'
     logger.debug(u'Save thumnail image: {0} ({1})'.format(outname, outformat))
+    print(u'\nThubnail: %s -> %s' % (source, outname))
     save_image(img, outname, outformat, options=options, autoconvert=True)

First run - creating from scratch - thumbnails is ok.
Second - recreating thumbnails - thumbnails is unrotated.
Third - recreating thumbnails in debug mode - thumbnails is ok.

tarantula!baz% rm -rf dst/

tarantula!baz% grep '^source\|^dest\|^theme' sigal.conf.py
source = '/home/baz/testgal/src'
destination = '/home/baz/testgal/dst'
theme = 'photoswipe'

tarantula!baz% sigal build
Sorting albums  [####################################]  100%
Sorting media  [####################################]  100%
Collecting files  [####################################]  100%
Processing files  [------------------------------------]  0/2
Thubnail: /home/baz/testgal/dst/IMG_20160503_221401_z5c.jpg -> /home/baz/testgal/dst/thumbnails/IMG_20160503_221401_z5c.jpg
Processing files  [##################------------------]  1/2
Thubnail: /home/baz/testgal/dst/IMG_20160503_221409_z5c.jpg -> /home/baz/testgal/dst/thumbnails/IMG_20160503_221409_z5c.jpg
Processing files  [####################################]  2/2

Done.
Processed 2 images and 0 videos in 0.66 seconds.

tarantula!baz% rm -rf dst/thumbnails/

tarantula!baz% sigal build
Sorting albums  [####################################]  100%
Sorting media  [####################################]  100%
Collecting files  [####################################]  100%
Processing files  [------------------------------------]  0/0


Thubnail: /home/baz/testgal/src/./IMG_20160503_221409_z5c.jpg -> /home/baz/testgal/dst/./thumbnails/IMG_20160503_221409_z5c.jpg
Done.
Processed 0 images (2 skipped) and 0 videos in 0.34 seconds.

tarantula!baz% rm -rf dst/thumbnails/

tarantula!baz% sigal build -fd -n 1
INFO: Reading settings ...
DEBUG: Settings file: sigal.conf.py
DEBUG: Settings:
{'albums_sort_attr': 'name',
 'albums_sort_reverse': False,
 'autorotate_images': True,
 'colorbox_column_size': 4,
 'copy_exif_data': False,
 'destination': u'/home/baz/testgal/dst',
 'files_to_copy': (),
 'google_analytics': '',
 'ignore_directories': [],
 'ignore_files': [],
 'img_processor': 'ResizeToFit',
 'img_size': (1024, 768),
 'index_in_url': False,
 'jpg_options': {'optimize': True, 'progressive': True, 'quality': 85},
 'keep_orig': False,
 'links': '',
 'locale': '',
 'make_thumbs': True,
 'medias_sort_attr': 'filename',
 'medias_sort_reverse': False,
 'mp4_options': ['-crf', '23', '-strict', '-2'],
 'orig_dir': 'original',
 'orig_link': False,
 'output_filename': 'index.html',
 'piwik': {'site_id': 0, 'tracker_url': ''},
 'plugin_paths': [],
 'plugins': [],
 'show_map': False,
 'source': u'/home/baz/testgal/src',
 'theme': 'photoswipe',
 'thumb_dir': 'thumbnails',
 'thumb_fit': True,
 'thumb_prefix': '',
 'thumb_size': (200, 150),
 'thumb_suffix': '',
 'thumb_video_delay': '0',
 'title': '',
 'use_assets_cdn': True,
 'use_orig': False,
 'video_format': 'webm',
 'video_size': (720, 640),
 'watermark': u'',
 'webm_options': ['-crf', '10', '-b:v', '1.6M', '-qmin', '4', '-qmax', '63'],
 'write_html': True,
 'zip_gallery': False,
 'zip_media_format': 'resized'}
INFO:       Source : /home/baz/testgal/src
INFO:  Destination : /home/baz/testgal/dst
INFO:        Theme : photoswipe
DEBUG: Plugin paths: []
INFO: Using 1 cores
DEBUG: Albums:
[<Album>(path='.', title=u'src')]
INFO: Processing /home/baz/testgal/src/./IMG_20160503_221401_z5c.jpg
DEBUG: Processor: ResizeToFit
DEBUG: Save resized image to /home/baz/testgal/dst/IMG_20160503_221401_z5c.jpg (JPEG)
DEBUG: Save thumnail image: /home/baz/testgal/dst/thumbnails/IMG_20160503_221401_z5c.jpg (JPEG)

Thubnail: /home/baz/testgal/dst/IMG_20160503_221401_z5c.jpg -> /home/baz/testgal/dst/thumbnails/IMG_20160503_221401_z5c.jpg
INFO: Processing /home/baz/testgal/src/./IMG_20160503_221409_z5c.jpg
DEBUG: Processor: ResizeToFit
DEBUG: Save resized image to /home/baz/testgal/dst/IMG_20160503_221409_z5c.jpg (JPEG)
DEBUG: Save thumnail image: /home/baz/testgal/dst/thumbnails/IMG_20160503_221409_z5c.jpg (JPEG)

Thubnail: /home/baz/testgal/dst/IMG_20160503_221409_z5c.jpg -> /home/baz/testgal/dst/thumbnails/IMG_20160503_221409_z5c.jpg

INFO: Theme  : /usr/lib/python2.7/dist-packages/sigal/themes/photoswipe
INFO: Output album : <Album>(path='.', title=u'src')
Done.
Processed 2 images and 0 videos in 0.85 seconds.

@bazuchan
Copy link
Contributor Author

--- /usr/lib/python2.7/dist-packages/sigal/image.py.orig        2016-07-13 11:25:36.497287232 +0300
+++ /usr/lib/python2.7/dist-packages/sigal/image.py     2016-07-13 12:05:49.304447706 +0300
@@ -130,6 +130,9 @@

     outformat = img.format or original_format or 'JPEG'
     logger.debug(u'Save thumnail image: {0} ({1})'.format(outname, outformat))
+    print(u'\nThubnail: %s -> %s' % (source, outname))
+    import traceback
+    traceback.print_stack()
     save_image(img, outname, outformat, options=options, autoconvert=True)

Thubnail: /home/baz/testgal/src/./IMG_20160503_221409_z5c.jpg -> /home/baz/testgal/dst/./thumbnails/IMG_20160503_221409_z5c.jpg
  File "/usr/bin/sigal", line 9, in <module>
    load_entry_point('sigal==1.2.0', 'console_scripts', 'sigal')()
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/sigal/__init__.py", line 142, in build
    gal.build(force=force)
  File "/usr/lib/python2.7/dist-packages/sigal/gallery.py", line 667, in build
    writer.write(album)
  File "/usr/lib/python2.7/dist-packages/sigal/writer.py", line 111, in write
    page = self.template.render(**self.generate_context(album))
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 986, in render
    return concat(self.root_render_func(self.new_context(vars)))
  File "/usr/lib/python2.7/dist-packages/sigal/themes/photoswipe/templates/index.html", line 30, in root
    {% endif %}
  File "/usr/lib/python2.7/dist-packages/sigal/themes/photoswipe/templates/index.html", line 118, in block_content
    <div class="pswp__item"></div>
  File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 408, in getattr
    return getattr(obj, attribute)
  File "/usr/lib/python2.7/dist-packages/sigal/gallery.py", line 124, in thumbnail
    fit=self.settings['thumb_fit'])
  File "/usr/lib/python2.7/dist-packages/sigal/image.py", line 135, in generate_thumbnail
    traceback.print_stack()

@saimn
Copy link
Owner

saimn commented Jul 25, 2016

Sorry it took some time before I could come back to this. So yes, actually you were right when you said "Reason seems to be that first time thumbnails was generated from output images and second time from source images."

It is the result of both a side effect from another feature (the possibility to generate thumbnail only when the theme request them, and when they have not been generated in the image processing step), and from the fact that you deleted only the thumbnail directory.
To sum up the current behavior:

  • Sigal checks in the dst directory if the resized image exists (but it doesn't check the thumbnail). If it exists the image is not generated (neither the thumbnail in your case). Otherwise it generates the image and the thumbnail from the processed image.
  • Later, when the templates are rendered, missing thumbnails can be generated, but then Sigal does not track generated files, so it is done from the src (un-rotated) image.

So, what could be done is to check if both the thumbnail and image exists to know if an image must be processed. But really, for me it is an edge-case, the state of the dst directory should not be inconsistent with what sigal expects from your settings.

@bazuchan
Copy link
Contributor Author

So, what could be done is to check if both the thumbnail and image exists to know if an image must be processed. But really, for me it is an edge-case, the state of the dst directory should not be inconsistent with what sigal expects from your settings.

I needed to change theme (on 100+GB source dir) with different thumbnail size and didn't wanted to reprocess all images and reencode videos.

@saimn
Copy link
Owner

saimn commented Aug 1, 2016

@bazuchan - Ok, actually it makes sense to always generate the thumbnail from the processed image, so I fixed that (239d7d0). Thanks !

@saimn saimn closed this as completed Aug 1, 2016
@saimn saimn added this to the 1.3.0 milestone Aug 1, 2016
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