Skip to content

Instantly share code, notes, and snippets.

@weishuaiwang
Created October 21, 2013 07:05
Show Gist options
  • Save weishuaiwang/7079725 to your computer and use it in GitHub Desktop.
Save weishuaiwang/7079725 to your computer and use it in GitHub Desktop.
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";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment