Skip to content

Instantly share code, notes, and snippets.

@roelven
Created September 29, 2010 13:44
Show Gist options
  • Save roelven/602761 to your computer and use it in GitHub Desktop.
Save roelven/602761 to your computer and use it in GitHub Desktop.
DataURIze all images in a dir with PHP
<?php
/*
- Check folder images for available images files (I used gif only in this case)
- Loop through all images and render them inline in HTML, using dataURI's with Base64 encoding through PHP
- View the output in your browser to get the encoded strings
*/
$path = 'images/';
$handle = opendir($path);
while (($file = readdir($handle)) != false) {
if(strlen($file) > 3) {
print '<img src="data:image/gif;base64,'.base64_encode(file_get_contents($path.$file)).'"> <br />'."\n";
}
}
closedir($handle);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment