Jump to content

problems with thumbnails


lapsinja

Recommended Posts

Hey. I have 2 problems with thumbnails. Hope you could help to solve at least one of them  wink.gif

1.I have made a form on my website where the user can upload image and add some extra information. So I made thumbnails for uploaded images that are stored in folder (they're stored in the database as well, but these thumbnails are linked with the folder not database) and when I click on the thumbnail I want it to show the big image and some data from database that was added when the user uploaded the image (like- name and date). Now when I click on a thumbnail it shows me all the data that's in the database- including other images as well. How to link a thumbnail that is made in folder with data from database? (thumbnails and original images have exact the same name).

2. I used this script to create thumbnails, but it is only for .jpg images. What should I add to allow .png , .jpeg and .gif extensions as well?

/** settings **/
$images_dir = 'images/';
$thumbs_dir = 'images_thumbs/';
$thumbs_width = 200;
$images_per_row = 3;






/* function:  generates thumbnail */
function make_thumb($src,$dest,$desired_width) {
	/* read the source image */
	$source_image = imagecreatefromjpeg($src);
	$width = imagesx($source_image);
	$height = imagesy($source_image);
	/* find the "desired height" of this thumbnail, relative to the desired width  */
	$desired_height = floor($height*($desired_width/$width));
	/* create a new, "virtual" image */
	$virtual_image = imagecreatetruecolor($desired_width,$desired_height);
	/* copy source image at a resized size */
	imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
	/* create the physical thumbnail image to its destination */

}

/* function:  returns files from dir */
function get_files($images_dir,$exts = array('jpg')) {
	$files = array();
	if($handle = opendir($images_dir)) {
		while(false !== ($file = readdir($handle))) {
			$extension = strtolower(get_file_extension($file));
			if($extension && in_array($extension,$exts)) {
				$files[] = $file;
			}
		}
		closedir($handle);
	}
	return $files;
}

/* function:  returns a file's extension */
function get_file_extension($file_name) {
	return substr(strrchr($file_name,'.'),1);
}



/** generate photo gallery **/
$image_files = get_files($images_dir);
if(count($image_files)) {
	$index = 0;
	foreach($image_files as $index=>$file) {
		$index++;
		$thumbnail_image = $thumbs_dir.$file;
		if(!file_exists($thumbnail_image)) {
			$extension = get_file_extension($thumbnail_image);
			if($extension) {
				make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
			}
		}
		echo '<a href="',$images_dir.$file,'"><img src="',$thumbnail_image,'" /></a>';
	}
}
else {
	echo '<p>There are no images in this gallery.</p>';
}

Really waiting for some answers. Thanks!!! :)

Link to comment
Share on other sites

Yes, I tried to add other extensions like :

 function get_files($images_dir,$exts = array('jpg', 'gif' ,'png'))

but that is not working.  :-\

 

what else should I add to this code to allow upload other file types?

Edited by lapsinja
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.