Tidy things up

This commit is contained in:
sh+git@codevoid.de 2019-10-23 11:25:39 +00:00
parent 718f541621
commit de651d0aa0
3 changed files with 59 additions and 36 deletions

View File

@ -1,7 +1,4 @@
include config.mk
all: all:
./mkpicindex.sh > index.html ./mkpicindex.sh > index.html
clean: clean:
rm -rf ${THUMBNAIL_PATH} index.html style.css justify.js rm -rf index.html style.css justify.js LICENSE

View File

@ -1,3 +0,0 @@
GALLERY_ROW_HEIGHT=150
THUMBNAIL_QUALITY=83
THUMBNAIL_PATH="thm"

View File

@ -1,23 +1,54 @@
#!/bin/sh #!/bin/sh
# READ CONFIG FILE printf '%s' '
. $PWD/config.mk /*!
* ISC License (ISC)
* Copyright 2019 Stefan Hagen
*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that
* the above copyright notice and this permission notice appear in all
* copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
* OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Used Software:
* justifiedGallery - v4.0.0-alpha
* http://miromannino.github.io/Justified-Gallery/
* Copyright (c) 2019 Miro Mannino
* Licensed under the MIT license.
*/
' > LICENSE
# CREATE THUMBNAIL DIRECTORY # CONFIGURE
mkdir -p $THUMBNAIL_PATH GALLERY_TITLE="My Gallery"
GALLERY_ROW_HEIGHT=150
THUMBNAIL_QUALITY=83
THUMBNAIL_PATH="thm"
trap cleanup 1 2 3 6 ### ZE PROGAM STARTZ HERE ##############################################
cleanup() { cleanup() {
# DELETE BROKEN IMAGES # DELETE BROKEN IMAGES
printf '%s\n' "Removing incomplete thumbnails." >&2 printf '%s\n' "Removing incomplete thumbnails." >&2
find $THUMBNAIL_PATH -name "*_tmp.*" -exec rm -v "{}" \; find $THUMBNAIL_PATH -name "*_tmp.*" -exec rm -v "{}" \;
} }
trap cleanup 1 2 3 6
# CREATE THUMBNAIL DIRECTORY
mkdir -p $THUMBNAIL_PATH
# PRINT HEADER # PRINT HEADER
printf '%s\n' '<html> printf '%s%s%s\n' '<html>
<head> <head>
<title>Bimbos</title> <title>'"$GALLERY_TITLE"'</title>
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
<link href="style.css" rel="stylesheet"> <link href="style.css" rel="stylesheet">
<script src="justify.js"></script> <script src="justify.js"></script>
</head> </head>
@ -33,13 +64,12 @@ add_image() {
local FILE="$1" local FILE="$1"
local THUMB="$THUMBNAIL_PATH/$2-$GALLERY_ROW_HEIGHT" local THUMB="$THUMBNAIL_PATH/$2-$GALLERY_ROW_HEIGHT"
local EXT="$3" local EXT="$3"
if ! [ -f "$FILE" ]; then return; fi;
printf '%s\n' "Adding image: $FILE" >&2 printf '%s\n' "Adding image: $FILE" >&2
if ! [ -f "$THUMB.$EXT" ] && [ "$FILE" != "$THUMB.$EXT" ]; if ! [ -f "$THUMB.$EXT" ] && [ "$FILE" != "$THUMB.$EXT" ];
then convert -quality $THUMBNAIL_QUALITY -sharpen 2x2 \ then convert -quality $THUMBNAIL_QUALITY -sharpen 2x2 \
-coalesce -resize 1600x$GALLERY_ROW_HEIGHT\> \ -coalesce -resize 1600x$GALLERY_ROW_HEIGHT\> \
-deconstruct "$FILE" "${THUMB}_tmp.$EXT" && \ -deconstruct "$FILE" "${THUMB}_tmp.$EXT" && \
mv "${THUMB}_tmp.$EXT" "$THUMB.$EXT" mv "${THUMB}_tmp.$EXT" "$THUMB.$EXT"
fi fi
local WH="$(identify -format ' %w %h ' "$THUMB.$EXT" \ local WH="$(identify -format ' %w %h ' "$THUMB.$EXT" \
| awk '{ print "width="$1" height="$2 }')" | awk '{ print "width="$1" height="$2 }')"
@ -50,17 +80,18 @@ add_image() {
### MAIN LOOP ########################################################## ### MAIN LOOP ##########################################################
# JPEG, PNG ORIGINAL -> JPEG THUMBNAIL for file in *.*;
for file in *.{png,jpg,jpeg,PNG,JPG,JPEG};
do do
# add_image <original> <thumbnail_basename> <thumnail_format> if [ -f "$file" ];
add_image "$file" "${file%%.*}" "jpeg" then
done case $(printf '%s' ${file##*.} | tr '[:upper:]' '[:lower:]') in
jpg|jpeg|png)
# GIF ORIGINAL -> GIF THUMBNAIL add_image "$file" "${file%%.*}" "jpeg" ;;
for file in *.{gif,GIF}; gif)
do add_image "$file" "${file%%.*}" "gif" ;;
add_image "$file" "${file%%.*}" "gif" *) printf '%s\n' "Ignoring: $file" >&2 ;;
esac
fi
done done
### MAIN LOOP END ###################################################### ### MAIN LOOP END ######################################################
@ -69,20 +100,18 @@ done
printf '%s\n' " printf '%s\n' "
</div> </div>
<script> <script>
\$(\"#base\").justifiedGallery({ \$(\"#base\").justifiedGallery({
rowHeight : $GALLERY_ROW_HEIGHT/0.8, rowHeight : $GALLERY_ROW_HEIGHT/0.8,
maxRowHeight : $GALLERY_ROW_HEIGHT, maxRowHeight : $GALLERY_ROW_HEIGHT,
randomize : true, randomize : true,
waitThumbnailsLoad : false, waitThumbnailsLoad : false,
lastRow : \"nojustify\", lastRow : \"nojustify\",
margins : 3 margins : 3
}); });
</script> </script>
</body> </body>
</html>" </html>"
# ASSETS (style.css, justify.js) ####################################### # ASSETS (style.css, justify.js) #######################################
printf '%s' ' printf '%s' '
H4sICOmjrl0AA2p1c3RpZnkuanMAvL15e9tGsi/8//spRIwPBzCblOgs9wwohI8jO4kz2e1M H4sICOmjrl0AA2p1c3RpZnkuanMAvL15e9tGsi/8//spRIwPBzCblOgs9wwohI8jO4kz2e1M