summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-04-17 00:29:38 +0200
committerJulian T <julian@jtle.dk>2021-04-17 00:29:38 +0200
commit2ae0671f5b8ccf3d3a31b95cf0ddaee544bc701a (patch)
tree7766eaef03f4893ae7bafd97e146d5ee5d1a60aa
parent2f752f51de99eb82fb953290b4e1289ca7a5e15f (diff)
Show and order by taken date
-rwxr-xr-xbuild.py41
-rw-r--r--imginfo.yml12
-rw-r--r--index.html.j23
3 files changed, 41 insertions, 15 deletions
diff --git a/build.py b/build.py
index e627f8f..f018b94 100755
--- a/build.py
+++ b/build.py
@@ -1,12 +1,14 @@
#!/usr/bin/env python3
import jinja2
import PIL.Image
+import PIL.ImageOps
import argparse
import yaml
import os
import re
import hashlib
import glob
+from datetime import datetime
imagereg = re.compile("([a-z0-9]*)\\..*")
@@ -76,13 +78,15 @@ class ImageLocation:
fname = f"{thash}.{settings['ext']}"
print(f"Converting file {imgname} to {fname}")
- im = PIL.Image.open(imgname)
-
- width = settings["res"]
- res = (width, int((im.size[1] / im.size[0]) * width))
- im = im.resize(res, PIL.Image.ANTIALIAS)
tmpname = f"{self.tmpname}.{settings['ext']}"
- im.save(tmpname)
+ with PIL.Image.open(imgname) as im:
+ target_height = settings["res"]
+ im = PIL.ImageOps.exif_transpose(im)
+ if im.size[0] > target_height:
+ res = (int((im.size[0] / im.size[1]) * target_height), target_height)
+ im = im.resize(res, PIL.Image.ANTIALIAS)
+
+ im.save(tmpname)
os.rename(tmpname, os.path.join(self.folder, fname))
@@ -119,6 +123,24 @@ class Image:
self.scaledpath = ""
self.fullurl = ""
+ self.taken = None
+ self.load_metadata()
+
+ def load_metadata(self):
+ try:
+ with PIL.Image.open(self.filename) as im:
+ taken_str = im.getexif()[36867]
+ except KeyError:
+ print(f"Could not load date from image {self.filename}")
+ return
+
+ self.taken = datetime.strptime(taken_str, "%Y:%m:%d %H:%M:%S")
+
+
+def value_or_default(val, default=None):
+ if val is None:
+ return default
+ return val
class Loader:
@@ -152,6 +174,11 @@ class Loader:
self.images.append(img)
+ self.images = sorted(self.images,
+ key=lambda img: value_or_default(img.taken,
+ datetime.min),
+ reverse=True)
+
class Renderer:
def __init__(self, loader, resolution, extension):
@@ -197,7 +224,7 @@ class Renderer:
parser = argparse.ArgumentParser()
parser.add_argument("--dest", "-d", default="build", help="where to put resulting files")
-parser.add_argument("--size", "-s", default="1920", help="size to scale web images to")
+parser.add_argument("--size", "-s", default="1080", help="size to scale web images to")
parser.add_argument("--commit", "-g", help="git commit hash to announce")
parser.add_argument("--clean", help="clean unused image files", action="store_true")
parser.add_argument("--config", "-c", default="imginfo.yml", help="where to load image definitions from")
diff --git a/imginfo.yml b/imginfo.yml
index 4230883..e758e48 100644
--- a/imginfo.yml
+++ b/imginfo.yml
@@ -1,10 +1,6 @@
imageglob: "*.jpg"
info:
- kirke.jpg:
- desc: Kirke i Århus
- olie.jpg:
- desc: Boreplatform i Grenå
- maskiner.jpg:
- desc: Gammel generator ved Tangeværket
- Struktur.jpg:
- desc: Restaureret radiotelescoop i Dwingeloo
+ kirke.jpg: Kirke i Århus
+ olie.jpg: Boreplatform i Grenå
+ maskiner.jpg: Gammel generator ved Tangeværket
+ Struktur.jpg: Restaureret radiotelescoop i Dwingeloo
diff --git a/index.html.j2 b/index.html.j2
index cc7dc28..ba58b70 100644
--- a/index.html.j2
+++ b/index.html.j2
@@ -26,6 +26,9 @@
{% for img in images %}
<div class="post">
+ {% if img.taken is not none %}
+ <i>Taget den {{ img.taken }}</i>
+ {% endif %}
{% if img.description is not none %}
<p>{{ img.description }}</p>
{% endif %}