title: ImageMagick: resize with borders in batch
body: <p>I have a few images I want to convert in batch using ImageMagick.</p>
  
  <p>All images should be converted to a specific width, lets say <code>500px</code>.</p>
  
  <ul>
  <li>If an image's width is larger than <code>500px</code>, scale it down and preserve the aspect ratio.</li>
  <li>If an image's width is less than <code>500px</code>, add borders to the sides to make it <code>500px</code> wide.</li>
  </ul>
  
  <p>The first one is possible using <code>magick mogrify -resize 500x *</code>, but this also scales images with a smaller width up. How can I prevent that from happening and add borders instead?</p>
  
  <p>I figured I could just add <code>-background black -gravity center</code> but I don't know how to prevent upscaling. </p>