How does Lightroom Classic calculate export Width & Height?
Explanation
Entry requirements for photographic competitions and distinctions/awards often specify a maximum pixel height and width for digital projected images.
This specifies the dimensions of a box inside which the image must fit.
In the Lightroom Classic (LrC) export dialogue under "Resize image" you can select "Width & Height" and LrC does the maths to export to the appropriate pixel dimensions.
I had been wondering about the logic that LrC uses to calculate these dimensions.
This page was created in an attempt to understand this logic.
When manually working out these dimensions I would decide whether the target height or the target width would have to be the exported dimension and then calculate the other exported dimension to maintain the original aspect ratio.
I couldn't work out how a computer would work this out.
Googling revealed that Lightroom Classic (LrC) works out the aspect ratio of the original image as a decimal number and then compares this with the aspect ratio of the target image as a decimal number and then proceed according to which is greater.
So the logic goes as follows:
If ($originalRatio > $targetRatio )
{
$exportWidth = $targetWidth;
$exportHeight = ($originalHeight * $targetRatio * $targetHeight)/$originalWidth;
}
else
{
$exportHeight = $targetHeight;
$exportWidth = $originalWidth * $targetHeight/$originalHeight;
}
The calculator at the top of this page can be used to calculate pixel dimensions to which an image should be resized to comply with competition pixel widths and heights.
I expect most image processing software such as Lightroom Classic will have a built way of exporting to these dimensions so it will probably be unnecessary to refer to this page.
This was just a little personal project to understand how the software would do this.