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 9182473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:34:04+00:00 2026-06-17T18:34:04+00:00

I know I could do this with a bunch of nested if statements, however

  • 0

I know I could do this with a bunch of nested if statements, however I can’t help feel like there’s a more elegant way. It’s really just a maths issue I guess, but I’m interested in pythonic answers if indeed there are any.

I have an image which can be ANY dimensions / aspect ratio.

It must be scaled up OR down so that it covers a minumum of 55w x 168h

The complication here is that it needs to be scaled by a function that takes only a single value which specifies the length of a side of a square which the image it will fit inside.

For instance, say we have an image of size 1000w x 500h and we scale it to 200, then the resulting image must fit inside a square the with a side of 200, meaning the resulting image would be 200w x 100h.

Conversely if our image is 200×1000 and we scale to to 200, we’ll end up with 40×200.

So to scale an image of 1000×500 to cover 55×168, we’d need to scale it to 336, giving a size of 336×168 since that’s the largest image which can fit inside a 336×336 sided square.

And to scale an image of 200×1000 to cover 55×168, we’d need to scale it to 275 and end up with 55×275.

Hopefully this is clearer than mud! Thanks for any ideas.

Justification: For those who are interested in why I’m scaling via a value of a square side, this is the way Picasa scales images via URL injection. For instance take the following 2 URLs:

  • https://lh3.googleusercontent.com/-rvkbjZgBMDs/UEHYD3VmGVI/AAAAAAAADwM/UekknfI838s/s150/IMG_20120901_172419.jpg
  • https://lh6.googleusercontent.com/-6BHPw9kYIQc/UEHYBS5z-dI/AAAAAAAADwA/QkEWF3H797A/s150/IMG_20120901_172405.jpg

Notice both have the URL component s150, however one image is 150×112 and the other is 112×150. 150 is the value of the square these images will both fit in.

  • 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. Editorial Team
    Editorial Team
    2026-06-17T18:34:06+00:00Added an answer on June 17, 2026 at 6:34 pm
    def name_of_function(img_x, img_y):  # for lack of a better name
        image_dimensions = (img_x, img_y)
        min_dimensions = (55.0, 168.0)
        scale = min(image_dimensions[i]/min_dimensions[i] for i in range(2))
        return max(i/scale for i in image_dimensions)
    
    name_of_function(1000, 500)
    # 336.0
    name_of_function(200, 1000)
    # 275.0
    

    Pretty sure this is what you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this could be done manually with some hardcoded Linq Joins. However, I
This could be a very basic Javascript I know but I just can't get
I know this question has been asked multiple times (however, I could still not
I know I could solve this with a header but I'd rather not have
Does anyone know where I could find this file on Ubuntu?
I don't know what could be causing this issue, but for some reason, elements
I know this doubt could be silly mistake. I am getting a variable from
I know I could use PHP to do this, but wanted to find out
Introduction: Now I know this question could be very broad and it would be
This is a great big mess... I know I could use an iframe, but

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.