Skip to content

Instantly share code, notes, and snippets.

@rogersguedes
Last active March 28, 2016 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogersguedes/2fb549a9f808b235a7db to your computer and use it in GitHub Desktop.
Save rogersguedes/2fb549a9f808b235a7db to your computer and use it in GitHub Desktop.
Data URI’s can be useful for embedding images into HTML/CSS/JS to save on HTTP requests and consequently enhance your site loading time. The following function will create a Data URI based on $file for easier embedding.
<?php
//Original source: https://css-tricks.com/snippets/php/create-data-uris/
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