public function QueryPath::dataURL in QueryPath 7.2
Same name and namespace in other branches
- 6 QueryPath/QueryPath.php \QueryPath::dataURL()
- 7.3 QueryPath/QueryPath.php \QueryPath::dataURL()
File
- QueryPath/
QueryPath.php, line 412
Class
Code
public function dataURL($attr, $data = NULL, $mime = 'application/octet-stream', $context = NULL) {
if (is_null($data)) {
$data = $this
->attr($attr);
if (empty($data) || is_array($data) || strpos($data, 'data:') !== 0) {
return;
}
$regex = '/^data:([a-zA-Z0-9]+)\\/([a-zA-Z0-9]+);base64,(.*)$/';
$matches = array();
preg_match($regex, $data, $matches);
if (!empty($matches)) {
$result = array(
'mime' => $matches[1] . '/' . $matches[2],
'data' => base64_decode($matches[3]),
);
return $result;
}
}
else {
$attVal = self::encodeDataURL($data, $mime, $context);
return $this
->attr($attr, $attVal);
}
}