The Scenario
I have a list of print formats, and an uploaded image.
The image may match certain formats well, and others less.
For instance, if the image is in ratio 4:3
, it will match a format 40 x 30 cm
.
However, there are also formats which do not fit the image exactly, for example: 40 x 35 cm
.
The Problem
The formats need to be ordered by how well they fit the image.
Code
$formats = array(
'30x40',
'35x40',
'40x60'
);
// Ratios in the format (such as 3:4) won't serve us in calculations.
// Therefore we use the images aspect factor, which we compute
// like this:
$imageAspectFactor = $imageX / $imageY;
At least that's how i think i could do this.
Question
From here on out, i have no idea where to go. Mathematically speaking, how can the aspect factor of the image be matched against the resulting aspect factor of the (current) format (in the loop), so that the resulting value can be used as an array key for building a new, ordered array of formats?
In order to understand this better, see the following, practical code snippet:
Practical Code
$formats = array(
'30x40',
'35x40',
'40x60'
);
foreach($formats as $formatString){
list($formatX, $formatY) = explode('x', $formatString);
$formatAspectFactor = $formatX / $formatY;
$output[/* NUMERIC THAT REPRESENTS HOW WELL FORMAT MATCHES IMAGE*/] = $formatString;
}
ksort($output);
Please take note: i don't need a complete solution, unless you feel overly motivated. What i look for is the mathematical understanding of how to calculate how well a number matches another one, and represent this, somehow, in a numeric.