Skip to content

Instantly share code, notes, and snippets.

@exu
Created March 30, 2011 12:37
Show Gist options
  • Save exu/894315 to your computer and use it in GitHub Desktop.
Save exu/894315 to your computer and use it in GitHub Desktop.
Image to inline data script
#!/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