Procházet zdrojové kódy

Use the correct resampling and ICC profile

master
David Larlet před 1 rokem
rodič
revize
5267a6db4f
2 změnil soubory, kde provedl 20 přidání a 5 odebrání
  1. 1
    1
      requirements.txt
  2. 19
    4
      site.py

+ 1
- 1
requirements.txt Zobrazit soubor

@@ -1,6 +1,6 @@
Jinja2==3.0.1
minicli==0.5.0
mistune==2.0.0rc1
Pillow==8.3.1
Pillow==9.4.0
python-slugify==5.0.2
regex==2021.8.3

+ 19
- 4
site.py Zobrazit soubor

@@ -148,8 +148,8 @@ class ImgsWithSizesRenderer(CustomAndBlockquoteLanguageRenderer):
return src_size

image = Image.open(full_path)
image.thumbnail((width, height))
image.save(full_path_size)
image.thumbnail((width, height), resample=Image.LANCZOS)
image.save(full_path_size, icc_profile=image.info.get("icc_profile"))
return src_size

def _generate_webp(self, src):
@@ -158,8 +158,23 @@ class ImgsWithSizesRenderer(CustomAndBlockquoteLanguageRenderer):
full_path_webp = STATIC / Path(src_webp[1:])
if full_path_webp.exists() or "/2023/" not in src:
return src_webp
command = ["cwebp", "-q", "80", full_path, "-o", full_path_webp]
subprocess.check_output(command, stderr=subprocess.STDOUT)

image = Image.open(full_path)
image.save(
full_path_webp, format="webp", icc_profile=image.info.get("icc_profile")
)
# command = [
# "cwebp",
# "-q",
# "80",
# full_path,
# "-o",
# full_path_webp,
# "-metadata",
# "icc",
# ]
# subprocess.check_output(command, stderr=subprocess.STDOUT)

return src_webp

def image(self, src, alt="", title=None):

Načítá se…
Zrušit
Uložit