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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:16:25+00:00 2026-06-02T07:16:25+00:00

I am trying to crop a (non background) image then scale that cropped image

  • 0

I am trying to crop a (non background) image then scale that cropped image by a percentage of the body. The idea I have is to combine all logos and basic graphics on my website into one image so that the browser can cache the image (quicker after the fist download). I then want to scale relative to the body width so that my website will look the same ratio of the page width no matter what the user’s monitor size.

This may be easier if I give the html & css then explain it after:

<html>
<head>
    <style>
    body
    {
        padding: 0px;
        margin: 0px;
        width: 100%
    }
    #crop1
    {
        float: left;
        overflow: hidden;
        border: 1px solid red;
        clear: both;
    }
    #crop1 img
    {
        vertical-align: middle;
        margin: -28px 0px -88px -189px; /*top right bottom left*/
    }
    #scale1
    {
        width: 10%;
        border: 1px solid blue;
    }
    #scale1 img
    {
        vertical-align: middle;
        width: 100%;
    }
    #crop2
    {
        float: left;
        overflow: hidden;
        border: 1px solid green;
        width: 100%;
    }
    #crop2 img
    {
        vertical-align: middle;
        margin: -28px 0px -88px -189px; /*top right bottom left*/
    }
    #scale2
    {
        width: 10%;
        border: 1px solid orange;
        clear: both;
    }
    </style>
</head>
<body>
    <img src="http://www.mathleague.com/help/geometry/IMG00088.gif">
    <div id="scale1"><img src="http://www.mathleague.com/help/geometry/IMG00088.gif"></div>
    <div id="crop1"><img src="http://www.mathleague.com/help/geometry/IMG00088.gif"></div>
    <div id="scale2"><div id="crop2"><img src="http://www.mathleague.com/help/geometry/IMG00088.gif"></div></div>
</body>
</html>

I’ve used the image http://www.mathleague.com/help/geometry/IMG00088.gif in this example. I’m not going to use this image in my website, but the principle will be the same.

So first I just put in the original image, unchanged, to give a size reference while debugging:

<img src="http://www.mathleague.com/help/geometry/IMG00088.gif">

Scaling a separate image down to 10% of the page width works fine:

<div id="scale1">
    <img src="http://www.mathleague.com/help/geometry/IMG00088.gif">
</div>

And cropping the image down to show just the oval shape also works fine:

<div id="crop1">
    <img src="http://www.mathleague.com/help/geometry/IMG00088.gif">
</div>

But I cannot shrink just the oval down to 10% of the page width:

<div id="scale2">
    <div id="crop2">
        <img src="http://www.mathleague.com/help/geometry/IMG00088.gif">
    </div>
</div>

(This crops the oval down to the 10% width, instead of scaling it). Maybe I’m missing some simple css properties on this last line, or maybe I need to add more divs. I’m stuck.

Here is the example image:
Example image

note: the solution must be cross-browser compatible

  • 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-02T07:16:27+00:00Added an answer on June 2, 2026 at 7:16 am

    Updated with working example (margins needed to be percentage)

    To do it the way you are headed is going to be a bit more complex than you realize. For your final sizing, you need to readjust the img size based on the inverse of the percentage that the piece takes up on the whole. Then you have to take that and multiply it with the scaling to then multiply the offsets of your margins.

    EDIT The following code is far more exact, as I was able to check and correct my math, and calculate based off your easier image (knowing the size and offsets is critical). The new example gets far closer to correct sizing calculations. I’ve adjusted below to show the math. Come to find out, the calculation is “easier” than I thought, but what I partly failed to account for was that even the offsets top and bottom should be set off the original width of the image, since width is what is scaling the whole image.

    #scale1
    {
        width: 10%;
        padding: 0;
        margin: 0;
    }
    
    #crop1
    {
        overflow: hidden;
        border: 1px solid green;
        width: 100%;
        padding: 0;
        margin: 0;
    }
    
    /*Image: 300 W x 209 H
      Offsets: oT = 8, oR = 56, oB = 75, oL = 204
      Icon: 40 w x 126 h */
    
    #crop1 img
    {
        width: 750% /* 1 / (40 / 300) [inverse of icon width / image width] */;
        vertical-align: middle;
        /*using the offsets, each has a percentage calculated based solely off 
          the image width, then adjusted based off the width % of the img as 
          calculated above */
        margin: -20%    /* (8 / 300) x 7.5 [the 750%] = 100 x 8 / 40*/
                0       /* right margin seems unnecessary, but if found otherwise, the
                     calculation would be (56 /300) x 7.5 = 100 x 56 / 40*/
                -187.5% /* (75 /300) x 7.5  = 100 x 75 / 40*/
                -510%;  /* (204 / 300)  x 7.5  = 100 x 204 / 40*/
        padding: 0;
        border: 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to crop an image and then paste the cropped image into the
I'm currently trying to crop an image, and then save the new image. I
I am trying to crop an image from an url and then stretch the
I am trying to crop an image. I have found multiple ways to do
I'm simply trying to crop a JPEG image (no scaling) using PHP. Here is
I'm trying to develop image crop using JQuery. I use ajax to upload the
I am trying to reuse a framelayout that has an image and textview inside
I'm trying to crop an image from the media gallery. I'm able to access
I am trying to crop the image using JQuery Jcrop plugin with Java Stuff,
i am trying to crop a gif image using the libMagick.so library. ./convert --version

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.