I was recently given the task of converting a massive corpus of images (10) to a fixed resolution with a fixed amount of padding. In the past, I’ve used ImageMagick to make quick work of problems like this, but I can never remember its commands. Maybe I should write down my solutions as an investment in my future self.
Okay, future self, here’s my incantation to scale and pad these images:
mogrify -resize 70x70 -background none -gravity center -extent 133x133 *.png
I’m not going to generalize this code. My future self would prefer to just change the numbers and throw the code away. We first scale the image to 70 pixels square with
-resize 70x70. Then we embed it in the middle of a transparent background that’s 133 pixels square.