WobertC's method won't quite work. Consider a 5472 x 3648 photo (a 3 x 2 ratio). When I crop that to 2338 wide, maintaining the original ratio, LR truncates the desired 1558 2/3 pixel height to 1558 (it should have rounded to 1559 rather than truncating, but LR gets much of the arithmetic of cropping a little wrong). Neither 2338 x 1558 nor 2338 x 1559 simplify to 3 x 2.
So instead, the code should search through the list of common photo ratios, looking for one that matches the cropped dimensions, possibly off by one pixel:
local ratios = {{1, 1}, {3,2}, {4, 3}, {5, 4}, {16, 9}}
local function aspectRatio (w, h)
if w < h then w, h = h, w end
for _, ratio in ipairs (ratios) do
local rw, rh = ratio [1], ratio [2]
local delta = math.abs (rw / rh * h - w)
if delta <= 1 then return rw, rh end
end
return nil, nil
end
But note that there are many cameras that produce images claiming a 3 x 2 aspect ratio but that are in fact slightly different:
Nikon D90, 4288 x 2848 ~ 1.5056
Nikon D3200, 6016 x 4000 = 1.504
Nikon D750, 6016 x 4016 ~ 1.498
Canon EOS Rebel T1i, 5477 x 3651 ~ 1.50014
(These are just some of the cameras from my catalog that I looked at.) All but the last differ by more than one pixel in width from the 3 x 2 aspect ratio. So if you want to label these as "3 x 2", you'll need to use a "fuzzier" test:
local delta = math.abs (rw / rh - w / h)
if delta <= 0.006 then return rw, rh end
I don't have an exhaustive list of camera sensors, so I don't know if the maximum delta of 0.06 is the best value.
Of course, this "fuzzy" matching will include crops that also don't quite match the common ratios exactly (or off by one pixel).
[Use the blue reply button under the first post to ensure replies sort properly.]