Jump to content

Calculate new height after width resize


drisate

Recommended Posts

Hey guys i am trying to resize a flash object but ia m having a hard time finding the logic to retrive the new height after the width resize.

 

                    $info = getimagesize("uploads/$categ_list[flash]");
                    if ($info[0] > "645") {
                        $w = "width='645'";
                        $dif = $info[0] - 645;
                        $height = $info[1] - $dif;
                        $h = "height='$height'";
                    }

 

This works for the width but not for the height. Any idea?

Link to comment
Share on other sites

I'm not understanding your logic.

 

If width > 645 then dif is width - 645 and height is height - dif?

 

What exactly are you trying to do, resize and maintain the aspect ratio?

 

$info[0] is width

$info[1] is height

 

Depending on what you are trying to do ie divide by 645 or subtract 645 etc..

 

So you had an image and you didn't want that image to be any more than 645 this would work..

 

if ($info[0] > 645) {
$newwidth = 645;
$ratio = $info[0] / $newwidth;                
$newheight = $info[0] / $ratio;
}

 

so assume width is 800 and height is 600

ratio is 800/645 which is roughly 1.24

then height is 600 / 1.24 which is 483

so newheight is 483 and you have your new image of 645 x 483

 

hope that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.