David Larlet 1 år sedan
förälder
incheckning
69e7b7c25a
Signerad av: David Larlet <david@larlet.fr> GPG-nyckel ID: 3E2953A359E7E7BD
3 ändrade filer med 11 tillägg och 31 borttagningar
  1. 4
    4
      requirements.txt
  2. 5
    26
      revelateur.py
  3. 2
    1
      theme/media.html.j2

+ 4
- 4
requirements.txt Visa fil

@@ -4,13 +4,13 @@
#
# pip-compile requirements.in
#
jinja2==3.0.3
jinja2==3.1.2
# via -r requirements.in
markupsafe==2.0.1
markupsafe==2.1.2
# via jinja2
pillow==9.0.0
pillow==9.4.0
# via -r requirements.in
python-ulid==1.0.3
python-ulid==1.1.0
# via -r requirements.in
pyyaml==6.0
# via -r requirements.in

+ 5
- 26
revelateur.py Visa fil

@@ -3,7 +3,6 @@
import os
import shutil
import re
import subprocess
import yaml

from operator import attrgetter, itemgetter
@@ -15,8 +14,6 @@ from PIL import Image
from configuration import OUTPUT_DIR, PICTURES_DIR, SIZES, THEME_DIR


FNULL = open(os.devnull, "w")

jinja_env = Environment(
loader=PackageLoader("revelateur", THEME_DIR),
autoescape=select_autoescape(["html"]),
@@ -169,8 +166,8 @@ def generate_webp_photo_for_size(
if output_path.exists():
return

command = ["cwebp", "-q", "80", jpg_output_path, "-o", output_path]
subprocess.Popen(command, stdout=FNULL, stderr=subprocess.STDOUT).communicate()
image = Image.open(jpg_output_path)
image.save(output_path, format="webp", icc_profile=image.info.get("icc_profile"))


def generate_jpg_photo_for_size(gallery_output_path, photo, width, height):
@@ -179,27 +176,9 @@ def generate_jpg_photo_for_size(gallery_output_path, photo, width, height):
if output_path.exists():
return output_path

with Image.open(photo["path"]) as image:
w, h = image.size
if w > width and h > height:
# If the original file is larger in width AND height, we resize
# first the image to the lowest size accepted (both width and
# height stays greater or equal to requested size).
# E.g. in case of (440, 264):
# 1200x900 is resized to 440x330
# 1200x600 is resized to 528x264
if width / height <= w / h:
w = int(max(height * w / h, 1))
h = height
else:
h = int(max(width * h / w, 1))
w = width
new_size = (w, h)

image.draft(None, new_size)
image = image.resize(new_size, Image.BICUBIC)

image.save(output_path)
image = Image.open(photo["path"])
image.thumbnail((width, height), resample=Image.LANCZOS)
image.save(output_path, icc_profile=image.info.get("icc_profile"))

return output_path


+ 2
- 1
theme/media.html.j2 Visa fil

@@ -65,6 +65,7 @@
{# TODO: less manual! #}
{% if gallery.type == "video" %}
<div class="u-center">
<script src="https://player.vimeo.com/api/player.js"></script>
<div class="iframe-container"><iframe src="https://player.vimeo.com/video/580086949?h=0833bc929c" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe></div>
<p><a href="https://vimeo.com/580086949/0833bc929c">Évasion (lire sur Vimeo)</a></p>
<hr>
@@ -104,7 +105,7 @@
{%- endfor -%}
"
sizes="{% if gallery_photo.narrow %}150px{% else %}310px{% endif %}"
alt="TODO" loading="lazy" decoding="async">
alt="{{ gallery_photo.alt or 'TODO' }}" loading="lazy" decoding="async">
</picture>
</a>
</div>

Laddar…
Avbryt
Spara