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 /////////////////////////////////////////////////////////////////
17 if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
21 class getid3_svg
extends getid3_handler
26 public function Analyze() {
27 $info = &$this->getid3
->info
;
29 $this->fseek($info['avdataoffset']);
31 $SVGheader = $this->fread(4096);
32 if (preg_match('#\<\?xml([^\>]+)\?\>#i', $SVGheader, $matches)) {
33 $info['svg']['xml']['raw'] = $matches;
35 if (preg_match('#\<\!DOCTYPE([^\>]+)\>#i', $SVGheader, $matches)) {
36 $info['svg']['doctype']['raw'] = $matches;
38 if (preg_match('#\<svg([^\>]+)\>#i', $SVGheader, $matches)) {
39 $info['svg']['svg']['raw'] = $matches;
41 if (isset($info['svg']['svg']['raw'])) {
43 $sections_to_fix = array('xml', 'doctype', 'svg');
44 foreach ($sections_to_fix as $section_to_fix) {
45 if (!isset($info['svg'][$section_to_fix])) {
48 $section_data = array();
49 while (preg_match('/ "([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
50 $section_data[] = $matches[1];
51 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
53 while (preg_match('/([^\s]+)="([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
54 $section_data[] = $matches[0];
55 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
57 $section_data = array_merge($section_data, preg_split('/[\s,]+/', $info['svg'][$section_to_fix]['raw'][1]));
58 foreach ($section_data as $keyvaluepair) {
59 $keyvaluepair = trim($keyvaluepair);
61 $keyvalueexploded = explode('=', $keyvaluepair);
62 $key = (isset($keyvalueexploded[0]) ?
$keyvalueexploded[0] : '');
63 $value = (isset($keyvalueexploded[1]) ?
$keyvalueexploded[1] : '');
64 $info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"');
69 $info['fileformat'] = 'svg';
70 $info['video']['dataformat'] = 'svg';
71 $info['video']['lossless'] = true;
72 //$info['video']['bits_per_sample'] = 24;
73 $info['video']['pixel_aspect_ratio'] = (float) 1;
75 if (!empty($info['svg']['svg']['sections']['width'])) {
76 $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']);
78 if (!empty($info['svg']['svg']['sections']['height'])) {
79 $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']);
81 if (!empty($info['svg']['svg']['sections']['version'])) {
82 $info['svg']['version'] = $info['svg']['svg']['sections']['version'];
84 if (!isset($info['svg']['version']) && isset($info['svg']['doctype']['sections'])) {
85 foreach ($info['svg']['doctype']['sections'] as $key => $value) {
86 if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) {
87 $info['svg']['version'] = $matches[1];
93 if (!empty($info['svg']['width'])) {
94 $info['video']['resolution_x'] = $info['svg']['width'];
96 if (!empty($info['svg']['height'])) {
97 $info['video']['resolution_y'] = $info['svg']['height'];
102 $this->error('Did not find expected <svg> tag');