Skip to content

Instantly share code, notes, and snippets.

Last active March 28, 2022 16:22
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# 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
# Usage: > ./
initial_folder="/your/images/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)")
while read -r image_full_path; do
filename=$(basename "$image_full_path");
source_folder=$(dirname "$image_full_path");
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 (
sips -Z 700 "$image_full_path" --out "$destination_full_path";
done <<< "$all_images"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment