Skip to content

Instantly share code, notes, and snippets.

@OatmealBath
Created August 6, 2019 16:52
Show Gist options
  • Save OatmealBath/1ed3e7fc169d0adefb10c0370b9cbc30 to your computer and use it in GitHub Desktop.
Save OatmealBath/1ed3e7fc169d0adefb10c0370b9cbc30 to your computer and use it in GitHub Desktop.
Bulk Resize Images OSX
initial_folder="." # You can use "." to target the folder in which you are running the script for example
all_images=$(find -E $initial_folder -iregex ".*\.(jpg|gif|png|jpeg|tiff)")
while read -r image_full_path; do
filename=$(basename "$image_full_path");
source_folder=$(dirname "$image_full_path");
destination_folder=$source_folder;
destination_full_path=$destination_folder"/"$filename;
<<< "$destination_full_path"
height=`sips --getProperty pixelHeight "$image_full_path" | sed -E "s/.*pixelHeight: ([0-9]+)/\1/g" | tail -1`
width=`sips --getProperty pixelWidth "$image_full_path" | sed -E "s/.*pixelWidth: ([0-9]+)/\1/g" | tail -1`
if [[ $height -gt 2200 || $width -gt 2200 ]]; then
<<< "large file needs reducing"
sips -Z 2200 "$image_full_path" --out "$destination_full_path";
fi
done <<< "$all_images"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment