Results 1 to 3 of 3

Math Help - Constrain images proportions.

  1. #1
    Newbie
    Joined
    Feb 2009
    From
    Yorkshire, England.
    Posts
    2

    Constrain images proportions.

    Say we have an image (760px*1100px), but we want to resize that image into a 300px*300px box. Just making the image 300px*300px would distort the image, so we have to 'constrain' it's proportions, but I am unsure on how to do this.

    My logic goes like this:

    • Find images largest dimension (this case: height = 1100px)
    • Find what percent 300 is of 1100px ((300 / 1100) * 100?)
    • ... here is where my logic ends.


    Any ideas? Is my math for working the percentage out correct? .. and would I then just apply this percentage to working out the smaller dimension?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member
    Joined
    Dec 2008
    Posts
    52
    1100/100 = 11, which is 1%

    so 300/11 = 27%

    If you resized the image so that both lengths were 27% of the original then it wouldn't look distorted, but it also wouldn't be 300x300, as 300 is only 27% of 1100. You can't have no distortion and 300x300, just one.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2009
    From
    Yorkshire, England.
    Posts
    2
    Quote Originally Posted by Bruce View Post
    1100/100 = 11, which is 1%

    so 300/11 = 27%

    If you resized the image so that both lengths were 27% of the original then it wouldn't look distorted, but it also wouldn't be 300x300, as 300 is only 27% of 1100. You can't have no distortion and 300x300, just one.
    Thanks. I wasn't saying I wanted it 300*300, but an image scaled to fit in there elegantly.

    Anyway, I've gotten it done.. I think. Is this correct:

    [PHP]

    // 1000 pixels wide
    $imageX = 1000;

    // 2000 pixels tall
    $imageY = 2000;

    // find the largest dimension
    $largest = ( $imageY > $imageX ) ? $imageY : $imageX;

    // your proportion
    $constrainTo = 300;

    $percent = floor(($constrainTo / $largest) * 100);

    $newImageY = ($imageY / 100) * $percent;
    $newImageX = ($imageX / 100) * $percent;

    [/PHP]
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 14
    Last Post: September 5th 2010, 12:40 PM
  2. 3D Rotation Rotational Constrain Equation
    Posted in the Geometry Forum
    Replies: 0
    Last Post: June 5th 2010, 08:13 AM
  3. Images of sets
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: August 26th 2009, 12:35 PM
  4. Homomorphic images of D3.
    Posted in the Advanced Algebra Forum
    Replies: 1
    Last Post: April 28th 2009, 04:55 PM
  5. images png beamer
    Posted in the LaTeX Help Forum
    Replies: 2
    Last Post: December 4th 2008, 11:44 PM

Search Tags


/mathhelpforum @mathhelpforum