From 2190c06edd52da72ff78bea34d5e8b3f09d121b7 Mon Sep 17 00:00:00 2001 From: "kujiu (@rincevent)" Date: Sun, 25 Jul 2021 16:29:09 +0200 Subject: [PATCH] Thumb in initial image format --- CHANGES.rst | 2 +- __init__.py | 7 +++++-- collector.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 6b2961b..ce71f2f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,7 +8,7 @@ Changes - Swipe support - More space for images - Restructure repository -- Use JPEG instead of PNG for thumbnails +- Use initial format instead of PNG for thumbnails 1.0.3 (*2021-07-13*) ~~~~~~~~~~~~~~~~~~~~ diff --git a/__init__.py b/__init__.py index 8a3c31c..9c9d0b5 100644 --- a/__init__.py +++ b/__init__.py @@ -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 + '.jpg' + dest = basename + ext ensuredir(os.path.dirname(dest)) with Image.open(original) as im: @@ -68,7 +68,10 @@ def copy_images_files(app: Sphinx, env: BuildEnvironment) -> None: (im.size[1]+thumbsize[0]*im.size[1]/thumbsize[0])//2, )) - out.save(dest, "JPEG", quality=90) + if ext.lower() in ("jpg", "jpeg"): + out.save(dest, "JPEG", quality=90) + else: + out.save(dest) def install_static_files(app: Sphinx, env: BuildEnvironment) -> None: diff --git a/collector.py b/collector.py index db4df92..e32a61b 100644 --- a/collector.py +++ b/collector.py @@ -87,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 += '.jpg' + thumb_path_cropped += ext if ext.lower() in ('.svg', '.svgz'): thumb_path_cropped = image_path thumb_path = image_path