e4502aaeaee4ae26280182fcd085e680870a871a
2 /////////////////////////////////////////////////////////////////
3 /// getID3() by James Heinrich <info@getid3.org> //
4 // available at http://getid3.sourceforge.net //
5 // or http://www.getid3.org //
6 // also https://github.com/JamesHeinrich/getID3 //
7 /////////////////////////////////////////////////////////////////
8 // See readme.txt for more details //
9 /////////////////////////////////////////////////////////////////
11 // module.graphic.svg.php //
12 // module for analyzing SVG Image files //
13 // dependencies: NONE //
15 /////////////////////////////////////////////////////////////////
18 class getid3_svg
extends getid3_handler
22 public function Analyze() {
23 $info = &$this->getid3
->info
;
25 $this->fseek($info['avdataoffset']);
27 $SVGheader = $this->fread(4096);
28 if (preg_match('#\<\?xml([^\>]+)\?\>#i', $SVGheader, $matches)) {
29 $info['svg']['xml']['raw'] = $matches;
31 if (preg_match('#\<\!DOCTYPE([^\>]+)\>#i', $SVGheader, $matches)) {
32 $info['svg']['doctype']['raw'] = $matches;
34 if (preg_match('#\<svg([^\>]+)\>#i', $SVGheader, $matches)) {
35 $info['svg']['svg']['raw'] = $matches;
37 if (isset($info['svg']['svg']['raw'])) {
39 $sections_to_fix = array('xml', 'doctype', 'svg');
40 foreach ($sections_to_fix as $section_to_fix) {
41 if (!isset($info['svg'][$section_to_fix])) {
44 $section_data = array();
45 while (preg_match('/ "([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
46 $section_data[] = $matches[1];
47 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
49 while (preg_match('/([^\s]+)="([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
50 $section_data[] = $matches[0];
51 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
53 $section_data = array_merge($section_data, preg_split('/[\s,]+/', $info['svg'][$section_to_fix]['raw'][1]));
54 foreach ($section_data as $keyvaluepair) {
55 $keyvaluepair = trim($keyvaluepair);
57 $keyvalueexploded = explode('=', $keyvaluepair);
58 $key = (isset($keyvalueexploded[0]) ?
$keyvalueexploded[0] : '');
59 $value = (isset($keyvalueexploded[1]) ?
$keyvalueexploded[1] : '');
60 $info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"');
65 $info['fileformat'] = 'svg';
66 $info['video']['dataformat'] = 'svg';
67 $info['video']['lossless'] = true;
68 //$info['video']['bits_per_sample'] = 24;
69 $info['video']['pixel_aspect_ratio'] = (float) 1;
71 if (!empty($info['svg']['svg']['sections']['width'])) {
72 $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']);
74 if (!empty($info['svg']['svg']['sections']['height'])) {
75 $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']);
77 if (!empty($info['svg']['svg']['sections']['version'])) {
78 $info['svg']['version'] = $info['svg']['svg']['sections']['version'];
80 if (!isset($info['svg']['version']) && isset($info['svg']['doctype']['sections'])) {
81 foreach ($info['svg']['doctype']['sections'] as $key => $value) {
82 if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) {
83 $info['svg']['version'] = $matches[1];
89 if (!empty($info['svg']['width'])) {
90 $info['video']['resolution_x'] = $info['svg']['width'];
92 if (!empty($info['svg']['height'])) {
93 $info['video']['resolution_y'] = $info['svg']['height'];
98 $this->error('Did not find expected <svg> tag');