Jump to content


Photo

image resize function an implementation


  • Please log in to reply
4 replies to this topic

#1 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 01 September 2006 - 05:14 PM

i have a function that resizes an image when it loads the page according to its ration(so it doesnt look all funny) I am having problems implementing this function and getting it to display, check out the function and where i am trying to use it. Please help.

where it is implemented...
echo "<TABLE border=0 id='gallery'>";
while (list($thumb) = mysql_fetch_row($res)) {
	$mysock = getimagesize($thumb);
	$resizethumb = imageResize($mysock[0],  $mysock[1], 150);
    if ($count % NUMCOLS == 0) echo "<TR>\n";  # new row

    echo "<td><img src='$resizethumb'></td><br>\n";
    $count++;

    if ($count % NUMCOLS == 0) echo "</TR>\n";  # end row
}



if ($count % NUMCOLS != 0) {
   while ($count++ % NUMCOLS) echo "<td>&nbsp;</td>";
   echo "</TR>\n";
}
echo "</TABLE>";

the function...
<?php 
function imageResize($width, $height, $target) { 

if ($width > $height) { 
$percentage = ($target / $width); 
} else { 
$percentage = ($target / $height); 
} 

//gets the new value and applies the percentage, then rounds the value 
$width = round($width * $percentage); 
$height = round($height * $percentage); 

return "width=\"$width\" height=\"$height\""; 
} 
?>
right now i am just getting the little X boxs where images are sapose to be. any ideas?

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 01 September 2006 - 05:33 PM

This line is NOT telling what image - it simply is giving the dimensions.
echo "<td><img src='$resizethumb'></td><br>\n";


try

echo "<td><img src=" . $whatevertheimagenameandpathare . $resizethumb ."></td>";

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 01 September 2006 - 05:35 PM

so how do i tell it both the image and the hieght and width??

#4 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 01 September 2006 - 05:36 PM

see my modified response ABOVE

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#5 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 01 September 2006 - 05:54 PM

thanks, got it, my image was there just needed to tweek that line a little. the image variable is $image in the example




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users