Skip to content

Instantly share code, notes, and snippets.

@nerdsrescueme
Created June 30, 2011 18:07
Show Gist options
  • Save nerdsrescueme/1056805 to your computer and use it in GitHub Desktop.
Save nerdsrescueme/1056805 to your computer and use it in GitHub Desktop.
Data URI
<?php
public static function data_uri($data, $mime)
{
return 'data:'.$mime.';base64,'.base64_encode($data);
}
public static function data_img($filename)
{
if ( ! static::find_file($filename, static::$_folders['img']))
{
throw new \Fuel_Exception('Could not find asset: '.$filename);
}
$info = getimagesize($file);
return static::data_uri(file_get_contents($filename), image_type_to_mime_type($info[2]));
}
public static function data_css($data)
{
if ($file = static::find_file($data, static::$_folders['img']))
{
$data = file_get_contents($file);
}
return static::data_uri($data, 'text/css');
}
public static function data_js($data)
{
if ($file = static::find_file($filename, static::$_folders['img']))
{
$data = file_get_contents($file);
}
return static::data_uri($data, 'text/javascript');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment