Resize images automatically based on width, height or percentage

Recently I came up with the issue of having to resize a set of images based on their width and at keep aspect ratio at the same time. I came up with the following threads on stackoverflow:


https://stackoverflow.com/questions/15987091/imagemagick-resize-images-to-25px-height-and-aspect-ratio
https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash

The purpose is to resize all images in the current folder using ImageMagick, while keeping old files and whereas the new filenames are written with the same extension and an appendix for easier identification of the resized images. The new filenames  also could be easily put in a new folder by changing the destination within the following commands:

 #!/bin/bash

# resize image based on width and keep aspect ratio
for i in *; do convert -verbose -geometry 800x "$i" "${i%.*}-small.${i##*.}"; done

# resize image based on height and keep aspect ratio
for i in *; do convert -verbose -geometry x600 "$i" "${i%.*}-small.${i##*.}"; done

# resize image by percentage and keep aspect ratio
for i in *; do convert -verbose -resize 40% "$i" "${i%.*}-small.${i##*.}"; done
A simple solution for designers who need to convert a folder of images at once instead of using a graphical editor and having to go through each image separately.