note 48684 deleted from function.imagecreatefromjpeg by cece

From: Date: Tue, 04 Jan 2005 22:38:31 +0000
Subject: note 48684 deleted from function.imagecreatefromjpeg by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82723@lists.php.net to get a copy of this message
Note Submitter: Reason: useless example ---- Hi, here is my method for converting a folder full of jpg's to a specified thumnail size. some requirements that can be changed in the code are; folder structure should follow; -main folder |-code files |-"images" folder |-"thumbs" folder the file naming convention under the images folder should be -"images" folder |-001.JPG |-002.JPG |-003.JPG |-so on up to 999.JPG here is the code I use to create the thumbs into the "thumbs folder" note: to display the images youll need to write your own customized code. Whats good about this is just upload the pics to the images folder, run the code in the parent folder and all the thumbs will be created automatically in the thumbs folder... hope this helps someone... and im sure it can be optimized... *************************************8 <?php //count the number of files the passed folder function file_count($dir) { $count = 0; if (substr($dir, -1) != DIRECTORY_SEPARATOR) $dir .= DIRECTORY_SEPARATOR; if ($dirhwnd = opendir($dir)) { while(($file = readdir($dirhwnd)) !== false) { $path = $dir . $file; if (is_file($path)) ++$count; } } return $count; } //sets $images number of files in the passed folder $num_of_images=(file_count("images"))+1; for ($i=1 ; $i<$num_of_images ; $i++) { if ($i < 10) {$image = '00' . $i . '.JPG';} if (( $i > 9 ) && ( $i < 100 )) {$image = '0' . $i . '.JPG';} if ( $i > 99 ) {$image = $i . '.JPG';} $sourcePath = 'images/'; // Path of original image $sourceName = $image; // Name of original image $thumbPath = 'thumbs'; // Writeable thumb path $thumbName = 'TN_' . $sourceName; // thumbnail name $thumbWidth = 125; // Intended width of thumb $thumbHeight = 94; // Intended height of thimb // Beyond this point is simply code. $sourceImage = imagecreatefromjpeg("$sourcePath/$sourceName"); $sourceWidth = imagesx($sourceImage); $sourceHeight = imagesy($sourceImage); if ( $sourceHeight > $sourceWidth ) { $thumbWidth = 94; // Intended width of thumb $thumbHeight = 125; // Intended height of thimb } $targetImage = imagecreatetruecolor($thumbWidth,$thumbHeight); imagecopyresampled($targetImage,$sourceImage,0,0,0,0,$thumbWidth, $thumbHeight,imagesx($sourceImage),imagesy($sourceImage)); imagejpeg($targetImage, "$thumbPath/$thumbName"); $thumbPath1 = 'thumbs/'; echo "<img src='$thumbPath1$thumbName' alt=''>"; } ?> **************************

« previous php.notes (#82723) next »