Skip to content

Instantly share code, notes, and snippets.

@tinacious
Last active August 29, 2015 13:55
Show Gist options
  • Save tinacious/8755602 to your computer and use it in GitHub Desktop.
Save tinacious/8755602 to your computer and use it in GitHub Desktop.
This bash script batch resizes and renames images. Run this script in a directory with images to process them. It will ask you: current file extension, and desired filename and size.
# Image processing function
# Usage: In the Terminal, run: bash images.sh
# Get user input and resize images
function process () {
# rename
a=1
for i in *.${ext}
do
new=$(printf "${filename}_%03d.${ext}" ${a}) # %03d = 3 digits
mv ${i} ${new}
let a=a+1
done
# resize
sips -Z ${size} *.${ext}
}
# Interveiw
echo "What would you like the filename to be?"
read filename
echo "What is the file extension of your image? Must be case sensitive (jpg JPG png PNG)"
read ext
echo "What width in pixels would you like your images?"
read size
# Confirm and process
read -p "Your filename will be '$filename' and the width will be $size pixels. Continue? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
process
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment