Jump to content

[SOLVED] can I make my thumbnails links??


php_beginner_83

Recommended Posts

Hi Everyone

 

I'm trying to create thumbnails, using the gd library, on the fly.  I was wondering if it will be possible to have these thumbnails be links.  I'm not sure if this can be done or should I just create and save the thumbnails.  I know this way I'd be able to make them links.

 

This is my code ...

 

$filename = 'images/alcatraz1.jpg';
$thumbWidth = 50;
$thumbHeight = 50;

// load image
$img = imagecreatefromjpeg($filename);

// get image size
$width = imagesx($img);
$height = imagesy($img);

// set size of thumbnails
if ($width > $height)
{
$newWidth = $thumbWidth;
$newHeight = $thumbWidth * ($height/$width);
}
else
{
$newWidth = $thumbHeight * ($width/$height);
$newHeight = $thumbHeight;
}

// create temporary image
$tempImg = imagecreatetruecolor($newWidth, $newHeight);

// create the thumbnail
imagecopyresampled($tempImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

// output thumbnail
imagejpeg($tempImg)

Link to comment
Share on other sites

By on the fly I assume you mean something like:

 

<img src="thumb.php?image=something.jpg&width=100&height=100" alt="" />

 

? If so, and you wanted to link them to the original image you could just do:

 

<a href="something.jpg"><img src="thumb.php?image=something.jpg&width=100&height=100" alt="" /></a>

Link to comment
Share on other sites

I'm trying to loop through an array of images and am having problems getting it to work...any ideas?

 

Thanks

 

While (...........)

$currentImage = "images//" . substr(strrchr($row['Path'],92),1);

   $counter++;
   
   if ($counter % 3 == 0)
   {
   		
	  echo '<a href=#><img src="shannaThumb.php?image=\"$currentImage\"" alt="" /></a><br/>';
   }
   else
   {
	  echo '<a href=#><img src="shannaThumb.php?image=\"$currentImage\"" alt="" /></a>';

   }

Link to comment
Share on other sites

It would be nice if you were a little more specific, and if you showed us the array of images, would be easier for us to tell you how to set it up.

 

Right away though, I see this:

 

$currentImage = "images//" . substr(strrchr($row['Path'],92),1);

Is that supposed to be images/ with only 1 '/'?

Link to comment
Share on other sites

I've had to use 2 '/' in other code because 1 didnt work so I figured I would do the same here but I have tried removing one and the code still didnt work.

 

My array of images comes from a database of images.  This is my code

I'm trying to take each image from the database and create a thumbnail and then have each thumbnail be a link.

 

Thanks for the help.

 

$result = mysql_query("SELECT * FROM pictures 
INNER JOIN pics_in_albums 
ON pictures.ID = pics_in_albums.PicID 
INNER JOIN albums 
ON pics_in_albums.AlbumID = albums.ID 
WHERE albums.ID = 1") or die(mysql_error());

$paths = array();

$counter = 0;
//fetch tha data from the database
while ($row = mysql_fetch_assoc($result)) 
{

$currentImage = "images//" . substr(strrchr($row['Path'],92),1);

   $counter++;
   
   if ($counter % 3 == 0)
   {
	  echo '<a href=#><img src="shannaThumb.php?image=$currentImage alt="" /></a><br/>';
   }
   else
   {
	  echo '<a href=#><img src="shannaThumb.php?image=$currentImage" alt="" /></a>';

   }
   
}
?>

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.