note 86564 added to book.image

From: Date: Fri, 24 Oct 2008 01:02:58 +0000
Subject: note 86564 added to book.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-145674@lists.php.net to get a copy of this message
I have been looking to send the output from GD to a text string without proxying via a file or to a browser. I have come up with a solution. This code buffers the output between the ob_start() and ob_end() functions into ob_get_contents() See the example below <?php // Create a test source image for this example $im = imagecreatetruecolor(300, 50); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); // start buffering ob_start(); // output jpeg (or any other chosen) format & quality imagejpeg($im, NULL, 85); // capture output to string $contents = ob_get_contents(); // end capture ob_end_clean(); // be tidy; free up memory imagedestroy($im); // lastly (for the example) we are writing the string to a file $fh = fopen("./temp/img.jpg", "a+" ); fwrite( $fh, $contents ); fclose( $fh ); ?> Enjoy! Ashley ---- Server IP: 87.124.35.190 Probable Submitter: 81.96.165.219 ---- Manual Page -- http://www.php.net/manual/en/book.image.php Edit -- https://master.php.net/note/edit/86564 Del: integrated -- https://master.php.net/note/delete/86564/integrated Del: useless -- https://master.php.net/note/delete/86564/useless Del: bad code -- https://master.php.net/note/delete/86564/bad+code Del: spam -- https://master.php.net/note/delete/86564/spam Del: non-english -- https://master.php.net/note/delete/86564/non-english Del: in docs -- https://master.php.net/note/delete/86564/in+docs Del: other reasons-- https://master.php.net/note/delete/86564 Reject -- https://master.php.net/note/reject/86564 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145674) next »