summaryrefslogtreecommitdiff
path: root/static/pic-resize.sh
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2021-07-31 11:35:39 -0600
committerBrian Picciano <mediocregopher@gmail.com>2021-07-31 11:35:39 -0600
commitf1998c321a4eec6d75b58d84aa8610971bf21979 (patch)
treea90783eb296cc50e1c48433f241624f26b99be27 /static/pic-resize.sh
parent03a35dcc38b055f15df160bd300969e3b703d4b1 (diff)
move static files into static sub-dir, refactor nix a bit
Diffstat (limited to 'static/pic-resize.sh')
-rwxr-xr-xstatic/pic-resize.sh39
1 files changed, 39 insertions, 0 deletions
diff --git a/static/pic-resize.sh b/static/pic-resize.sh
new file mode 100755
index 0000000..849d395
--- /dev/null
+++ b/static/pic-resize.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# requires imagemagick and perl-image-exiftool
+
+set -e
+
+widths="500 1000 1500 2000 2500 3000"
+
+for img in $@; do
+ echo $img
+
+ # make target directories
+ dir=$(dirname "$img") # gets directory
+ for targetWidth in $widths; do
+ mkdir -p $dir/${targetWidth}px
+ done
+
+ # get width
+ width=$(identify "$img" | awk '{print $3}' | cut -dx -f1)
+ echo -e "\toriginal width: $width"
+
+ echo -e "\tremoving metadata"
+ exiftool -all= "$img"
+ rm -f "${img}_original" # exiftool makes a copy of the original, delete it
+
+ for targetWidth in $widths; do
+ targetFile=$dir/${targetWidth}px/$(basename "$img")
+ echo -en "\tresizing into $targetFile... "
+ if [ "$targetWidth" -ge "$width" ]; then
+ echo "skipping, original image too small"
+ continue
+ elif [ -e "$targetFile" ]; then
+ echo "skipping, target file exists"
+ continue
+ fi
+ convert "$img" -resize $targetWidth "$targetFile"
+ echo "done"
+ done
+done