Skip to content

Instantly share code, notes, and snippets.

@palamago
Created October 12, 2018 19:51
Show Gist options
  • Save palamago/f0eb0cd00fe1beee3e78101ab2358e67 to your computer and use it in GitHub Desktop.
Save palamago/f0eb0cd00fe1beee3e78101ab2358e67 to your computer and use it in GitHub Desktop.
Iterate recursively over folders and convert every image
#!/bin/bash
function loop() {
shopt -s nullglob
for dir in $1/*/
do
dir=${dir%*/}
if [ -d "$dir" ]
then
echo "FOLDER-> $dir"
for file in $dir/*.jpg
do
echo " FILE-> $file"
convert -contrast -gravity center -resize 340x220\^ -extent 340x220 -background white -colorspace RGB -quality 75 -format jpg $file $file
done
loop "$dir"
fi
done
}
loop "$PWD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment