ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Svg.php
Go to the documentation of this file.
1<?php
2
4
6
9// available at http://getid3.sourceforge.net //
10// or http://www.getid3.org //
12// See readme.txt for more details //
14// //
15// module.graphic.svg.php //
16// module for analyzing SVG Image files //
17// dependencies: NONE //
18// ///
20
28class Svg extends BaseHandler
29{
34 public function analyze()
35 {
36 $info = &$this->getid3->info;
37
38 fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
39
40 $SVGheader = fread($this->getid3->fp, 4096);
41 if (preg_match('#<\?xml([^>]+)\?>#i', $SVGheader, $matches)) {
42 $info['svg']['xml']['raw'] = $matches;
43 }
44 if (preg_match('#<\!DOCTYPE([^>]+)>#i', $SVGheader, $matches)) {
45 $info['svg']['doctype']['raw'] = $matches;
46 }
47 if (preg_match('#<svg([^>]+)>#i', $SVGheader, $matches)) {
48 $info['svg']['svg']['raw'] = $matches;
49 }
50 if (isset($info['svg']['svg']['raw'])) {
51
52 $sections_to_fix = array('xml', 'doctype', 'svg');
53 foreach ($sections_to_fix as $section_to_fix) {
54 if (!isset($info['svg'][$section_to_fix])) {
55 continue;
56 }
57 $section_data = array();
58 while (preg_match('/ "([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
59 $section_data[] = $matches[1];
60 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
61 }
62 while (preg_match('/([^\s]+)="([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) {
63 $section_data[] = $matches[0];
64 $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]);
65 }
66 $section_data = array_merge($section_data, preg_split('/[\s,]+/', $info['svg'][$section_to_fix]['raw'][1]));
67 foreach ($section_data as $keyvaluepair) {
68 $keyvaluepair = trim($keyvaluepair);
69 if ($keyvaluepair) {
70 $keyvalueexploded = explode('=', $keyvaluepair);
71 $key = (isset($keyvalueexploded[0]) ? $keyvalueexploded[0] : '');
72 $value = (isset($keyvalueexploded[1]) ? $keyvalueexploded[1] : '');
73 $info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"');
74 }
75 }
76 }
77
78 $info['fileformat'] = 'svg';
79 $info['video']['dataformat'] = 'svg';
80 $info['video']['lossless'] = true;
81 //$info['video']['bits_per_sample'] = 24;
82 $info['video']['pixel_aspect_ratio'] = (float) 1;
83
84 if (!empty($info['svg']['svg']['sections']['width'])) {
85 $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']);
86 }
87 if (!empty($info['svg']['svg']['sections']['height'])) {
88 $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']);
89 }
90 if (!empty($info['svg']['svg']['sections']['version'])) {
91 $info['svg']['version'] = $info['svg']['svg']['sections']['version'];
92 }
93 if (!isset($info['svg']['version']) && isset($info['svg']['doctype']['sections'])) {
94 foreach ($info['svg']['doctype']['sections'] as $key => $value) {
95 if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) {
96 $info['svg']['version'] = $matches[1];
97 break;
98 }
99 }
100 }
101
102 if (!empty($info['svg']['width'])) {
103 $info['video']['resolution_x'] = $info['svg']['width'];
104 }
105 if (!empty($info['svg']['height'])) {
106 $info['video']['resolution_y'] = $info['svg']['height'];
107 }
108
109 return true;
110 }
111 $info['error'][] = 'Did not find expected <svg> tag';
112
113 return false;
114 }
115
116}
An exception for terminatinating execution or to throw for unit testing.
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:26
fseek($bytes, $whence=SEEK_SET)
GetId3() by James Heinrich info@getid3.org //.
Definition: Svg.php:29
$info
Definition: example_052.php:80