note 68194 added to function.imagejpeg

From: Date: Mon, 17 Jul 2006 21:44:32 +0000
Subject: note 68194 added to function.imagejpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-114860@lists.php.net to get a copy of this message
function create_thumbnail( $source_file, $destination_file, $max_dimension) { list($img_width,$img_height) = getimagesize($source_file); // Get the original dimentions $aspect_ratio = $img_width / $img_height; if ( ($img_width > $max_dimension) || ($img_height > $max_dimension) ) // If either dimension is too big... { if ( $img_width > $img_height ) // For wide images... { $new_width = $max_dimension; $new_height = $new_width / $aspect_ratio; } elseif ( $img_width < $img_height ) // For tall images... { $new_height = $max_dimension; $new_width = $new_height * $aspect_ratio; } elseif ( $img_width == $img_height ) // For square images... { $new_width = $max_dimension; $new_height = $max_dimension; } else { echo "Error reading image size."; return FALSE; } } else { $new_width = $img_width; $new_height = $img_height; } // If it's already smaller, don't change the size. // Make sure these are integers. $new_width = intval($new_width); $new_height = intval($new_height); $thumbnail = imagecreatetruecolor($new_width,$new_height); // Creates a new image in memory. // The following block retrieves the source file. It assumes the filename extensions match the file's format. if ( strpos($source_file,".gif") ) { $img_source = imagecreatefromgif($source_file); } if ( (strpos($source_file,".jpg")) || (strpos($source_file,".jpeg")) ) { $img_source = imagecreatefromjpeg($source_file); } if ( strpos($source_file,".bmp") ) { $img_source = imagecreatefromwbmp($source_file); } if ( strpos($source_file,".png") ) { $img_source = imagecreatefrompng($source_file); } // Here we resample and create the new jpeg. imagecopyresampled($thumbnail, $img_source, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height); imagejpeg( $thumbnail, $destination_file, 100 ); // Finally, we destroy the two images in memory. imagedestroy($img_source); imagedestroy($thumbnail); } ---- Server IP: 216.194.113.175 Probable Submitter: 128.151.231.224 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php Edit -- http://master.php.net/note/edit/68194 Del: integrated -- http://master.php.net/note/delete/68194/integrated Del: useless -- http://master.php.net/note/delete/68194/useless Del: bad code -- http://master.php.net/note/delete/68194/bad+code Del: spam -- http://master.php.net/note/delete/68194/spam Del: non-english -- http://master.php.net/note/delete/68194/non-english Del: in docs -- http://master.php.net/note/delete/68194/in+docs Del: other reasons-- http://master.php.net/note/delete/68194 Reject -- http://master.php.net/note/reject/68194 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114860) next »