Created
January 31, 2012 19:33
-
-
Save fabioluciano/1712434 to your computer and use it in GitHub Desktop.
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 | |
final class DataUri { | |
protected $file; | |
public function __construct($file) { | |
$this->file = $file; | |
return $this; | |
} | |
public function generate() { | |
if (file_exists($this->file)) { | |
return $this->make_uri(); | |
} else { | |
return false; | |
} | |
} | |
private function make_uri() { | |
return 'data:' | |
. $this->get_mime() | |
. ';base64,' | |
. base64_encode(file_get_contents($this->file)); | |
} | |
private function get_mime() { | |
$info = new finfo(FILEINFO_MIME); | |
return $info->file($this->file); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment