Created
June 30, 2011 18:07
-
-
Save nerdsrescueme/1056805 to your computer and use it in GitHub Desktop.
Data URI
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
<?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