Scale image to completely fill bounding box

Posted by Larsenal on Stack Overflow See other posts from Stack Overflow or by Larsenal
Published on 2009-03-06T03:36:16Z Indexed on 2010/05/08 10:18 UTC
Read the original article Hit count: 270

Filed under:
|
|

For instance, if I need to fill a bounding box that is 100px wide by 50px tall, the following input images would have the following behavior:

  1. 200w x 200h gets scaled down 50% and 25% gets chopped off the top and bottom.

  2. 200w x 100h gets scaled down 50% with no cropping.

  3. 100w x 200h gets is not scaled, but 75px get chopped off top and bottom.

This seems like it'd be a common resizing function, but I haven't been able to track down an example of the algorithm.

Will accept answer in any language including pseudo code. A link to a page with the answer is great too!

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about image