These can be useful for embedding images into HTML/CSS/JS to save on HTTP requests, at the cost of maintainability. More information. There are online tools to do it, but if you want your own very simple utility, here’s some PHP to do it:
function data_uri($file, $mime) {
$contents=file_get_contents($file);
$base64=base64_encode($contents);
echo "data:$mime;base64,$base64";
}
Maybe this Gist helps, too.
@Rodney, Many thanks for the Gist link..
I don’t like the server-side way of doing this. I prefer a client-side solution. Here’s a much better solution. Just drag and drop the file, and it gives you a DATA URI.
http://iwantaneff.in/datauri
Enjoy!
Nice little snippet. Updated it to automatically get the right image type, without passing it as a parameter.
How do you go about in using this?
yaar,please step by step…