Jump to content

Quick question on a script Im making


blah19

Recommended Posts

Hey! I am working on a script(I'm fairly new, and self taught so it may seem sloppy or inefficient) listed below. In a nutshell, this script creates thumbnails and links them to the larger files. This is just the shell and I plan to expand it a lot, but my main concern is right now my script creates the thumbnail whether it exists or not. I've done some looking around but I can't figure out how to make this script ONLY create a thumbnail if the thumbnail file does not exist already. Any Ideas?

function thumbIt($filename,$percent,$prename,$setWidth,$setHeight)
	{
	$newdir='slideImages/thumbs/';//Dircetory to store new pic
	//$prename='t_';//name for creating thumbnails
	$thumbQ=80;//Quality for saving pic
	$filenameT=$filename;
	$filename='slideImages/'.$filename;
	//======================
	//Debugging Hard Vars
	//$filename='lime.jpg';
	//$percent=.3;
	//======================
	// Content type
	//header('Content-type: image/jpeg');

	// Get new sizes
	list($width, $height) = getimagesize($filename);

	if($percent!=0)
		{
		$newwidth = $width * $percent;
		$newheight = $height * $percent;
		}

		else
		{
		$newwidth = $setWidth;
		$newheight = $setHeight;
		}

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

//Save Image
$thumbPath=$newdir.$prename.$filenameT; //consolidate for output

imagejpeg($thumb, $thumbPath);
// Output

//echo($thumbPath);
return($thumbPath);

}

basically I pull all the files from a folder and put them into an array, from the array I send them to HTML via echo. I'll post the entire page it you need it.

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.