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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.