Skip to content

Instantly share code, notes, and snippets.

@jasny
Last active April 30, 2022 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasny/f20cffc77a09e5dce04146b6c1cab076 to your computer and use it in GitHub Desktop.
Save jasny/f20cffc77a09e5dce04146b6c1cab076 to your computer and use it in GitHub Desktop.
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