From 185120b5756b331bd1972388d6bc8a647699cca3 Mon Sep 17 00:00:00 2001 From: "kujiu (@rincevent)" Date: Sun, 25 Jul 2021 15:16:10 +0200 Subject: [PATCH] Use JPEG instead of PNG on thumbnails --- CHANGES.rst | 1 + README.rst | 4 +++- __init__.py | 8 ++++---- collector.py | 9 +++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 18ab3ae..6b2961b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,7 @@ Changes - Swipe support - More space for images - Restructure repository +- Use JPEG instead of PNG for thumbnails 1.0.3 (*2021-07-13*) ~~~~~~~~~~~~~~~~~~~~ diff --git a/README.rst b/README.rst index ea0bb2a..e5a09f5 100644 --- a/README.rst +++ b/README.rst @@ -49,7 +49,9 @@ same galleria name. In this case, node level options must be defined only once. Thumbnail size is in "WIDTHxHEIGHT" format, resulting -image keeps ratio. +image keeps ratio. Be careful with tumbnail size, the +browser loads all thumbnails of a gallery when loading +the page. It can take some time with really big galleries. The first image of a gallery is displayed if javascript is not available on the browser. diff --git a/__init__.py b/__init__.py index 6589730..8a3c31c 100644 --- a/__init__.py +++ b/__init__.py @@ -11,8 +11,8 @@ from sphinx.environment import BuildEnvironment from sphinx.util.osutil import ensuredir, copyfile from PIL import Image -from . import directive -from . import collector +from sphinx_galleria import directive +from sphinx_galleria import collector with open(os.path.join( @@ -43,7 +43,7 @@ def copy_images_files(app: Sphinx, env: BuildEnvironment) -> None: thumbsize = basename.split('-')[-1].split('x') thumbsize = [int(size) for size in thumbsize] original = '.'.join(basename.split('.')[:-1]) + ext - dest = basename + '.png' + dest = basename + '.jpg' ensuredir(os.path.dirname(dest)) with Image.open(original) as im: @@ -68,7 +68,7 @@ def copy_images_files(app: Sphinx, env: BuildEnvironment) -> None: (im.size[1]+thumbsize[0]*im.size[1]/thumbsize[0])//2, )) - out.save(dest, "PNG") + out.save(dest, "JPEG", quality=90) def install_static_files(app: Sphinx, env: BuildEnvironment) -> None: diff --git a/collector.py b/collector.py index 7561fa3..db4df92 100644 --- a/collector.py +++ b/collector.py @@ -10,14 +10,15 @@ import glob import logging from copy import copy from typing import Set -from sphinx.environment.collectors import EnvironmentCollector + from docutils import nodes +from sphinx.environment.collectors import EnvironmentCollector from sphinx.application import Sphinx from sphinx.environment import BuildEnvironment from sphinx.util import FilenameUniqDict from sphinx.locale import __ -from .directive import galleria +from sphinx_galleria.directive import galleria logger = logging.getLogger(__name__) @@ -86,7 +87,7 @@ class GalleriaCollector(EnvironmentCollector): basename, ext = os.path.splitext(image_path) thumb_path = basename + ".thumb-" + thumbsize + ext thumb_path_cropped = basename + ".thumb-" + thumbsize - thumb_path_cropped += '.png' + thumb_path_cropped += '.jpg' if ext.lower() in ('.svg', '.svgz'): thumb_path_cropped = image_path thumb_path = image_path @@ -109,7 +110,7 @@ class GalleriaCollector(EnvironmentCollector): app.srcdir, image_path), os.R_OK): logger.warning( - __('image file not readable %s') % + __('image file not readable %s'), image_path) app.env.galleria.add_file(docname, image_path)