diff options
-rwxr-xr-x | galgen | 259 |
1 files changed, 135 insertions, 124 deletions
@@ -1,51 +1,49 @@ #!/bin/bash -# Forked from https://github.com/Cyclenerd/gallery_shell - ######################################################################################### #### Configuration Section ######################################################################################### -MY_HEIGHT_SMALL=406 -MY_HEIGHT_LARGE=768 -MY_QUALITY=85 -MY_THUMBDIR="thumbnails" -MY_INDEX_HTML_FILE="index.html" -MY_TITLE="Gallery" -# MY_FOOTER='Created with <a href="https://github.com/Cyclenerd/gallery_shell">gallery.sh</a>' +HEIGHT_SMALL=406 +HEIGHT_LARGE=768 +QUALITY=85 +THUMBDIR="thumbnails" +INDEX_HTML_FILE="index.html" +TITLE="Gallery" +# FOOTER='Created with <a href="https://git.infraredcombat.xyz/galgen">galgen</a>' # Use convert from ImageMagick -MY_CONVERT_COMMAND="convert" +CONVERT_COMMAND="magick" # Use JHead for EXIF Information -MY_EXIF_COMMAND="jhead" +EXIF_COMMAND="jhead" -# Bootstrap 4 -MY_CSS="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.2/css/bootstrap.min.css" +# Bootstrap 5 +CSS="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" # Debugging output # true=enable, false=disable -MY_DEBUG=true +DEBUG=true ######################################################################################### #### End Configuration Section ######################################################################################### -MY_SCRIPT_NAME=$(basename "$0") -MY_DATETIME=$(date -u "+%Y-%m-%d %H:%M:%S") -MY_DATETIME+=" UTC" +SCRIPT_NAME=$(basename "$0") +DATETIME=$(date -u "+%Y-%m-%d %H:%M:%S") +DATETIME+=" UTC" function usage { - MY_RETURN_CODE="$1" - echo -e "Usage: $MY_SCRIPT_NAME [-t <title>] [-d <thumbdir>] [-h]: - [-t <title>]\\t sets the title (default: $MY_TITLE) - [-d <thumbdir>]\\t sets the thumbdir (default: $MY_THUMBDIR) + RETURN_CODE="$1" + echo -e "Usage: $SCRIPT_NAME [-t <title>] [-d <thumbdir>] [-h]: + [-t <title>]\\t sets the title (default: $TITLE) + [-d <thumbdir>]\\t sets the thumbdir (default: $THUMBDIR) [-h]\\t\\t displays help (this message)" - exit "$MY_RETURN_CODE" + exit "$RETURN_CODE" } function debugOutput(){ - if [[ "$MY_DEBUG" == true ]]; then + if [[ "$DEBUG" == true ]]; then echo "$1" # if debug variable is true, echo whatever's passed to the function fi } @@ -54,21 +52,21 @@ function getFileSize(){ # Be aware that BSD stat doesn't support --version and -c if stat --version &>/dev/null; then # GNU - MY_FILE_SIZE=$(stat -c %s "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') + FILE_SIZE=$(stat -c %s "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') else # BSD - MY_FILE_SIZE=$(stat -f %z "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') + FILE_SIZE=$(stat -f %z "$1" | awk '{$1/=1000000;printf "%.2fMB\n",$1}') fi - echo "$MY_FILE_SIZE" + echo "$FILE_SIZE" } while getopts ":t:d:h" opt; do case $opt in t) - MY_TITLE="$OPTARG" + TITLE="$OPTARG" ;; d) - MY_THUMBDIR="$OPTARG" + THUMBDIR="$OPTARG" ;; h) usage 0 @@ -80,169 +78,176 @@ while getopts ":t:d:h" opt; do esac done -debugOutput "- $MY_SCRIPT_NAME : $MY_DATETIME" +debugOutput "- $SCRIPT_NAME : $DATETIME" ### Check Commands -command -v $MY_CONVERT_COMMAND >/dev/null 2>&1 || { echo >&2 "!!! $MY_CONVERT_COMMAND it's not installed. Aborting."; exit 1; } -command -v $MY_EXIF_COMMAND >/dev/null 2>&1 || { echo >&2 "!!! $MY_EXIF_COMMAND it's not installed. Aborting."; exit 1; } +command -v $CONVERT_COMMAND >/dev/null 2>&1 || { echo >&2 "!!! $CONVERT_COMMAND it's not installed. Aborting."; exit 1; } +command -v $EXIF_COMMAND >/dev/null 2>&1 || { echo >&2 "!!! $EXIF_COMMAND it's not installed. Aborting."; exit 1; } ### Create Folders -[[ -d "$MY_THUMBDIR" ]] || mkdir "$MY_THUMBDIR" || exit 2 +[[ -d "$THUMBDIR" ]] || mkdir "$THUMBDIR" || exit 2 -MY_HEIGHTS[0]=$MY_HEIGHT_SMALL -MY_HEIGHTS[1]=$MY_HEIGHT_LARGE -for MY_RES in "${MY_HEIGHTS[@]}"; do - [[ -d "$MY_THUMBDIR/$MY_RES" ]] || mkdir -p "$MY_THUMBDIR/$MY_RES" || exit 3 +HEIGHTS[0]=$HEIGHT_SMALL +HEIGHTS[1]=$HEIGHT_LARGE +for RES in "${HEIGHTS[@]}"; do + [[ -d "$THUMBDIR/$RES" ]] || mkdir -p "$THUMBDIR/$RES" || exit 3 done #### Create Startpage -debugOutput "$MY_INDEX_HTML_FILE" -cat > "$MY_INDEX_HTML_FILE" << EOF +debugOutput "$INDEX_HTML_FILE" +cat > "$INDEX_HTML_FILE" << _EOF <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8"> - <title>$MY_TITLE</title> + <title>$TITLE</title> <meta name="viewport" content="width=device-width"> <meta name="robots" content="noindex, nofollow"> - <link rel="stylesheet" href="$MY_CSS"> + <link rel="stylesheet" href="$CSS"> </head> -<body> +<body class="bg-black text-white"> <header> <div class="navbar navbar-dark bg-dark shadow-sm"> <div class="container"> <a href="#" class="navbar-brand"> - <strong>$MY_TITLE</strong> + <strong>$TITLE</strong> </a> </div> </div> </header> -<main class="container"> -EOF +<main class="container text-center"> +_EOF ### Photos (JPG) if [[ $(find . -maxdepth 1 -type f -iname \*.jpg | wc -l) -gt 0 ]]; then -MY_ROWS='3' -echo '<div class="row row-cols-3 no-gutters py-3">' >> "$MY_INDEX_HTML_FILE" +ROWS='3' +echo '<div class="row row-cols-3 g-1 py-3">' >> "$INDEX_HTML_FILE" ## Generate Images -MY_NUM_FILES=0 -for MY_FILENAME in $(ls -r *.[jJ][pP][gG]); do - MY_FILELIST[$MY_NUM_FILES]=$MY_FILENAME - (( MY_NUM_FILES++ )) - debugOutput "$MY_THUMBDIR/$MY_HEIGHT_SMALL/$MY_FILENAME" - $MY_CONVERT_COMMAND -auto-orient -strip -quality $MY_QUALITY -resize "$MY_HEIGHT_SMALL^>" -gravity center -crop "$MY_HEIGHT_SMALL"x"$MY_HEIGHT_SMALL"+0+0 "$MY_FILENAME" "$MY_THUMBDIR/$MY_HEIGHT_SMALL/$MY_FILENAME" - debugOutput "$MY_THUMBDIR/$MY_HEIGHT_LARGE/$MY_FILENAME" - $MY_CONVERT_COMMAND -auto-orient -strip -quality $MY_QUALITY -resize x$MY_HEIGHT_LARGE "$MY_FILENAME" "$MY_THUMBDIR/$MY_HEIGHT_LARGE/$MY_FILENAME" - - cat >> "$MY_INDEX_HTML_FILE" << EOF +NUM_FILES=0 +for FILENAME in $(ls -r *.[jJ][pP][gG]); do + FILELIST[$NUM_FILES]=$FILENAME + (( NUM_FILES++ )) + debugOutput "$THUMBDIR/$HEIGHT_SMALL/$FILENAME" + $CONVERT_COMMAND "$FILENAME" -auto-orient -strip -quality $QUALITY -resize "$HEIGHT_SMALL^>" -gravity center -crop "$HEIGHT_SMALL"x"$HEIGHT_SMALL"+0+0 "$THUMBDIR/$HEIGHT_SMALL/$FILENAME" + debugOutput "$THUMBDIR/$HEIGHT_LARGE/$FILENAME" + $CONVERT_COMMAND "$FILENAME" -auto-orient -strip -quality $QUALITY -resize x$HEIGHT_LARGE "$THUMBDIR/$HEIGHT_LARGE/$FILENAME" + + cat >> "$INDEX_HTML_FILE" << _EOF <div class="col mx-auto"> - <a href="$MY_THUMBDIR/$MY_FILENAME.html"><img src="$MY_THUMBDIR/$MY_HEIGHT_SMALL/$MY_FILENAME" alt="thumbnail: $MY_FILENAME" class="img-fluid border border-white"></a> + <a href="$THUMBDIR/$FILENAME.html"><img src="$THUMBDIR/$HEIGHT_SMALL/$FILENAME" alt="thumbnail: $FILENAME" class="img-fluid"></a> </div> -EOF +_EOF done -echo '</div>' >> "$MY_INDEX_HTML_FILE" +echo '</div>' >> "$INDEX_HTML_FILE" ## Generate the HTML Files for Images in thumbdir -MY_FILE=0 -while [[ $MY_FILE -lt $MY_NUM_FILES ]]; do - MY_FILENAME=${MY_FILELIST[$MY_FILE]} - MY_PREV="" - MY_NEXT="" - [[ $MY_FILE -ne 0 ]] && MY_PREV=${MY_FILELIST[$((MY_FILE - 1))]} - [[ $MY_FILE -ne $((MY_NUM_FILES - 1)) ]] && MY_NEXT=${MY_FILELIST[$((MY_FILE + 1))]} - MY_IMAGE_HTML_FILE="$MY_THUMBDIR/$MY_FILENAME.html" - MY_EXIF_INFO=$($MY_EXIF_COMMAND "$MY_FILENAME") - MY_FILESIZE=$(getFileSize "$MY_FILENAME") - debugOutput "$MY_IMAGE_HTML_FILE" - cat > "$MY_IMAGE_HTML_FILE" << EOF +FILE=0 +while [[ $FILE -lt $NUM_FILES ]]; do + FILENAME=${FILELIST[$FILE]} + PREV="" + NEXT="" + [[ $FILE -ne 0 ]] && PREV=${FILELIST[$((FILE - 1))]} + [[ $FILE -ne $((NUM_FILES - 1)) ]] && NEXT=${FILELIST[$((FILE + 1))]} + IMAGE_HTML_FILE="$THUMBDIR/$FILENAME.html" + EXIF_INFO=$($EXIF_COMMAND "$FILENAME") + FILESIZE=$(getFileSize "$FILENAME") + debugOutput "$IMAGE_HTML_FILE" + cat > "$IMAGE_HTML_FILE" << _EOF <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8"> -<title>$MY_FILENAME</title> +<title>$FILENAME</title> <meta name="viewport" content="width=device-width"> <meta name="robots" content="noindex, nofollow"> -<link rel="stylesheet" href="$MY_CSS"> +<link rel="stylesheet" href="$CSS"> </head> -<body> +<body class="bg-black text-white"> <header> <div class="navbar navbar-dark bg-dark shadow-sm"> <div class="container"> <a href="/" class="navbar-brand"> - <strong>$MY_TITLE</strong> + <strong>$TITLE</strong> </a> </div> </div> </header> <main class="container"> -EOF +_EOF # Pager - echo '<div class="row py-3"><div class="col text-left">' >> "$MY_IMAGE_HTML_FILE" - if [[ $MY_PREV ]]; then - echo '<a href="'"$MY_PREV"'.html" accesskey="p" class="btn btn-secondary" role="button">« Previous</a>' >> "$MY_IMAGE_HTML_FILE" + echo '<div class="row py-3"><div class="col text-left">' >> "$IMAGE_HTML_FILE" + if [[ $PREV ]]; then + echo '<a href="'"$PREV"'.html" accesskey="p" class="btn btn-dark" role="button">« Previous</a>' >> "$IMAGE_HTML_FILE" else - echo '<a href="#" class="btn btn-secondary disabled" role="button" aria-disabled="true">« Previous</a>' >> "$MY_IMAGE_HTML_FILE" + echo '<a href="#" class="btn btn-dark disabled" role="button" aria-disabled="true">« Previous</a>' >> "$IMAGE_HTML_FILE" fi - cat >> "$MY_IMAGE_HTML_FILE" << EOF + cat >> "$IMAGE_HTML_FILE" << _EOF </div> -<div class="col d-none d-md-block text-center"><h3>$MY_FILENAME</h3></div> -<div class="col text-right"> -EOF - if [[ $MY_NEXT ]]; then - echo '<a href="'"$MY_NEXT"'.html" accesskey="n" class="btn btn-secondary">Next »</a>' >> "$MY_IMAGE_HTML_FILE" +<div class="col d-none d-md-block text-center"><h3>$FILENAME</h3></div> +<div class="col text-end"> +_EOF + if [[ $NEXT ]]; then + echo '<a href="'"$NEXT"'.html" accesskey="n" class="btn btn-dark">Next »</a>' >> "$IMAGE_HTML_FILE" else - echo '<a href="#" class="btn btn-secondary disabled" role="button" aria-disabled="true">Next »</a>' >> "$MY_IMAGE_HTML_FILE" + echo '<a href="#" class="btn btn-dark disabled" role="button" aria-disabled="true">Next »</a>' >> "$IMAGE_HTML_FILE" fi - echo '</div></div>' >> "$MY_IMAGE_HTML_FILE" + echo '</div></div>' >> "$IMAGE_HTML_FILE" - cat >> "$MY_IMAGE_HTML_FILE" << EOF + cat >> "$IMAGE_HTML_FILE" << _EOF <div class="row"> <div class="col"> - <p><img src="$MY_HEIGHT_LARGE/$MY_FILENAME" class="img-fluid" alt="Image: $MY_FILENAME"></p> + <p><img src="$HEIGHT_LARGE/$FILENAME" class="img-fluid border border-1 border-dark" alt="Image: $FILENAME"></p> </div> </div> <div class="row"> <div class="col"> - <p><a class="btn btn-primary" href="../$MY_FILENAME">View original ($MY_FILESIZE)</a></p> + <p><a class="btn btn-primary" href="../$FILENAME">View original ($FILESIZE)</a></p> </div> </div> -EOF +_EOF # EXIF - if [[ $MY_EXIF_INFO ]]; then - cat >> "$MY_IMAGE_HTML_FILE" << EOF + if [[ $EXIF_INFO ]]; then + cat >> "$IMAGE_HTML_FILE" << _EOF <div class="row"> <div class="col"> <pre> -$MY_EXIF_INFO +$EXIF_INFO </pre> </div> </div> -EOF +_EOF fi # Footer - # cat >> "$MY_IMAGE_HTML_FILE" << EOF + # cat >> "$IMAGE_HTML_FILE" << _EOF # </main> <!-- // main container --> # <br> # <footer class="footer mt-auto py-3 bg-light"> # <div class="container"> - # <span class="text-muted">$MY_FOOTER - $MY_DATETIME</span> + # <span class="text-muted">$FOOTER - $DATETIME</span> # </div> # </footer> # </body> # </html> -# EOF - (( MY_FILE++ )) +# _EOF + + cat >> "$IMAGE_HTML_FILE" << _EOF +</main> +</body> +</html> +_EOF + + (( FILE++ )) done fi ### Movies (MOV or MP4) if [[ $(find . -maxdepth 1 -type f -iname \*.mov -o -iname '*.mp4' | wc -l) -gt 0 ]]; then - cat >> "$MY_INDEX_HTML_FILE" << EOF + cat >> "$INDEX_HTML_FILE" << _EOF <div class="row"> <div class="col"> <div class="page-header"><h2>Movies</h2></div> @@ -250,29 +255,29 @@ if [[ $(find . -maxdepth 1 -type f -iname \*.mov -o -iname '*.mp4' | wc -l) -gt </div> <div class="row"> <div class="col"> -EOF +_EOF if [[ $(find . -maxdepth 1 -type f -iname \*.mov | wc -l) -gt 0 ]]; then - for MY_FILENAME in *.[mM][oO][vV]; do - MY_FILESIZE=$(getFileSize "$MY_FILENAME") - cat >> "$MY_INDEX_HTML_FILE" << EOF -<a href="$MY_FILENAME" class="btn btn-primary" role="button">$MY_FILENAME ($MY_FILESIZE)</a> -EOF + for FILENAME in *.[mM][oO][vV]; do + FILESIZE=$(getFileSize "$FILENAME") + cat >> "$INDEX_HTML_FILE" << _EOF +<a href="$FILENAME" class="btn btn-primary" role="button">$FILENAME ($FILESIZE)</a> +_EOF done fi if [[ $(find . -maxdepth 1 -type f -iname \*.mp4 | wc -l) -gt 0 ]]; then - for MY_FILENAME in *.[mM][pP]4; do - MY_FILESIZE=$(getFileSize "$MY_FILENAME") - cat >> "$MY_INDEX_HTML_FILE" << EOF -<a href="$MY_FILENAME" class="btn btn-primary" role="button">$MY_FILENAME ($MY_FILESIZE)</a> -EOF + for FILENAME in *.[mM][pP]4; do + FILESIZE=$(getFileSize "$FILENAME") + cat >> "$INDEX_HTML_FILE" << _EOF +<a href="$FILENAME" class="btn btn-primary" role="button">$FILENAME ($FILESIZE)</a> +_EOF done fi - echo '</div></div>' >> "$MY_INDEX_HTML_FILE" + echo '</div></div>' >> "$INDEX_HTML_FILE" fi ### Downloads (ZIP) if [[ $(find . -maxdepth 1 -type f -iname \*.zip | wc -l) -gt 0 ]]; then - cat >> "$MY_INDEX_HTML_FILE" << EOF + cat >> "$INDEX_HTML_FILE" << _EOF <div class="row"> <div class="col"> <div class="page-header"><h2>Downloads</h2></div> @@ -280,27 +285,33 @@ if [[ $(find . -maxdepth 1 -type f -iname \*.zip | wc -l) -gt 0 ]]; then </div> <div class="row"> <div class="col"> -EOF - for MY_FILENAME in *.[zZ][iI][pP]; do - MY_FILESIZE=$(getFileSize "$MY_FILENAME") - cat >> "$MY_INDEX_HTML_FILE" << EOF -<a href="$MY_FILENAME" class="btn btn-primary" role="button">$MY_FILENAME ($MY_FILESIZE)</a> -EOF +_EOF + for FILENAME in *.[zZ][iI][pP]; do + FILESIZE=$(getFileSize "$FILENAME") + cat >> "$INDEX_HTML_FILE" << _EOF +<a href="$FILENAME" class="btn btn-primary" role="button">$FILENAME ($FILESIZE)</a> +_EOF done - echo '</div></div>' >> "$MY_INDEX_HTML_FILE" + echo '</div></div>' >> "$INDEX_HTML_FILE" fi ### Footer -# cat >> "$MY_INDEX_HTML_FILE" << EOF +# cat >> "$INDEX_HTML_FILE" << _EOF # </main> <!-- // main container --> # <br> # <footer class="footer mt-auto py-3 bg-light"> # <div class="container"> -# <span class="text-muted">$MY_FOOTER - $MY_DATETIME</span> +# <span class="text-muted">$FOOTER - $DATETIME</span> # </div> # </footer> # </body> # </html> -# EOF +# _EOF + +cat >> "$INDEX_HTML_FILE" << _EOF +</main> +</body> +</html> +_EOF debugOutput "= done" |