about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rwxr-xr-xgal49
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
     <div class="tiles">
 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 <<EOF
+    ## Add to index.html
+    [ -f $f ] && cat >> $OUTPUT/index.html <<EOF
       <div class="tile">
         <a href="photos/$filename">
           <picture>
@@ -57,8 +64,20 @@ for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
         </a>
       </div>
 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 <<EOF
     </div>
     <footer>
@@ -69,28 +88,6 @@ cat >> $OUTPUT/index.html <<EOF
 </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 <<EOF
-$filename
-EOF
-done
-
-## Optimize images
-
-for f in $PHOTOS/*.{jpg,JPG,jpeg,JPEG,png,PNG}; do
-  filename=$(basename $f)
-  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
-
 ## Create zip archive
 
 zip $OUTPUT/"archive_$TITLE.zip" -r $OUTPUT/photos