note 69702 modified in ref.outcontrol by danbrown

From: Date: Fri, 25 Feb 2011 14:55:18 +0000
Subject: note 69702 modified in ref.outcontrol by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177332@lists.php.net to get a copy of this message
Unfortunately, the PHP guys didn't build support into any of the image output functions to return the image instead of outputting it. Fortunately, we have output buffering to fix that. <?php $im = imagecreatetruecolor(200, 200); // Other image functions here... ob_start(); imagepng($im); $imageData = ob_get_contents(); ob_clean(); ?> You can now use the $imageData variable to either create another GD image, save it, put it in a database, make modifications to the binary, or output it to the user. You can easily check the size of it as well without having to access the disk...just use strlen(); --was-- Unfortunately, the PHP guys didn't build support into any of the image output functions to return the image instead of outputting it. Fortunately, we have output buffering to fix that. <? $im = imagecreatetruecolor(200, 200); // Other image functions here... ob_start(); imagepng($im); $imageData = ob_get_contents(); ob_clean(); ?> You can now use the $imageData variable to either create another GD image, save it, put it in a database, make modifications to the binary, or output it to the user. You can easily check the size of it as well without having to access the disk...just use strlen(); http://php.net/manual/en/ref.outcontrol.php

« previous php.notes (#177332) next »