public static function dataStream($data, $type = NULL) { if ($type === NULL) { $type = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data); } return 'data:' . ($type ? "{$type};" : '') . 'base64,' . base64_encode($data); }