ソースを参照

Use the correct resampling and ICC profile

master
David Larlet 1年前
コミット
5267a6db4f
2個のファイルの変更20行の追加5行の削除
  1. 1
    1
      requirements.txt
  2. 19
    4
      site.py

+ 1
- 1
requirements.txt ファイルの表示

@@ -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 ファイルの表示

@@ -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):

読み込み中…
キャンセル
保存