Created
November 27, 2013 16:36
-
-
Save joshbeckman/7678799 to your computer and use it in GitHub Desktop.
Base64 encode images for browser loading
This file contains hidden or 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 | |
$im = file_get_contents('<image url here>'); | |
$imdata = base64_encode($im); | |
?> | |
<img src="data:image/png;base64,<?php echo $imdata; ?>" /> | |
or | |
<img src="data:image/jpg;base64,<?php echo $imdata; ?>" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Combine this with a lazy-loading library like echo.js and you get deferred image rendering by the browser without any calls to external image servers.