Created
March 30, 2011 12:37
-
-
Save exu/894315 to your computer and use it in GitHub Desktop.
Image to inline data script
This file contains 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
#!/usr/bin/env php | |
<?php | |
function data_uri($file, $mime) | |
{ | |
$contents = file_get_contents($file); | |
$base64 = base64_encode($contents); | |
return ('data:' . $mime . ';base64,' . $base64); | |
} | |
$url = $mime = false; | |
if(isset($argv[1])) { | |
$url = $argv[1]; | |
} | |
if(isset($argv[2])) { | |
$mime = $argv[2]; | |
} | |
if(!$url) die('gimme url sucker!'); | |
if(!$mime) $mime = 'image/png'; | |
echo data_uri($url, $mime)."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment