diff --git a/sigal/gallery.py b/sigal/gallery.py index db91a93..3ee783c 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -103,11 +103,11 @@ class PathsDb(object): self.db[relpath].update(get_metadata(path)) path_media = [path for path in self.db['paths_list'] - if (self.db[path]['img'] or self.db[path]['vid']) and - path != '.'] - path_nomedia = [path for path in self.db['paths_list'] if not - (self.db[path]['img'] or self.db[path]['vid']) and path != - '.'] + if (self.db[path]['img'] or self.db[path]['vid']) + and path != '.'] + path_nomedia = [path for path in self.db['paths_list'] + if not (self.db[path]['img'] or self.db[path]['vid']) + and path !='.'] # dir with images: check the thumbnail, and find it if necessary for path in path_media: @@ -264,14 +264,15 @@ def process_image(filepath, outpath, settings): if settings['keep_orig']: shutil.copy(filepath, join(outpath, settings['orig_dir'], filename)) - sigal.image.generate_image(filepath, outname, settings['img_size'], None, - options=options, copyright_text=settings['copyright'], - method=settings['img_processor']) + sigal.image.generate_image(filepath, outname, settings['img_size'], + None, options=options, copyright_text=settings['copyright'], + method=settings['img_processor']) if settings['make_thumbs']: thumb_name = join(outpath, get_thumb(settings, filename)) - sigal.image.generate_thumbnail(outname, thumb_name, settings['thumb_size'], None, - fit=settings['thumb_fit'], options=options) + sigal.image.generate_thumbnail(outname, thumb_name, + settings['thumb_size'], None, fit=settings['thumb_fit'], + options=options) def process_video(filepath, outpath, settings): """Process one image: resize, create thumbnail.""" @@ -283,11 +284,13 @@ def process_video(filepath, outpath, settings): if settings['keep_orig']: shutil.copy(filepath, join(outpath, settings['orig_dir'], filename)) - sigal.video.generate_video(filepath, outname) + # TODO: Add specific video size settings + sigal.video.generate_video(filepath, outname, settings['img_size']) if settings['make_thumbs']: - thumb_name = join(outpath, get_thumb(settings, base + '.jpg')) - sigal.video.generate_thumbnail(outname, thumb_name) + thumb_name = join(outpath, get_thumb(settings, filename)) + sigal.video.generate_thumbnail(outname, thumb_name, + settings['thumb_size']) def get_metadata(path): diff --git a/sigal/settings.py b/sigal/settings.py index a71bf9d..cf5598d 100644 --- a/sigal/settings.py +++ b/sigal/settings.py @@ -49,10 +49,23 @@ _DEFAULT_CONFIG = { def get_thumb(settings, filename): - """Return the path to the thumb.""" + """Return the path to the thumb. + + examples: + >>> get_thumb(default_settings, "bar/foo.jpg") + "bar/thumbnails/foo.jpg" + >>> get_thumb(default_settings, "bar/foo.png") + "bar/thumbnails/foo.png" + + for videos, it returns a jpg file: + >>> get_thumb(default_settings, "bar/foo.webm") + "bar/thumbnails/foo.jpg" + """ path, filen = os.path.split(filename) name, ext = os.path.splitext(filen) + if ext in settings['vid_ext_list']: + ext = '.jpg' return os.path.join(path, settings['thumb_dir'], settings['thumb_prefix'] + name + settings['thumb_suffix'] + ext) diff --git a/sigal/themes/galleria/templates/index.html b/sigal/themes/galleria/templates/index.html index c16f20f..b25f2f2 100644 --- a/sigal/themes/galleria/templates/index.html +++ b/sigal/themes/galleria/templates/index.html @@ -57,7 +57,7 @@ {% endif %} - {% if image or videos %} + {% if images or videos %} diff --git a/sigal/video.py b/sigal/video.py index 1ff35fb..b0601d2 100644 --- a/sigal/video.py +++ b/sigal/video.py @@ -23,8 +23,7 @@ from __future__ import with_statement import subprocess -def generate_video(source, outname, options=['-vf', 'scale=800:trunc(ow/a/2)*2']): - # http://stackoverflow.com/questions/8218363/maintaining-ffmpeg-aspect-ratio +def generate_video(source, outname, size, options=[]): """Video processor :param source: path to an image @@ -32,13 +31,20 @@ def generate_video(source, outname, options=['-vf', 'scale=800:trunc(ow/a/2)*2'] :param options: array of options passed to ffmpeg """ + # We don't keep the h param, because we want to keep the same ratio as + # the original file (resizeToFit is not available in ffmpeg) + # see http://stackoverflow.com/questions/8218363/maintaining-ffmpeg-aspect-ratio + (w, h) = size with open("/dev/null") as devnull: - subprocess.call(['ffmpeg', '-i', source, '-y'] + options + - [outname], stderr=devnull) + subprocess.call(['ffmpeg', '-i', source, '-y', '-vf', + "scale=%i:trunc(ow/a/2)*2'" % w] + options + [outname], + stderr=devnull) -def generate_thumbnail(source, outname, options=['-vf', 'scale=80:trunc(ow/a/2)*2']): - # http://stackoverflow.com/questions/8218363/maintaining-ffmpeg-aspect-ratio +def generate_thumbnail(source, outname, box, options=[]): "Create a thumbnail image" + # See comment in the previous function + (w, h) = box with open("/dev/null") as devnull: subprocess.call(['ffmpeg', '-i', source, '-an', '-r', '1', - '-vframes', '1', '-y'] + options + [outname], stderr=devnull) + '-vframes', '1', '-y', '-vf', "scale=%i:trunc(ow/a/2)*2" % h] + + options + [outname], stderr=devnull) diff --git a/sigal/writer.py b/sigal/writer.py index c7c6d5f..ae127ad 100644 --- a/sigal/writer.py +++ b/sigal/writer.py @@ -145,7 +145,7 @@ class Writer(object): for i in paths[relpath]['vid']: base, ext = os.path.splitext(i) vid_ctx = {'file': base + '.webm', - 'thumb': get_thumb(self.settings, base + '.jpg')} + 'thumb': get_thumb(self.settings, i)} if self.settings['keep_orig']: vid_ctx['big'] = get_orig(self.settings, i) ctx['videos'].append(vid_ctx)