Created
December 14, 2013 20:30
-
-
Save alemohamad/7964530 to your computer and use it in GitHub Desktop.
Create Data URI's
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
<?php | |
// These can be useful for embedding images into HTML/CSS/JS | |
// to save on HTTP requests, at the cost of maintainability. | |
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