Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 165003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:50:39+00:00 2026-05-11T11:50:39+00:00

For instance, if I need to fill a bounding box that is 100px wide

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:50:40+00:00Added an answer on May 11, 2026 at 11:50 am

    What you’re asking for is pretty easy. Calculate the different scaling factors for the width and the height, then pick the larger one for your actual scale factor. Multiply your input size by the scale, and crop whichever one comes out too large.

    scale = max(maxwidth/oldwidth, maxheight/oldheight) scaledwidth = oldwidth * scale scaledheight = oldheight * scale if scaledheight > maxheight:     croptop = (scaledheight - maxheight) / 2     cropbottom = (scaledheight - maxheight) - croptop if scaledwidth > maxwidth:     cropleft = (scaledwidth - maxwidth) / 2     cropright = (scaledwidth - maxwidth) - cropleft 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a function that is passed an instance of a CharField.
I need to serialize a Lucene.net Document instance. When I try the following public
I need to mock a GrailsControllerClass interface. Instance should have a static variable defined.
I need some help. I'm looking to have a sidebar that toggles when a
I have a custom object and NSMutableArray as instance member. I fill the array
I need some help! I have no doubt this is a dumb problem that
I need to create a new DB2 instance and import a database from the
I need to get an instance of the application's MembershipProvider from within a controller.
I need to connect to a MongoDB instance from my EJB3 application, running on
I need to replace every instance of any text in square brackets with something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.