Last active
December 6, 2017 16:02
-
-
Save Phlow/18e8fa9e436855242a7a04943596147a to your computer and use it in GitHub Desktop.
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.
This file contains 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
#!/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