How to use the sigal.settings.get_thumb function in sigal

To help you get started, we’ve selected a few sigal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saimn / sigal / tests / test_settings.py View on Github external
def test_get_thumb(settings):
    """Test the get_thumb function."""
    tests = [('example.jpg', 'thumbnails/example.tn.jpg'),
             ('test/example.jpg', 'test/thumbnails/example.tn.jpg'),
             ('test/t/example.jpg', 'test/t/thumbnails/example.tn.jpg')]
    for src, ref in tests:
        assert get_thumb(settings, src) == ref

    tests = [('example.webm', 'thumbnails/example.tn.jpg'),
             ('test/example.mp4', 'test/thumbnails/example.tn.jpg'),
             ('test/t/example.avi', 'test/t/thumbnails/example.tn.jpg')]
    for src, ref in tests:
        assert get_thumb(settings, src) == ref
github saimn / sigal / sigal / image.py View on Github external
filename = os.path.split(filepath)[1]
    outname = os.path.join(outpath, filename)
    ext = os.path.splitext(filename)[1]

    if ext in ('.jpg', '.jpeg', '.JPG', '.JPEG'):
        options = settings['jpg_options']
    elif ext == '.png':
        options = {'optimize': True}
    else:
        options = {}

    try:
        generate_image(filepath, outname, settings, options=options)

        if settings['make_thumbs']:
            thumb_name = os.path.join(outpath, get_thumb(settings, filename))
            generate_thumbnail(
                outname, thumb_name, settings['thumb_size'],
                fit=settings['thumb_fit'], options=options,
                thumb_fit_centering=settings["thumb_fit_centering"])
    except Exception as e:
        logger.info('Failed to process: %r', e)
        if logger.getEffectiveLevel() == logging.DEBUG:
            raise
        else:
            return Status.FAILURE

    return Status.SUCCESS
github saimn / sigal / sigal / image.py View on Github external
if ext in ('.jpg', '.jpeg', '.JPG', '.JPEG'):
        options = settings['jpg_options']
    elif ext == '.png':
        options = {'optimize': True}
    else:
        options = {}

    try:
        generate_image(filepath, outname, settings, options=options)
    except Exception as e:
        logger.error('Failed to process image: %s', e)
        return

    if settings['make_thumbs']:
        thumb_name = os.path.join(outpath, get_thumb(settings, filename))
        generate_thumbnail(outname, thumb_name, settings['thumb_size'],
                           fit=settings['thumb_fit'], options=options)
github saimn / sigal / sigal / video.py View on Github external
if video_format not in valid_formats:
                logger.error('Invalid video_format. Please choose one of: %s',
                             valid_formats)
                raise ValueError

            outname = os.path.join(outpath, basename + '.' + video_format)
            generate_video(filepath, outname, settings,
                           options=settings.get(video_format + '_options'))
    except Exception:
        if logger.getEffectiveLevel() == logging.DEBUG:
            raise
        else:
            return Status.FAILURE

    if settings['make_thumbs']:
        thumb_name = os.path.join(outpath, get_thumb(settings, filename))
        try:
            generate_thumbnail(
                outname, thumb_name, settings['thumb_size'],
                settings['thumb_video_delay'], fit=settings['thumb_fit'],
                options=settings['jpg_options'],
                converter=settings['video_converter'])
        except Exception:
            if logger.getEffectiveLevel() == logging.DEBUG:
                raise
            else:
                return Status.FAILURE

    return Status.SUCCESS
github saimn / sigal / sigal / gallery.py View on Github external
def thumbnail(self):
        """Path to the thumbnail of the album."""

        if self._thumbnail:
            # stop if it is already set
            return self._thumbnail

        # Test the thumbnail from the Markdown file.
        thumbnail = self.meta.get('thumbnail', [''])[0]

        if thumbnail and isfile(join(self.src_path, thumbnail)):
            self._thumbnail = url_from_path(join(
                self.name, get_thumb(self.settings, thumbnail)))
            self.logger.debug("Thumbnail for %r : %s", self, self._thumbnail)
            return self._thumbnail
        else:
            # find and return the first landscape image
            for f in self.medias:
                ext = splitext(f.filename)[1]
                if ext.lower() in self.settings['img_extensions']:
                    # Use f.size if available as it is quicker (in cache), but
                    # fallback to the size of src_path if dst_path is missing
                    size = f.size
                    if size is None:
                        size = get_size(f.src_path)

                    if size['width'] > size['height']:
                        self._thumbnail = (url_quote(self.name) + '/' +
                                           f.thumbnail)
github saimn / sigal / sigal / gallery.py View on Github external
def __init__(self, filename, path, settings):
        self.src_filename = self.filename = filename
        self.path = path
        self.settings = settings
        self.ext = os.path.splitext(filename)[1].lower()

        self.src_path = join(settings['source'], path, filename)
        self.dst_path = join(settings['destination'], path, filename)

        self.thumb_name = get_thumb(self.settings, self.filename)
        self.thumb_path = join(settings['destination'], path, self.thumb_name)

        self.logger = logging.getLogger(__name__)
        self._get_metadata()
        # default: title is the filename
        if not self.title:
            self.title = self.filename
        signals.media_initialized.send(self)