ImageMagick
Creating Thumbnails
Creating a thumbnail that keeps the aspect ratio and adds a border when necessary.
file_name=image
file_extn=jpg
convert -define jpeg:size=150x150 "${file_name}.${file_extn}" \
-resize 150x150 \
-background white -gravity center \
-extent 150x150 "${file_name}-150x150.${file_extn}"
Or, relying on defaults in ImageMagick:
convert ${file_name}.${file_extn} -scale 150x150 -gravity center \
-extent 150x150 ${file_name}-150x150.${file_extn}