Use JPEG instead of PNG on thumbnails

This commit is contained in:
Kujiu 2021-07-25 15:16:10 +02:00
parent 3ddf47cd70
commit 185120b575
Signed by: kujiu
GPG key ID: ABBB2CAC6855599F
4 changed files with 13 additions and 9 deletions

View file

@ -8,6 +8,7 @@ Changes
- Swipe support - Swipe support
- More space for images - More space for images
- Restructure repository - Restructure repository
- Use JPEG instead of PNG for thumbnails
1.0.3 (*2021-07-13*) 1.0.3 (*2021-07-13*)
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

View file

@ -49,7 +49,9 @@ same galleria name. In this case, node level options
must be defined only once. must be defined only once.
Thumbnail size is in "WIDTHxHEIGHT" format, resulting 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 The first image of a gallery is displayed if javascript
is not available on the browser. is not available on the browser.

View file

@ -11,8 +11,8 @@ from sphinx.environment import BuildEnvironment
from sphinx.util.osutil import ensuredir, copyfile from sphinx.util.osutil import ensuredir, copyfile
from PIL import Image from PIL import Image
from . import directive from sphinx_galleria import directive
from . import collector from sphinx_galleria import collector
with open(os.path.join( 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 = basename.split('-')[-1].split('x')
thumbsize = [int(size) for size in thumbsize] thumbsize = [int(size) for size in thumbsize]
original = '.'.join(basename.split('.')[:-1]) + ext original = '.'.join(basename.split('.')[:-1]) + ext
dest = basename + '.png' dest = basename + '.jpg'
ensuredir(os.path.dirname(dest)) ensuredir(os.path.dirname(dest))
with Image.open(original) as im: 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, (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: def install_static_files(app: Sphinx, env: BuildEnvironment) -> None:

View file

@ -10,14 +10,15 @@ import glob
import logging import logging
from copy import copy from copy import copy
from typing import Set from typing import Set
from sphinx.environment.collectors import EnvironmentCollector
from docutils import nodes from docutils import nodes
from sphinx.environment.collectors import EnvironmentCollector
from sphinx.application import Sphinx from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment from sphinx.environment import BuildEnvironment
from sphinx.util import FilenameUniqDict from sphinx.util import FilenameUniqDict
from sphinx.locale import __ from sphinx.locale import __
from .directive import galleria from sphinx_galleria.directive import galleria
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -86,7 +87,7 @@ class GalleriaCollector(EnvironmentCollector):
basename, ext = os.path.splitext(image_path) basename, ext = os.path.splitext(image_path)
thumb_path = basename + ".thumb-" + thumbsize + ext thumb_path = basename + ".thumb-" + thumbsize + ext
thumb_path_cropped = basename + ".thumb-" + thumbsize thumb_path_cropped = basename + ".thumb-" + thumbsize
thumb_path_cropped += '.png' thumb_path_cropped += '.jpg'
if ext.lower() in ('.svg', '.svgz'): if ext.lower() in ('.svg', '.svgz'):
thumb_path_cropped = image_path thumb_path_cropped = image_path
thumb_path = image_path thumb_path = image_path
@ -109,7 +110,7 @@ class GalleriaCollector(EnvironmentCollector):
app.srcdir, app.srcdir,
image_path), os.R_OK): image_path), os.R_OK):
logger.warning( logger.warning(
__('image file not readable %s') % __('image file not readable %s'),
image_path) image_path)
app.env.galleria.add_file(docname, image_path) app.env.galleria.add_file(docname, image_path)