Created
July 4, 2015 22:15
-
-
Save Shaz3e/3079857c3316538d0448 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
Data URI’s can be useful for embedding images into HTML/CSS/JS to save on HTTP requests. The following function will create a Data URI based on $file for easier embedding. |
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 | |
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