commit 12657f9075ebe7cef3f1a49324aeed4fa954893b
Author: sej <sej@sejdt.localhost>
Date: Thu, 26 Sep 2024 13:19:08 +0200
Initial commit
Diffstat:
18 files changed, 466 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+__pycache__
diff --git a/extract_metadata.sh b/extract_metadata.sh
@@ -0,0 +1 @@
+exiftool -p '$FileName, $ImageWidth, $ImageHeight, $DateTimeOriginal, $ExposureTime, $FNumber, $FocalLength, $ISO, $Model, $LensType, $CameraTemperature' -w $1img/metadata/%f.csv $2
diff --git a/gen_thumbs.sh b/gen_thumbs.sh
@@ -0,0 +1,2 @@
+mogrify -path $1img/thumb -quality 70 -strip -resize 12.5% $1img/fullres/*
+mogrify -path $1img/preview -quality 80 -strip -resize 50% $1img/fullres/*
diff --git a/jinjarender.py b/jinjarender.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+from jinja2 import Environment, PackageLoader, select_autoescape
+import sys
+import os
+import csv
+import json
+import argparse
+
+class image_info:
+ datetimeoriginal = ""
+ exposuretime = ""
+ fnumber = ""
+ focallength = ""
+ iso = ""
+ model = ""
+ lenstype = ""
+ lightvalue = ""
+ measuredev2 = ""
+ cameratemperature = ""
+
+
+if __name__ == "__main__":
+
+ if len( sys.argv ) == 3:
+ albumpath = sys.argv[1] # sti til json-fil der beskriver albums, altså fortæller hvilke billeder der er i hvilke albums.
+ outputpath = sys.argv[2] # sti til output af html-filer. det forventes at der her ligger en undermappe med metadata på csv-format for hvert inputbillede og thumbnails til hvert inputbillede
+ #imginpath = sys.argv[3] # sti til de originale input-billeder.
+ #imgmetapath = sys.argv[4] # sti til mappe med img thumbs og metadata
+ else:
+ print( "insufficient arguments" )
+ exit()
+
+
+ env = Environment(
+ loader=PackageLoader( "jinjarender", package_path="templates" ),
+ autoescape=select_autoescape()
+ )
+
+ index = env.get_template( "index3.html" )
+ viewer = env.get_template( "viewer2.html" )
+ album = env.get_template( "album2.html" )
+
+ ls = os.listdir( outputpath + "img/metadata/" )
+ m = dict()
+ for metadata in ls:
+ with open( outputpath + "img/metadata/" + metadata ) as f:
+ r = csv.reader( f )
+ row = next(r)
+ m[ row[0] ] = row[1:]
+
+
+ #imgs = os.listdir( "web/img" )
+ with open( albumpath ) as jsonfile:
+ jsonarray = json.load( jsonfile )
+
+ allimgsdict = dict()
+ allalbums = []
+ for json in jsonarray:
+ print( json["name"] )
+ allalbums.append( json["name"] )
+ for img in json["imgs"]:
+ allimgsdict[img] = None
+
+ allimgs = list( allimgsdict.keys() )
+
+ nalbums = len( allalbums )
+
+ #generate album files
+ for i in range( nalbums ):
+ json = jsonarray[i];
+ nextalbum = "{}.html".format( jsonarray[ (i+1)%nalbums ]["name"] )
+ prevalbum = "{}.html".format( jsonarray[ (i-1)%nalbums ]["name"] )
+ with open( outputpath + json["name"] + ".html", "x" ) as f:
+ f.write( album.render( nextalbum = nextalbum, prevalbum = prevalbum, title = json["name"], imgs = json["imgs"], csspath = "css/stylesheet.css", navbar = True ) )
+
+ #generate viewer files for this album
+ os.makedirs( outputpath + "img/viewer/{}".format( json["name"] ) )
+
+ n = len( json["imgs"] )
+ for i in range( n ):
+ img = json["imgs"][i]
+ exif = m[img]
+ exifstring = "{} || {}s | f/{} | {} | ISO{} || {} + {} | {}".format( exif[2], exif[3], exif[4][1:], exif[5], exif[6], exif[7], exif[8], exif[9] )
+ nexti = str( "{}.html".format( json["imgs"][ (i+1)%n ] ) )
+ previ = str( "{}.html".format( json["imgs"][ (i-1)%n ] ) )
+ with open( outputpath + "img/viewer/{}/{}.html".format( json["name"], img ), "x" ) as f:
+ f.write( viewer.render( navbar = True, fullrespath = "/img/fullres/", previewpath = "/img/preview/" , img = img, exif = exifstring, nexti = nexti, previ = previ ) )
+
+ #generate index file
+ albums = []
+ imgs = []
+ desc = []
+ for json in jsonarray:
+ albums.append( json["name"] + ".html" )
+ imgs.append( json["imgs"][0] )
+ desc.append( json["name"] )
+
+ with open( outputpath + "index.html", "x" ) as f:
+ f.write( index.render( title = "index", imgs = imgs, hrefs = albums, desc = desc, bodyclass = "index" ) )
+
+ #generate viewer files for all imgs
+ n = len( allimgs )
+ for i in range( n ):
+ img = allimgs[i]
+ exif = m[img]
+ exifstring = "{} || {}s | f/{} | {} | ISO{} || {} + {} | {}".format( exif[2], exif[3], exif[4][1:], exif[5], exif[6], exif[7], exif[8], exif[9] )
+ nexti = str( allimgs[ (i+1)%n ] ) + ".html"
+ previ = str( allimgs[ (i-1)%n ] ) + ".html"
+ with open( outputpath + "img/viewer/{}.html".format( img ), "x" ) as f:
+ f.write( viewer.render( navbar = True, fullrespath = "/img/fullres/", previewpath = "/img/preview/", img = img, exif = exifstring, path = "/img/", nexti = nexti, previ = previ) )
+
+
+
+
+"""
+ for img in imgs:
+ f = open( img + ".html", "x" )
+ f.write( viewer.render( img = img, exif = exif ) )
+"""
diff --git a/templates/album.html b/templates/album.html
@@ -0,0 +1,26 @@
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>{{ title }}</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="css/stylesheet.css">
+ </head>
+ <body>
+
+ <h1>{{ title }}</h1>
+ <p>This is a paragraph.</p>
+
+ <div class="flex-container wrap">
+
+ {% for img in imgs %}
+ <div class="box">
+ <a href="img/viewer/{{ img }}.html">
+ <img src="img/thumbs/{{ img }}">
+ </a>
+ </div>
+ {% endfor %}
+
+ </div>
+ </body>
+ </html>
diff --git a/templates/album2.html b/templates/album2.html
@@ -0,0 +1,30 @@
+{% extends "base.html" %}
+{% block title %}{{ title }}{% endblock %}
+{% block navbar %}
+<a class="half" href="index.html">
+ <p>Return to all albums</p>
+</a>
+
+<a class="quarter" href="{{ prevalbum }}">
+ <p><==</p>
+</a>
+
+<a class="right quarter" href="{{ nextalbum }}">
+ <p>==></p>
+</a>
+{% endblock %}
+{% block content %}
+<h1>{{ title }}</h1>
+{# <p>This is a paragraph.</p> #}
+
+<div class="flex-container wrap">
+
+ {% for img in imgs %}
+ <div class="box">
+ <a href="img/viewer/{{ title }}/{{ img }}.html">
+ <img src="img/thumb/{{ img }}">
+ </a>
+ </div>
+ {% endfor %}
+</div>
+{% endblock %}
diff --git a/templates/base.html b/templates/base.html
@@ -0,0 +1,37 @@
+{# base.html #}
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>{% block title %}{% endblock %}</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="/css/stylesheet.css">
+ </head>
+ <body {% block bodyclass %}class="{{ bodyclass }}"{% endblock %}>
+ {% if navbar %}
+ <div id="navbar">
+ {% block navbar %}
+ <a class="np half" href="{{ previ }}"></a>
+ <a class="right np half" href="{{ nexti }}"></a>
+ {% endblock %}
+ </div>
+ {% endif %}
+ {% block content %}
+ <div class="view-container">
+ <a href="{{ imgpath + img }}">
+ <img class="viewer" src="{{ imgpath + img }}">
+ </a>
+ </div>
+ <p class="desc">{{ exif }}</p>
+ {% endblock %}
+ </body>
+ <footer>
+ <p>Author: sej
+ {% for l in links %}
+ | <a href="{{ l['link'] }}">{{ l['text'] }}</a>
+ {% endfor %}
+ </p>
+
+ <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
+ </footer>
+ </html>
diff --git a/templates/basekm.html b/templates/basekm.html
@@ -0,0 +1,38 @@
+{# base.html #}
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>{% block title %}{% endblock %}</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta name="robots" content="noindex">
+ <link rel="stylesheet" href="{{ csspath }}">
+ </head>
+ <body>
+ {% if navbar %}
+ <div id="navbar">
+ <a class="np half" href="{{ previ }}"></a>
+ <a class="right np half" href="{{ nexti }}"></a>
+ </div>
+ {% endif %}
+ {% block content %}
+ <div class="view-container">
+ <a href="{{ imgpath + img }}">
+ <img class="viewer" src="{{ imgpath + img }}">
+ </a>
+ </div>
+ <p class="desc">{{ exif }}</p>
+ {% endblock %}
+ </body>
+ <footer>
+ <p>Author: sej
+ {% if buttons %}
+ | <a href="../../index.html">Index</a> |
+ <a href="{{ fullrespath + img }}">Full res</a> |
+ <a href="{{ metadatapath + img[:8] + '.csv' }}">Metadata</a>
+ {% endif %}
+ </p>
+
+ <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
+ </footer>
+ </html>
diff --git a/templates/index.html b/templates/index.html
@@ -0,0 +1,25 @@
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>{{ title }}</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="css/stylesheet.css">
+ </head>
+ <body>
+
+ <h1>{{ title }}</h1>
+ <p>This is a paragraph.</p>
+
+ {% for img in imgs %}
+ <div class="gallery" >
+ <a href="{{ hrefs[loop.index0] }}">
+ <img class="preview" src="img/thumb/{{ img }}">
+ </a>
+ <div class="desc">
+ <p class="desc">{{ desc[loop.index0] }}</p>
+ </div>
+ </div>
+ {% endfor %}
+ </body>
+ </html>
diff --git a/templates/index2.html b/templates/index2.html
@@ -0,0 +1,19 @@
+{% extends "base.html" %}
+{% block title %}Index{% endblock %}
+
+{% block content%}
+
+<h1>{{ title }}</h1>
+<p>This is a paragraph.</p>
+
+{% for img in imgs %}
+<div class="gallery" >
+ <a href="{{ hrefs[loop.index0] }}">
+ <img class="preview" src="img/thumbs/{{ img }}">
+ </a>
+ <div class="desc">
+ <p class="desc">{{ desc[loop.index0] }}</p>
+ </div>
+</div>
+{% endfor %}
+{% endblock %}
diff --git a/templates/index3.html b/templates/index3.html
@@ -0,0 +1,31 @@
+{% extends "base.html" %}
+{% block title %}{{ title }}{% endblock %}
+{% block navbar %}
+<a class="half" href="index.html">
+ <p>Return to all albums</p>
+</a>
+
+<a class="quarter" href="{{ prevalbum }}">
+ <p><==</p>
+</a>
+
+<a class="right quarter" href="{{ nextalbum }}">
+ <p>==></p>
+</a>
+{% endblock %}
+{% block content %}
+<h1>{{ title }}</h1>
+
+<div class="flex-container wrap">
+ {% for img in imgs %}
+ <div class="box">
+ <a href="{{ hrefs[loop.index0] }}">
+ <img class="preview" src="img/thumbs/{{ img }}">
+ </a>
+ <div class="desc">
+ <p class="desc">{{ desc[loop.index0] }}</p>
+ </div>
+ </div>
+ {% endfor %}
+</div>
+{% endblock %}
diff --git a/templates/km.html b/templates/km.html
@@ -0,0 +1,4 @@
+{% extends "base.html" %}
+{% block content %}
+
+{% endblock %}
diff --git a/templates/kmalbum.html b/templates/kmalbum.html
@@ -0,0 +1,17 @@
+{% extends "basekm.html" %}
+{% block title %}{{ title }}{% endblock %}
+{% block content %}
+<h1>{{ title }}</h1>
+{# <p>This is a paragraph.</p> #}
+
+<div class="flex-container wrap">
+
+ {% for img in imgs %}
+ <div class="box">
+ <a href="img/viewer/{{ img }}.html">
+ <img src="img/thumb/{{ img }}">
+ </a>
+ </div>
+ {% endfor %}
+</div>
+{% endblock %}
diff --git a/templates/kmindex.html b/templates/kmindex.html
@@ -0,0 +1,18 @@
+{% extends "basekm.html" %}
+{% block title %}{{ title }}{% endblock %}
+{% block content %}
+<h1>{{ title }}</h1>
+
+<div class="flex-container wrap">
+ {% for img in imgs %}
+ <div class="box">
+ <a href="{{ hrefs[loop.index0] }}">
+ <img class="preview" src="img/thumbs/{{ img }}">
+ </a>
+ <div class="desc">
+ <p class="desc">{{ desc[loop.index0] }}</p>
+ </div>
+ </div>
+ {% endfor %}
+</div>
+{% endblock %}
diff --git a/templates/kmviewer.html b/templates/kmviewer.html
@@ -0,0 +1,19 @@
+{% extends "basekm.html" %}
+
+{% block title %}{{ img }}{% endblock %}
+{% if navbar %}
+
+<a class="np half" href="{{ previ }}">
+</a>
+
+<a class="right np half" href="{{ nexti }}">
+</a>
+{% endif %}
+{% block content %}
+<div class="view-container">
+ <a href="{{ fullrespath + img }}">
+ <img class="viewer" src="{{ previewpath + img }}">
+ </a>
+</div>
+<p id="metadata" class="imgdesc">{{ exif }}</p>
+{% endblock %}
diff --git a/templates/viewer.html b/templates/viewer.html
@@ -0,0 +1,25 @@
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <title>{{ img }}</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="../../css/stylesheet.css">
+ </head>
+ <body>
+ <div id="navbar">
+ <a href="{{ previ }}">
+ <p><==</p>
+ </a>
+ <a class="right" href="{{ nexti }}">
+ <p>==></p>
+ </a>
+ </div>
+ <div class="view-container">
+ <a href="{{ imgpath + img }}">
+ <img class="viewer" src="{{ imgpath + img }}">
+ </a>
+ </div>
+ <p class="desc">{{ exif }}</p>
+ </body>
+ </html>
diff --git a/templates/viewer2.html b/templates/viewer2.html
@@ -0,0 +1,35 @@
+{% extends "base.html" %}
+
+{% block title %}{{ img }}{% endblock %}
+{% block navbar %}
+
+<a href="{{ albumpath }}">
+ <p>Back to albums view</p>
+</a>
+
+<a href="/index.html">
+ <p>Back to index view</p>
+</a>
+
+<a href="{{ fullrespath + img }}">
+ <p>Open original</p>
+</a>
+
+<a href="../{{ img }}.html">
+ <p>Open i all-viewer</p>
+</a>
+
+<a class="np half" href="{{ previ }}">
+</a>
+
+<a class="right np half" href="{{ nexti }}">
+</a>
+{% endblock %}
+{% block content %}
+<div class="view-container">
+ <a href="{{ fullrespath + img }}">
+ <img class="viewer" src="{{ previewpath + img }}">
+ </a>
+</div>
+<p id="metadata" class="imgdesc">{{ exif }}</p>
+{% endblock %}
diff --git a/templates/viewer3.html b/templates/viewer3.html
@@ -0,0 +1,19 @@
+{% extends "base.html" %}
+
+{% block title %}{{ img }}{% endblock %}
+{% if navbar %}
+
+<a class="np half" href="{{ previ }}">
+</a>
+
+<a class="right np half" href="{{ nexti }}">
+</a>
+{% endif %}
+{% block content %}
+<div class="view-container">
+ <a href="{{ fullrespath + img }}">
+ <img class="viewer" src="{{ previewpath + img }}">
+ </a>
+</div>
+<p id="metadata" class="imgdesc">{{ exif }}</p>
+{% endblock %}