Child pages
  • How to resize pictures (jpg, jpeg, gif, png, tiff, bmp) in recursive folder
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

#!/bin/bash
 
echo -n "Enter the width of resize in pixel : "
read size
echo -n "Name of folder you want to resize : "
read foldername
 
# populate the array
while IFS='' read -r -d '' file; do
array+=("$file")
done < <(find . \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.tiff" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" \) -type f -print0)
 
# loop through all elements
for ((i=0; i<${#array[*]}; i++)); do
dir=${array[i]%/*}
name=${array[i]##*/}
if [[ ! -d "$dir/$foldername" ]]; then
 mkdir "$dir/$foldername"
fi
echo converting "${array[i]}"
convert "${array[i]}" -adaptive-resize $size "$dir/$foldername/thumbnail_$name"
done
 
exit 0
  • No labels