Jump to content

Archived

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

jpratt

image resize function an implementation

Recommended Posts

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...
[code]
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>";
[/code]

the function...
[code]
<?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\"";
}
?>
[/code]
right now i am just getting the little X boxs where images are sapose to be. any ideas?

Share this post


Link to post
Share on other sites
This line is NOT telling what image - it simply is giving the dimensions.
[code]
echo "<td><img src='$resizethumb'></td><br>\n";
[/code]


try

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

Share this post


Link to post
Share on other sites
thanks, got it, my image was there just needed to tweek that line a little. the image variable is $image in the example

Share this post


Link to post
Share on other sites

×

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.