Skip to content

Instantly share code, notes, and snippets.

@fernandomr
Last active August 3, 2022 12:14
Show Gist options
  • Save fernandomr/c096fb42a51fbcf44201d3bdb8b02242 to your computer and use it in GitHub Desktop.
Save fernandomr/c096fb42a51fbcf44201d3bdb8b02242 to your computer and use it in GitHub Desktop.
Resize images using imagemagick
# absolute path to image folder
FOLDER=""
# max width
WIDTH=620
# max height
HEIGHT=620
cd prods/
# it is array of dirs already
arrayOfDirs=(*/)
# loop trough dirs
for dir in "${arrayOfDirs[@]}"; do
echo "entering $dir";
cd $dir;
# FOLDER=$(pwd);
# get files bigger than 640kb
arqs=( $(find ./ -maxdepth 1 -type f -size +640k) )
numOfFiles=${#arqs[@]}
# echo "num of files: $numOfFiles"
if [ $numOfFiles > 0 ]; then
for fileItem in ${arqs}; do
# echo "$fileItem";
# mount file absolute path
aux=${fileItem##*/} # fileItem is in format "./2938230982309823.png". This cuts after './'
dotSlash="/"
# fileAbsolutePath=$FOLDER$dotSlash$aux
# echo "$fileAbsolutePath";
echo "--processing $aux";
convert $aux -verbose -resize $WIDTHx$HEIGHT $aux
done
fi
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment