php: recreate and display an image from binary data

You can do this using a data URI in the image src attribute. The format is: data:[<MIME-type>][;charset=”<encoding>”][;base64],<data> This example is straight from the Wikipedia page on data URIs: <?php function data_uri($file, $mime) { $contents = file_get_contents($file); $base64 = base64_encode($contents); return (‘data:’ . $mime . ‘;base64,’ . $base64); } ?> <img src=”https://stackoverflow.com/questions/2070603/<?php echo data_uri(“elephant.png’,’image/png’); ?>” alt=”An … Read more

How can I save a base64-encoded image to disk?

I think you are converting the data a bit more than you need to. Once you create the buffer with the proper encoding, you just need to write the buffer to the file. var base64Data = req.rawBody.replace(/^data:image\/png;base64,/, “”); require(“fs”).writeFile(“out.png”, base64Data, ‘base64′, function(err) { console.log(err); }); new Buffer(…, ‘base64’) will convert the input string to a … Read more

Download binary file over HTTP

If you mean you see this as string in your browser, the mime type sent by your server to your client may be wrong. By default it is set to text/html. It should be something like application/x-binary or perhaps application/x-gzip Check what mime type is fetched by your client when you display the page and … Read more