A one-liner to convert and scale any JPEG image into a square 512x512 pixels only if any side is larger than 512px.
$ convert -resize 1:1\!\> -resize 512x512\> input.jpg output.jpg
1:1
is the aspect ratio!
ignores the original aspect ratio>
shrinks the larger side