1

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.

agend
  • 648
  • 1
  • 8
  • 18
  • If you are looking for 'best quality', how are you taking into account for the definition of image? Also, this could be of interest: http://stackoverflow.com/questions/2250693/looking-for-image-distortion-algorithm?rq=1 – jbutler483 Sep 01 '14 at 11:27
  • I think you should just compare `width/height` of the div to `width/height` of the pictures and take whichever is closest – tobias_k Sep 01 '14 at 11:36
  • possible duplicate of [How to determine which aspect ratios are closest](http://stackoverflow.com/questions/10416366/how-to-determine-which-aspect-ratios-are-closest) – Joe Sep 01 '14 at 11:41
  • " i need some kind of weight ": can you provide some kind of explanation ? –  Sep 01 '14 at 13:18
  • jbutler - what do u mean by 'definition of image'? I'm not familiar with 'seam carving' but I believe it would be computational intensive - I'm looking for something which could be done as easy and as fast as possible. – agend Sep 01 '14 at 13:49

0 Answers0