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
https://forums.phpfreaks.com/topic/137868-quick-question-on-a-script-im-making/
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.