From b3caa806669442dddbccabadd296204d46a5fbb6 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Sun, 28 Feb 2021 21:57:46 +0100 Subject: Add video gallery --- README.md | 16 ++----- gal | 96 ------------------------------------- galier | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 7 +++ 4 files changed, 172 insertions(+), 109 deletions(-) delete mode 100755 gal create mode 100755 galier diff --git a/README.md b/README.md index 7d39b2c..2c7b068 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,7 @@ -# gal +# galier -Yet another photo gallery generator. +Better [gal](https://github.com/19pdh/gal) - media gallery generator. -[Demo page](http://pics.niedzwiedzinski.cyou/mando/) - -## Why? - -I could not find any other working solution that would be as simple as this. This script just resizes all images and generates grid menu for them. That is all. +It supports images and videos ## Usage - -``` -nix shell github:19pdh/gal - -gal [PHOTOS DIR] [OUTPUT DIR] -``` diff --git a/gal b/gal deleted file mode 100755 index 6dbcfd4..0000000 --- a/gal +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/sh -## Script for generating photo gallery website -## -## Usage: -## $ ./gal [PHOTOS DIR] [OUTPUT DIR] -## -## Setting custom title: -## $ TITLE=Title ./gal [AS ABOVE] - -## === Customize === - -QUALITY=70 -THUMBNAIL_RESOLUTION=250 -RESOLUTION=1500 - -## ================= - -[ -z $1 ] && echo "You need to pass photos dir" && exit 1 -[ -z $2 ] && echo "You need to pass output dir" && exit 1 - -PHOTOS=$1 -OUTPUT=$2 -TITLE=${TITLE:-$(basename $OUTPUT)} -mkdir -p $2/{photos,thumbs} - -## Generate index.html menu file -cp style.css $OUTPUT -chmod 644 $OUTPUT/style.css -echo "Generating index.html" - -cat > $OUTPUT/index.html < - - - - - $TITLE - - - -

$TITLE

-

Last update: $(date '+%d.%m.%Y')

-
-EOF - - -for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do - filename=$(basename $f) - [ -f $f ] && cat >> $OUTPUT/index.html < - - - - - $filename - - -
-EOF -done - -cat >> $OUTPUT/index.html < - - - -EOF - -## Generate photo_list -echo "Generating photo_list" - -[ -f $OUTPUT/photo_list ] && echo "Replacing existing photo_list" && rm $OUTPUT/photo_list - -for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do - filename=$(basename $f) - [ -f $f ] && cat >> $OUTPUT/photo_list < $OUTPUT/index.html < + + + + + $TITLE + + + +

$TITLE

+

Last update: $(date '+%d.%m.%Y')

+
+EOF + +### Images + +[ -f $OUTPUT/photo_list ] && echo "Replacing existing photo_list" && rm $OUTPUT/photo_list + +for f in $MEDIA/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do + filename=$(basename $f) + [ -f $f ] || continue + + cat >> $OUTPUT/index.html < + + + + + $filename + + +
+EOF + + echo "Optimizing $filename" + convert -auto-orient -strip -quality $QUALITY -resize x$RESOLUTION "$f" "$OUTPUT/photos/$filename" + convert -auto-orient -strip -quality $QUALITY -resize x$THUMBNAIL_RESOLUTION "$f" "$OUTPUT/thumbs/$filename" + cwebp -q $QUALITY -resize 400 0 $f -o "$OUTPUT/thumbs/${filename%.*}.webp" + + echo $filename >> $OUTPUT/photo_list + +done + +### Movies + +cat >> $OUTPUT/index.html < +

Filmy

+
+EOF + +[ -f $OUTPUT/vids_list ] && echo "Replacing existing vids_list" && rm $OUTPUT/vids_list + +for f in $MEDIA/*.{webm,mp4,MP4,avi,AVI}; do + filename=$(basename $f) + [ -f $f ] || continue + + mkdir $OUTPUT/vids/${filename%.*} + + cat >> $OUTPUT/index.html < + + + + + $filename + + +
+EOF + tmp=`mktemp galier.XXX.jpg` + duration=`ffprobe -i $f -show_entries format=duration -v quiet -of csv="p=0" | cut -d'.' -f1` + echo $duration + [ -z $duration ] && echo "Empty \$duration for file $f" && exit 1 + ffmpeg -y -ss $(($duration/2)) -i $f -vframes 1 $tmp + + convert -auto-orient -strip -quality $QUALITY -resize x$THUMBNAIL_RESOLUTION "$tmp" "$OUTPUT/thumbs/${filename%.*}.vid.jpg" + cwebp -q $QUALITY -resize 400 0 $tmp -o "$OUTPUT/thumbs/${filename%.*}.vid.webp" + rm $tmp + + [ -f $OUTPUT/vids/${filename%.*}/source.mp4 ] && \ + echo "MP4 file for $filename exists" || \ + ffmpeg -i $f -vcodec libx264 -crf 23 "$OUTPUT/vids/${filename%.*}/source.mp4" + [ -f $OUTPUT/vids/${filename%.*}/source.webm ] && \ + echo "WEBM file for $filename exists" || \ + ffmpeg -i $f -c:v libvpx -crf 23 -b:v 1M -c:a libvorbis "$OUTPUT/vids/${filename%.*}/source.webm" + + cat > $OUTPUT/vids/${filename%.*}/index.html < + + + + + ${filename%.*} + + + + +

${filename%.*}

+

Last update: $(date '+%d.%m.%Y')

+ + + +EOF + + echo ${filename%.*} >> $OUTPUT/vids_list + +done + +cat >> $OUTPUT/index.html < + + + +EOF + + +## Create zip archive + +zip $OUTPUT/"archive_$TITLE.zip" -r $OUTPUT diff --git a/style.css b/style.css index 43ae13d..76adc92 100644 --- a/style.css +++ b/style.css @@ -6,6 +6,13 @@ body { height: 100vh; font-family: sans-serif; } +body * { + margin: 0 auto; +} +video { + display: block; + max-width: 58vw; +} h1, h3 { width: 58vw; margin: auto; -- cgit 1.4.1