I have a list of images, each one of them has width and height. and I have one div - with width and height
now I have to find out which image would look the best in my div - would be the least distorted.
What i'm trying now is checking the aspect ratios and width - but then i need some kind of weight - how important should be each one.
Is there a better way to do it? Any ready to use algorithms?
edit: about the weight - lets say I have a div of size 100 x 50, and 2 images: 2000 x 1000, 101 x 51. The ratio for first one is perfect - but i would have to scale it down 20 times, so it would be easier for the browser and proabably for the viewer experience use the second image. So I use
a = abs((img.aspect_ratio - div.aspect_ratio) / (img.aspect_ratio + div.aspect_ratio))
b = abs((img.width - div.width) / (img.width + div.width))
// division to scale the value between (0, 1)
and then look for image with smallest a + b. To get better effect tried to use a+2b instead - these are the weights.