Skip to content

Instantly share code, notes, and snippets.

@joshbeckman
Created November 27, 2013 16:36
Show Gist options
  • Save joshbeckman/7678799 to your computer and use it in GitHub Desktop.
Save joshbeckman/7678799 to your computer and use it in GitHub Desktop.
Base64 encode images for browser loading
<?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; ?>" />
@joshbeckman
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment