3 /////////////////////////////////////////////////////////////////
4 /// getID3() by James Heinrich <info@getid3.org> //
5 // available at https://github.com/JamesHeinrich/getID3 //
6 // or https://www.getid3.org //
7 // or http://getid3.sourceforge.net //
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
23 public function Analyze() {
24 $info = &$this->getid3
->info
;
26 $this->fseek($info['avdataoffset']);
28 $SVGheader = $this->fread(4096);
29 if (preg_match('#\<\?xml([^\>]+)\?\>#i', $SVGheader, $matches)) {
30 $info['svg']['xml']['raw'] = $matches;
32 if (preg_match('#\<\!DOCTYPE([^\>]+)\>#i', $SVGheader, $matches)) {
33 $info['svg']['doctype']['raw'] = $matches;
35 if (preg_match('#\<svg([^\>]+)\>#i', $SVGheader, $matches)) {
36 $info['svg']['svg']['raw'] = $matches;
38 if (isset($info['svg']['svg']['raw'])) {
40 $sections_to_fix = array('xml', 'doctype', 'svg');
41 foreach ($sections_to_fix as $section_to_fix) {
42 if (!isset($info['svg'][$section_to_fix])) {
45 $section_data = array();
46 while (preg_match('/ "([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
47 $section_data[] = $matches[1];
48 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
50 while (preg_match('/([^\s]+)="([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
51 $section_data[] = $matches[0];
52 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
54 $section_data = array_merge($section_data, preg_split('/[\s,]+/', $info['svg'][$section_to_fix]['raw'][1]));
55 foreach ($section_data as $keyvaluepair) {
56 $keyvaluepair = trim($keyvaluepair);
58 $keyvalueexploded = explode('=', $keyvaluepair);
59 $key = (isset($keyvalueexploded[0]) ?
$keyvalueexploded[0] : '');
60 $value = (isset($keyvalueexploded[1]) ?
$keyvalueexploded[1] : '');
61 $info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"');
66 $info['fileformat'] = 'svg';
67 $info['video']['dataformat'] = 'svg';
68 $info['video']['lossless'] = true;
69 //$info['video']['bits_per_sample'] = 24;
70 $info['video']['pixel_aspect_ratio'] = (float) 1;
72 if (!empty($info['svg']['svg']['sections']['width'])) {
73 $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']);
75 if (!empty($info['svg']['svg']['sections']['height'])) {
76 $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']);
78 if (!empty($info['svg']['svg']['sections']['version'])) {
79 $info['svg']['version'] = $info['svg']['svg']['sections']['version'];
81 if (!isset($info['svg']['version']) && isset($info['svg']['doctype']['sections'])) {
82 foreach ($info['svg']['doctype']['sections'] as $key => $value) {
83 if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) {
84 $info['svg']['version'] = $matches[1];
90 if (!empty($info['svg']['width'])) {
91 $info['video']['resolution_x'] = $info['svg']['width'];
93 if (!empty($info['svg']['height'])) {
94 $info['video']['resolution_y'] = $info['svg']['height'];
99 $this->error('Did not find expected <svg> tag');