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
https://forums.phpfreaks.com/topic/161569-calculate-new-height-after-width-resize/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.