note 92597 added to function.imagejpeg

From: Date: Thu, 30 Jul 2009 22:16:33 +0000
Subject: note 92597 added to function.imagejpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-158932@lists.php.net to get a copy of this message
I wanted a function that could resize an image and store the resulting thumbnail in a variable so I could manually save it. Here is the function. I basically strung together two snippets, one from this website (I think) and one by MrCoder here: http://www.webdeveloper.com/forum/showthread.php?t=188298. <?php function resizeToVariable($sourceImage,$newHeight,$newWidth,$destImage) { list($width,$height) = getimagesize($image); $img = imagecreatefromjpeg($sourceImage); // create a new temporary image $tmp_img = imagecreatetruecolor($newHeight,$newWidth); // copy and resize old image into new image imagecopyresized( $tmp_img, $img, 0, 0, 0, 0,$newHeight,$newWidth, $width, $height ); // use output buffering to capture outputted image stream ob_start(); imagejpeg($tmp_img); $i = ob_get_clean(); // Save file $fp = fopen ($destImage,'w'); fwrite ($fp, $i); fclose ($fp); } ?> You can use this for all your image resizing tasks. I for some reason had a problem using imagejpeg to save the image directly. ---- Server IP: 64.71.164.2 Probable Submitter: 69.142.233.248 ---- Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php Edit -- https://master.php.net/note/edit/92597 Del: integrated -- https://master.php.net/note/delete/92597/integrated Del: useless -- https://master.php.net/note/delete/92597/useless Del: bad code -- https://master.php.net/note/delete/92597/bad+code Del: spam -- https://master.php.net/note/delete/92597/spam Del: non-english -- https://master.php.net/note/delete/92597/non-english Del: in docs -- https://master.php.net/note/delete/92597/in+docs Del: other reasons-- https://master.php.net/note/delete/92597 Reject -- https://master.php.net/note/reject/92597 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158932) next »