From 5cfce76ac1a3219fc30ae3227d1c912dd7122508 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 29 Sep 2018 15:52:27 -0400 Subject: implement responsive image sizing for mr-worldwide posts (and all others going forward) --- pic-resize.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 pic-resize.sh (limited to 'pic-resize.sh') diff --git a/pic-resize.sh b/pic-resize.sh new file mode 100755 index 0000000..849d395 --- /dev/null +++ b/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 -- cgit v1.2.3