diff --git a/sigal/gallery.py b/sigal/gallery.py index 62e2689..e0c1cbe 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -41,7 +41,7 @@ from PIL import Image as PILImage from . import image, video, signals from .compat import PY2, UnicodeMixin, strxfrm, url_quote, text_type -from .image import process_image, get_exif_tags, get_exif_data +from .image import process_image, get_exif_tags, get_exif_data, get_size from .settings import get_thumb from .utils import (Devnull, copy, check_or_create_dir, url_from_path, read_markdown, cached_property, is_valid_html5_video, @@ -168,6 +168,14 @@ class Image(Media): self.src_path) return None + @cached_property + def size(self): + try: + return get_size(self) + except (IOError, IndexError, TypeError, AttributeError): + self.logger.warning(u'Could not read size %s', + self.src_path) + return None class Video(Media): """Gather all informations on a video file.""" @@ -371,7 +379,7 @@ class Album(UnicodeMixin): except: self.logger.error("Failed to open %s", f.src_path) else: - if im.size[0] > im.size[1]: + if im.size[0] > im.size[1]: self._thumbnail = join(self.name, f.thumbnail) self.logger.debug( "Use 1st landscape image as thumbnail for %r :" diff --git a/sigal/image.py b/sigal/image.py index 0450ded..f0b40f4 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -160,6 +160,18 @@ def process_image(filepath, outpath, settings): return Status.SUCCESS +def get_size(filename): + """Return image size.""" + big = PILImage.open(filename.dst_path) + widthBig,heightBig = big.size + thumb = PILImage.open(filename.thumb_path) + widthThumb,heightThumb = thumb.size + data = { + 'big' : {'width': widthBig, 'height': heightBig}, + 'thumbnail': {'width': widthThumb, 'height': heightThumb}, + } + return data + def get_exif_data(filename): """Return a dict with the raw EXIF data."""