Skip to content

Instantly share code, notes, and snippets.

@fabioluciano
Created January 31, 2012 19:33
Show Gist options
  • Save fabioluciano/1712434 to your computer and use it in GitHub Desktop.
Save fabioluciano/1712434 to your computer and use it in GitHub Desktop.
<?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