Created
October 21, 2013 07:05
-
-
Save weishuaiwang/7079727 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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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