note 12994 deleted from ref.image by didou

From: Date: Sun, 07 Dec 2003 02:19:49 +0000
Subject: note 12994 deleted from ref.image by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-61506@lists.php.net to get a copy of this message
Note Submitter: icecube@fr.fm ---- Improved version of ResizeGif given by tjhunter with Height % Widht. <?php /* ResizeGif with (height % width) */ function RatioResizeImg( $image, $newWidth, $newHeight){ //Open the gif file to resize eregi(".(.*)$",$image,$regs); switch($regs[1]){ case "gif": $srcImage = ImageCreateFromGIF( $image ); break; case "jpg": $srcImage = ImageCreateFromJPEG( $image ); break; case "png": $srcImage = ImageCreateFromPNG( $image ); break; default: $srcImage = ImageCreateFromGIF( $image ); break;} //obtain the original image Height and Width $srcWidth = ImageSX( $srcImage ); $srcHeight = ImageSY( $srcImage ); // the follwing portion of code checks to see if // the width > height or if width < height // if so it adjust accordingly to make sure the image // stays smaller then the $newWidth and $newHeight $ratioWidth = $srcWidth/$newWidth; $ratioHeight = $srcHeight/$newHeight; if( $ratioWidth < $ratioHeight){ $destWidth = $srcWidth/$ratioHeight; $destHeight = $newHeight; }else{ $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } // creating the destination image with the new Width and Height $destImage = imagecreate( $destWidth, $destHeight); //copy the srcImage to the destImage ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight ); //create the gif ImageGif( $destImage ); //fre the memory used for the images ImageDestroy( $srcImage ); ImageDestroy( $destImage ); } //save output to a buffer ob_start(); //Resize image ( will be stored in the buffer ) ResizeGif( "/where/image/is/image.gif", "150", "150"); //copy output buffer to string $resizedImage = ob_get_contents(); //clear output buffer that was saved ob_end_clean(); //write $resizedImage to Database, file , echo to browser whatever you need to do with it ?>

« previous php.notes (#61506) next »