Last active
July 5, 2021 16:13
-
-
Save rendon/bc5f2c351c203f30f846f8e2da58085a to your computer and use it in GitHub Desktop.
A script to scale images using ImageMagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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