note 29778 added to function.imagejpeg
| From: | jt at tsw dot org dot uk | Date: | Tue, 25 Feb 2003 01:39:17 +0000 |
| Subject: | note 29778 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44465@lists.php.net to get a copy of this message | ||
I've just read all this AFTER solving the problem in my own little way. (this is re dumping the
image into a string)
Im not actually saving the file to a database, but I'm passing it over XML:RPC so I have the
constraint that I cant just dump it to browser, and also its not binary safe.. my solution does not
involve ob_start(); which might arguably be the more elgant solution. I didnt see my solution
listed, so I thought I aught to post it to add to the wealth of knowledge:
[apologies if this is incorrect, im snipping from a large bit of irrelevent XML:RPC catching stuff]
$tmpfname = tempnam ("/tmp", "FOO"); // Generate the temp file
Imagejpeg($im,$tmpfname); // save me image to the file
$temp = fopen($tmpfname,"rb"); // <- Open the file for reading binary
$buffer = fread($temp,filesize($tmpfname)); // get that data into the buffer
fclose($temp); // close the file
unlink($tmpfname); // finished with the file, discard
$out = base64_encode($buffer); // encode it (not nessicary if you are using some
kind of binary safe function with the info)
and of course on the other end of whatever your doing,
[ some function to get $in ]
header("Content-type: image/jpeg");
$in = base64_decode($buffer); // get the binary data back
echo $in;
This should work with things like Imagepng
Hope that helps anyone out.
--
http://www.php.net/manual/en/function.imagejpeg.php
http://master.php.net/manage/user-notes.php?action=edit+29778
http://master.php.net/manage/user-notes.php?action=delete+29778
http://master.php.net/manage/user-notes.php?action=reject+29778