-
-
Save sineld/fe6a21fd27fda537b83b5d552050d2e0 to your computer and use it in GitHub Desktop.
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 | |
# This script resizes all the images it finds in a folder (and its subfolders) and resizes them | |
# The resized image is placed in the /resized folder which will reside in the same directory as the image | |
# | |
# chmod +x batch_resize.sh | |
# Usage: > ./batch_resize.sh | |
# or run: | |
# sips -Z 600 *.jpg | |
initial_folder="/your/images/folder" # You can use "." to target the folder in which you are running the script for example | |
resized_folder_name="resized" | |
all_images=$(find -E $initial_folder -iregex ".*\.(jpg|gif|png|jpeg)") | |
while read -r image_full_path; do | |
filename=$(basename "$image_full_path"); | |
source_folder=$(dirname "$image_full_path"); | |
destination_folder=$source_folder"/"$resized_folder_name"/"; | |
destination_full_path=$destination_folder$filename; | |
if [ ! -z "$image_full_path" -a "$image_full_path" != " " ] && | |
# Do not resize images inside a folder that was already resized | |
[ "$(basename "$source_folder")" != "$resized_folder_name" ]; then | |
mkdir "$destination_folder"; | |
# If you are not using this in an OSX system, you can use imagemagick's "convert" command instead (http://www.imagemagick.org/script/convert.php) | |
sips -Z 600 "$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