note 11786 deleted from ref.image by tularis

From: Date: Sun, 29 Jun 2008 21:13:34 +0000
Subject: note 11786 deleted from ref.image by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140986@lists.php.net to get a copy of this message
Note Submitter: ---- When using ImageGif( $im ) it sends the output directly to the browser. to prevent this from happening and also to be able to save your new image to a database for example use ob_start(), ob_get_contents(), and ob_end_clean() <BR><BR>ex:<BR> <?php <BR>function ResizeGif( $image, $newWidth, $newHeight){ //Open the gif file to resize $srcImage = ImageCreateFromGif( $image ); //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 if( $srcWidth < $srcHeight ){ $destWidth = $newWidth * $srcWidth/$srcHeight; $destHeight = $newHeight; }else{ $destWidth = $newWidth; $destHeight = $newHeight * $srcHeight/$srcWidth; } // 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<BR><BR>Also do not put Header() between ob_start and ob_end_clean() because they will still be sent. $resizedImage is the resized image had there been no ob function calls ResizeGif() would have sent the output to the browser.I hope this helps some people with databases that want to store there image <BR><BR>Dave

« previous php.notes (#140986) next »