Browse Source

Bump

master
David Larlet 1 year ago
parent
commit
69e7b7c25a
Signed by: David Larlet <david@larlet.fr> GPG Key ID: 3E2953A359E7E7BD
3 changed files with 11 additions and 31 deletions
  1. 4
    4
      requirements.txt
  2. 5
    26
      revelateur.py
  3. 2
    1
      theme/media.html.j2

+ 4
- 4
requirements.txt View File

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

+ 5
- 26
revelateur.py View File

import os import os
import shutil import shutil
import re import re
import subprocess
import yaml import yaml


from operator import attrgetter, itemgetter from operator import attrgetter, itemgetter
from configuration import OUTPUT_DIR, PICTURES_DIR, SIZES, THEME_DIR from configuration import OUTPUT_DIR, PICTURES_DIR, SIZES, THEME_DIR




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

jinja_env = Environment( jinja_env = Environment(
loader=PackageLoader("revelateur", THEME_DIR), loader=PackageLoader("revelateur", THEME_DIR),
autoescape=select_autoescape(["html"]), autoescape=select_autoescape(["html"]),
if output_path.exists(): if output_path.exists():
return 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): def generate_jpg_photo_for_size(gallery_output_path, photo, width, height):
if output_path.exists(): if output_path.exists():
return output_path 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 return output_path



+ 2
- 1
theme/media.html.j2 View File

{# TODO: less manual! #} {# TODO: less manual! #}
{% if gallery.type == "video" %} {% if gallery.type == "video" %}
<div class="u-center"> <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> <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> <p><a href="https://vimeo.com/580086949/0833bc929c">Évasion (lire sur Vimeo)</a></p>
<hr> <hr>
{%- endfor -%} {%- endfor -%}
" "
sizes="{% if gallery_photo.narrow %}150px{% else %}310px{% endif %}" 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> </picture>
</a> </a>
</div> </div>

Loading…
Cancel
Save