note 103787 added to function.imagepng
| From: | boukeversteegh at gmail dot com | Date: | Tue, 03 May 2011 21:41:19 +0000 |
| Subject: | note 103787 added to function.imagepng | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179387@lists.php.net to get a copy of this message | ||
If you care about speed, you probably already cache your generated images to a file. In that case,
DON'T use "createimagefrompng" and "imagepng" to output the image. Use
fpassthru instead. It is literally hundreds of times faster.
<?php
header("Content-Type: image/png");
# Generate cachefile for image, if it doesn't exist
if( !file_exists($cachefile) ) {
$im = generateimage(); # some code generates an image resource
imagepng($im, $cachefile); # store the image to cachefile
# don't output it like this:
/* imagepng($im);*/
imagedestroy($im);
}
$fp = fopen($cachefile, 'rb'); # stream the image directly from the cachefile
fpassthru($fp);
exit;
?>
I've tested it with a 5120x5120 (1.2Mb) image, that was cached on the harddisk. Using imagepng,
the transfer took 12 seconds. Using fpassthru, it took only 32ms!
----
Server IP: 91.199.167.223
Probable Submitter: 145.53.45.17
----
Manual Page -- http://www.php.net/manual/en/function.imagepng.php
Edit -- https://master.php.net/note/edit/103787
Del: integrated -- https://master.php.net/note/delete/103787/integrated
Del: useless -- https://master.php.net/note/delete/103787/useless
Del: bad code -- https://master.php.net/note/delete/103787/bad+code
Del: spam -- https://master.php.net/note/delete/103787/spam
Del: non-english -- https://master.php.net/note/delete/103787/non-english
Del: in docs -- https://master.php.net/note/delete/103787/in+docs
Del: other reasons-- https://master.php.net/note/delete/103787
Reject -- https://master.php.net/note/reject/103787
Search -- https://master.php.net/manage/user-notes.php