From 53caa45a89ca96a0f58e662776de692dff0aff2c Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Sat, 10 Apr 2021 11:29:30 +0200 Subject: Refactor, use simpler syntax for dash --- README.md | 8 ++++++++ gal | 49 +++++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 7d39b2c..e9d41ce 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,14 @@ Yet another photo gallery generator. 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. +## Install + +``` +git clone https://git.niedzwiedzinski.cyou/gal && cd gal +export BINDIR=$HOME/scripts +ln -s $PWD/gal $BINDIR +``` + ## Usage ``` diff --git a/gal b/gal index 70a92dd..83ea478 100755 --- a/gal +++ b/gal @@ -13,6 +13,8 @@ QUALITY=70 THUMBNAIL_RESOLUTION=250 RESOLUTION=1500 +EXTENSIONS="jpg JPG jpeg JPEG png PNG" + ## ================= [ -z $1 ] && echo "You need to pass photos dir" && exit 1 @@ -21,7 +23,8 @@ RESOLUTION=1500 PHOTOS=$1 OUTPUT=$2 TITLE=${TITLE:-$(basename $OUTPUT)} -mkdir -p $2/{photos,thumbs} +mkdir -p $2/photos +mkdir -p $2/thumbs ## Generate index.html menu file cp $(dirname $(readlink -f $0))/style.css $OUTPUT @@ -43,10 +46,14 @@ cat > $OUTPUT/index.html < EOF +[ -f $OUTPUT/photo_list ] && echo "Replacing existing photo_list" && rm $OUTPUT/photo_list + +for ext in $EXTENSIONS; do + for f in `find $PHOTOS -name "*.$ext"`; do + filename=$(basename $f) -for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do - filename=$(basename $f) - [ -f $f ] && cat >> $OUTPUT/index.html <> $OUTPUT/index.html < @@ -57,8 +64,20 @@ for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do EOF + + ## Add to photo_list + [ -f $f ] && echo $filename >> $OUTPUT/photo_list + + ## Optimize image + echo "Optimizing $filename" + [ -f $f ] && 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" + + done done +## Add footer cat >> $OUTPUT/index.html <