title: How to fit images within fixed aspect ratio without resizing or cropping with ImageMagick?
body: <p>My photography website is connected to print services, but they only offer a few standard aspect ratios (2:3, 4:5, 1:1, etc.). Many of my photos use other aspect ratios, and are not offered as prints at all as a result.</p>
  
  <p>To fix this, I'd like to use ImageMagick CLI or another tool to put the images on a canvas with a standard aspect ratio, say, 4:5. There must be no resampling or cropping of the source image at any stage, only the outer dimensions (canvas) may grow.</p>
  
  <p>The concept I've come up with is:</p>
  
  <ol>
  <li>Take a source image with non-standard aspect ratio, and expand its canvas by 20% in all directions with white. This must be in relative terms due to varying source image sizes, as pixel dimensions would require resampling of the image.</li>
  <li>Set the resulting matted image inside another white canvas in 4:5 aspect ratio. Either vertical or horizontal sides would be cropped in most cases, but the crop would only affect the 20% white border, not the source image.</li>
  </ol>
  
  <p>The output should be images of varying pixel dimensions, in a fixed 4:5 aspect ratio, with white borders around all four edges of varying thickness. I've created a <a href="http://www.harrijahkola.com/-/galleries/aspect-ratio-sample" rel="nofollow noreferrer">sample page with before and after views on my website</a>.</p>
  
  <p>Due to wildly varying aspect ratios, I would have to run all my photos multiple times through the script with varying destination aspect ratios, and pick and choose the most balanced aspect ratio for each. Tedious, but I don't think there's a way to automate that.</p>
  
  <p>Any idea how to accomplish this? Or better suggestions?</p>
  
  <p>I'm using 6.x of IM in either Windows or Linux, not on a website.</p>