Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create missing resized images for Fiestainfo
#!/bin/bash
ALBUM=$1
mkdir -p "$ALBUM/original" "$ALBUM/new"
aws s3 ls "s3://fiestainfo-old-images/albums/$ALBUM/" | awk '{for(i=4; i<=NF; ++i) printf "%s ", $i; print ""}' | grep -v '.DS_Store' > "$ALBUM/list"
function resize_image {
IMAGE=$1
SIZE=$2
test -f "$ALBUM/original/$IMAGE" || aws s3 cp "s3://fiestainfo-old-images/albums/$ALBUM/$IMAGE" "$ALBUM/original/$IMAGE"
convert "$ALBUM/original/$IMAGE" -resize $SIZE^ -gravity center -crop $SIZE+0+0 "$ALBUM/new/$SIZE-crop.$IMAGE"
}
grep -E -v 'thumb_|normal_|[0-9]+x[0-9]+' "$ALBUM/list" | while read IMAGE; do
for SIZE in 250x188 400x300 500x375 600x450 800x600 1200x900; do
grep -q "$SIZE-crop.$IMAGE" "$ALBUM/list" || resize_image "$IMAGE" $SIZE
done
done
if [ "$(ls -A $ALBUM/new)" ]; then
aws s3 sync "$ALBUM/new/" "s3://fiestainfo-old-images/albums/$ALBUM/"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment