Skip to content

Instantly share code, notes, and snippets.

@rendon
Last active July 5, 2021 16:13
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 rendon/bc5f2c351c203f30f846f8e2da58085a to your computer and use it in GitHub Desktop.
Save rendon/bc5f2c351c203f30f846f8e2da58085a to your computer and use it in GitHub Desktop.
A script to scale images using ImageMagick
#!/usr/bin/env bash
SOURCE_DIRECTORY=$1 # Provide absolute path
TARGET_DIRECTORY=$2 # Provide absolute path
if [ ! -d $SOURCE_DIRECTORY ]
then
echo "Source directory ${SOURCE_DIRECTORY} does not exist"
exit 1
fi
if [ ! -d $TARGET_DIRECTORY ]
then
echo "Target directory ${TARGET_DIRECTORY} does not exist"
exit 1
fi
cd $SOURCE_DIRECTORY
# Update file extension as needed
for file in $(ls -1 *.JPG)
do
# Resize to specific dimensions and keep aspect ratio
# Update dimmentions as needed
convert -verbose $file -resize 3500x3500 "${TARGET_DIRECTORY}/$file"
done
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment