Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script makes a copy of images, resizes the copied images and renames the copied images with the correct width and height. The information gets the script from sips.
#!/bin/bash
#
# 1. This script copies all *.jpg-files to a new folder
# 2. Jumps into folder and resizes all files with sips
# 3. Renames all files and uses information from sips
#
folder="processed"
height="320"
width="160" # not used
mkdir -p "$folder"
cp *.jpg "$folder"
cd "$folder"
# RESIZE ALL IMAGES TO MAXIMUM HEIGHT OF $height
echo "RESIZE ALL IMAGES WITH MAXIMUM HEIGHT OF $height"
sips --resampleHeight "$height" *.jpg
# RENAME FILES WITH INFORMATION FROM SIPS
for i in *.jpg
do
pixelWidth=$(sips -g pixelWidth "$i" | awk '/pixelWidth:/{print $2}')
pixelHeight=$(sips -g pixelHeight "$i" | awk '/pixelHeight:/{print $2}')
# REMOVE EXTENSION
filename=${i%.jpg}
# NOW RENAME
mv $i ${filename##*/}-${pixelWidth}x${pixelHeight}.jpg
done
for i in *.jpg
do
echo -e "\x1b[0;33mOptimize $i now with Guetzli"
guetzli -quality 85 $i $i
echo -e "\033[32mDone ✓\033[0m"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment