franknu Posted May 6, 2007 Share Posted May 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/ Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 try <?php $image = "images/image.jpg"; $size = getimagesize($image); $NewH = 250; $height =$NewH; $width = ((100/$size[0]) * $NewH); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246691 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246694 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 check the link to the image No such file or directory in /home/townsfin/public_html/bizwebpage2.php on line 50 Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246695 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 this is the link on the source <img src='/business_images/stuufloadtsd.jpg' width='0' height='250'> Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246701 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 this is the link on the source <img src='/business_images/stuufloadtsd.jpg' width='0' height='250'> what!!.. thats makes no sense! Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246703 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 it seems tha the calculation is equal to "zero". it seem that is the reason Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246705 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246708 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 ok, i fixed it, you were right, but now i dont like how it looks i will see what i can do Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246719 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246726 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 ok, i just dont like how it looks maybe i am doing something wrong here is the link top pictures id the one it looks disturb http://www.townsfinder.com/bizwebpage2.php?BusinessName=Punto%20Final%20Night%20Club Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246731 Share on other sites More sharing options...
MadTechie Posted May 6, 2007 Share Posted May 6, 2007 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= ......) Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246738 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 samething, i dont know, <img src='/business_images/featured.jpg' width='250' height='109.17030567686'> that is my display on the source Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246777 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 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'>"; Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246782 Share on other sites More sharing options...
franknu Posted May 6, 2007 Author Share Posted May 6, 2007 all i need now is not to make it look distore Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246790 Share on other sites More sharing options...
Psycho Posted May 6, 2007 Share Posted May 6, 2007 This will resize the image to the desired width while keeping the scale proportional: <?php $image = "images/image.jpg"; $size = getimagesize($image); $scale = $size[0]/$size[1]; // width/height $width = 250; $height = $width * $scale; ?> Quote Link to comment https://forums.phpfreaks.com/topic/50256-resizing-image-proportianal/#findComment-246830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.