The following command will shrink all .jpg’s in the current directory that are larger than 500px and center them on a square 500x500px canvas. Since the aspect ratio of the original images will be preserved and not all of the originals are square, the left over space will be filled with an off-white color. All the modified images will be placed in a directory called ‘resized’. Original filenames will be preserved.
mogrify -path resized -resize 500x500\> -background 'rgb(217,215,202)' -extent 500x500 -gravity center *.jpg