Jump to content

php pros, help me with thumbnail display


prakash911

Recommended Posts

here is my code to generate and display thumbnail

 

function createthumbnail($name,$filename,$width,$height)
{
  $system = explode('.',$name);

  if (preg_match('/jpg|jpeg/',$system[1]))
  {
$image = imagecreatefromjpeg($name);
  }
  if (preg_match('/png/',$system[1]))
  {
$image = imagecreatefrompng($name);
  }

  $x = imageSX($image);
  $y = imageSY($image);

  if ($x > $y) 
  {
$thumb_w= $width;
$thumb_h= $y*($height/$x);
  }

  if ($x < $y) 
  {
$thumb_w= $x*($width/$y);
$thumb_h= $height;
  }

  if ($x == $y) 
  {
$thumb_w = $width;
$thumb_h = $height;
  }

  $dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
  imagecopyresampled($dst_img,$image,0,0,0,0,$thumb_w,$thumb_h,$x,$y);

  if (preg_match("/png/",$system[1]))
  {
imagepng($dst_img,$filename); 
  } else {
imagejpeg($dst_img,$filename); 
  }

  imagedestroy($dst_img); 
  imagedestroy($image); 
}

 

while ($row = mysql_fetch_assoc($result))
   {
      print "<tr>\n";
      foreach ($row as $col_value)
      {
         print "<tb>";
         createthumbnail('pics/beautifulWebDesign.jpg','pics/beautifulWebDesign.jpg',100,100);
         print "</tb>\n";
         $col_value = htmlspecialchars(stripslashes($col_value));
         print "<td>$col_value</td>\n";
      }

      $isbn = $row['isbn'];
?>
  
      <form action="<?php echo $self?>" method="POST">
      <td>
      <input type="hidden" name="isbn" value="<?php echo $isbn?>">
      <input type="text" name="quantity" value="1" size="2">
      <input type="submit" name="add" value="add">
      </td>
      </form>
<?php
   }
?>

 

i want the image to be displayed in the pictures column down all the rows, but when i run it i get this. no image is being displayed and i am not even getting any error messages.

 

thumbnail.jpg

Link to comment
https://forums.phpfreaks.com/topic/195623-php-pros-help-me-with-thumbnail-display/
Share on other sites

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.