note 29778 deleted from function.imagejpeg by cmb
| From: | cmb@php.net | Date: | Sun, 02 Oct 2016 07:55:45 +0000 |
| Subject: | note 29778 deleted from function.imagejpeg by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206722@lists.php.net to get a copy of this message | ||
Note Submitter: jt at tsw dot org dot uk
----
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.