The script to resize all .png files in a folder to 30%. The original file can either be removed (if delete_original is true), or stays, in that case the resized file would get a name postfix rename_postfix:
#!/bin/bash
rename_postfix="-small"
delete_original=true
substr=".png"
for str in *.png; do
#reverse strings
reverse_str=$(echo $str | rev)
reverse_substr=$(echo $substr | rev)
#find index of reversed substring in reversed string
prefix=${reverse_str%%$reverse_substr*}
reverse_index=${#prefix}
#calculate last index
index=$(( ${#str} - ${#substr} - $reverse_index ))
# Extract the filename without extension
filename="${str:0:index}"
if $delete_original; then
# the name can remain, because the original will be removed
new_filename="${str}"
else
# need a new name, two files will remain
new_filename="${filename}${rename_postfix}${substr}"
fi
echo "extension = ${substr}, original = ${str}, filename = ${filename}, new = ${new_filename}"
# Resize and convert the file to .jpg
convert -resize 30% "${str}" "${new_filename}"
done
I think you should be able to write a function with the above body that would accept a directory argument, etc (if you want to make it go into subfolders)
The convert function is from the imagemagick library:
sudo apt install imagemagick
find . -name "*.jpg" -exec mogrify -resize 820x {} +will do them all; if you don't want to process the "less than 820px" ones, there are some options here.