Alexhoward Posted June 18, 2008 Share Posted June 18, 2008 Hello guys, I've got this script from the PHP manual: <?php while($row = mysql_fetch_array($sub_results)) { $title = $row['title']; $image1 = $row['image1']; $fdesc = SUBSTR($row['fdesc'],0,400); $user = $row['username']; $ref = $row['ref']; $image = "$image1"; $size = getimagesize("$image"); $height = $size[1]; $width = $size[0]; if ($height > 100) { $height = 100; $percent = ($size[1] / $height); $width = ($size[0] / $percent); } else if ($width > 100) { $width = 100; $percent = ($size[0] / $width); $height = ($size[1] / $percent); } //echo "<img src\"image/path/image.jpg\" height=\"$height\" width=\"$width\" />"; ?> The top part is the end of my select query... Problem is it's not working as i hoped. What i'd like to do is fit whatever sized image into a 100 X 100 cell, so i just assumed take whatever length is bigger and make it 100, then the other dimension would just scale proportionally. However this is not what it's doing. Could any of you suggest how i change this...? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/110712-solved-dynamic-image-resize-width-height/ Share on other sites More sharing options...
Alexhoward Posted June 18, 2008 Author Share Posted June 18, 2008 Sussed! This'll do the job... <?php while($row = mysql_fetch_array($sub_results)) { $title = $row['title']; $image1 = $row['image1']; $fdesc = SUBSTR($row['fdesc'],0,400); $user = $row['username']; $ref = $row['ref']; $image = "$image1"; $size = getimagesize("$image"); $height = $size[1]; $width = $size[0]; if ($height > $width) { $height = 100; $percent = ($size[1] / $height); $width = ($size[0] / $percent); } else if ($width > $height) { $width = 100; $percent = ($size[0] / $width); $height = ($size[1] / $percent); } //echo "<img src\"image/path/image.jpg\" height=\"$height\" width=\"$width\" />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/110712-solved-dynamic-image-resize-width-height/#findComment-568014 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.