I have an array:
$resolutions = array( '480x640', '480x800', '640x480', '640x960', '800x1280', '2048x1536' );
I want to retrieve closest larger value with the nearest aspect ratio (same orientation).
So, in case of
$needle = '768x1280' –
And, in case of
$needle = '320x240' –
640x480. While the closest here is
480x640 it shouldn’t be matched, because its aspect ratio differs too much.
So on, and so forth.
I have a set of images with resolutions as specified in
$resolutions. Those images are going to be used for smartphone wallpapers.
screen.height to determine
On the server side, I am going to fetch the closest larger value of the given resolution, scale it down to fit the whole screen while preserving aspect ratio, and if something overlaps the dimensions, crop it to perfectly fit the screen.
While everything is pretty simple with scaling and cropping, I cannot think of a way to find out the closest larger value, to load the reference image.
In case it helps,
$needle can be in a different format, ie.:
array('width' => x, 'height' => y).
I tried to experiment with levenshtein distance: http://codepad.viper-7.com/e8JGOw
Apparently, it worked only for
768x1280 and resulted
320x240 it resulted in
480x640 but that does not fit this time.