Created
July 26, 2013 04:38
-
-
Save emersonbroga/6086286 to your computer and use it in GitHub Desktop.
Generates a base64 image constant from an image folder.
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 | |
| // path to image folder | |
| $folder = dirname(__FILE__); | |
| foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder)) as $filename) | |
| { | |
| // check if is not file | |
| if(!is_file($filename)) | |
| continue; | |
| // get file information | |
| $path_info = pathinfo($filename); | |
| // get file contents | |
| $image = file_get_contents($filename); | |
| // get file base64 | |
| $imdata = base64_encode($image); | |
| // create a base64 image string | |
| $base64 = sprintf('data:image/%s;base64,%s',$path_info['extension'], $imdata ); | |
| // create a uppercase file name to generate the php constant | |
| $filename = 'IMG_'.strtoupper($path_info['filename']); | |
| // print the php constant | |
| printf('defined(\'%s\') || defined(\'%s\', \'%s\'); <br/><br/>', $filename, $filename, $base64); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment