Jump to content

resizing image proportianal


franknu

Recommended Posts

i want to resize an image propertional my only problem is that the width is getting to thin my problem will be my calculation any help please here is my code

<?php
$image = "images/image.jpg";
$size = getimagesize($image);
$height ="250";

$width = $size[0] / 100 * 250;

?>

i want the height to be 250 but the width to be proportinal to that.

 

the width is to thin right now

please help what should be the right calculation so it wouldnt like that distore

 

Link to comment
https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/
Share on other sites

well, that is not working and actually it is getting a error

 

Warning: getimagesize(images/image.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/townsfin/public_html/bizwebpage2.php on line 50

 

Warning: Division by zero in /home/townsfin/public_html/bizwebpage2.php on line 54

 

well i can see the file but it is to thin

 

No the error IS as follows

Warning: getimagesize(images/image.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/townsfin/public_html/bizwebpage2.php on line 50

 

Warning: Division by zero in /home/townsfin/public_html/bizwebpage2.php on line 54

 

SO, your the image

$image = "images/image.jpg";

doesn't exist.. thus no sizes are pulled from

$size = getimagesize($image);

read the error again.. you know it makes sense

what about this

if i did it correctly it should shrink the image to fit in a box of 250x250 (proportianal)

 

<?php
$image = "images/image.jpg";
$size = getimagesize($image);
$NewHW = 250;
if($size[0] > $size[1])
{
$height =$NewHW ;
$width = ((100/$size[0]) * $NewHW );
}else{
$width =$NewHW ;
$height = ((100/$size[1]) * $NewHW );
}
?>

 

just incase the height is too big and the width is ok

 

*untested

your setting both height and width the same

 

try this

 

<?php
$image = "/business_images/stuufloadtsd.jpg";
$size = getimagesize($image);
$NewHW = 250;
if($size[0] > $size[1])
{
$height =$NewHW ;
$width = ((100/$size[0]) * $NewHW );
}else{
$width =$NewHW ;
$height = ((100/$size[1]) * $NewHW );
}

echo "<img src='$image' width='$width' height='$height'>"
?>

 

or post  the code that set the image up (aka the part that prints <img scr= ......)

this is the new changes i made to the codes in order to be congruent to my codes



$image2 = "$Picture2";
$size = getimagesize($image2);
$NewHW2 = 250;
if($size[0] > $size[1])
{
$height2 =$NewHW2 ;
$width2 = ((100/$size[0]) * $NewHW2 );
}else{
$width2 =$NewHW2 ;
$height2 = ((100/$size[1]) * $NewHW2 );
}

 

 

code that display

$image2 = preg_replace('#^.*/public_html#', '', $row['Picture2']);
           echo "<img src='$image2' width='$width2' height='$height2'>";

 

 

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.