ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
module.graphic.svg.php
Go to the documentation of this file.
1<?php
4// available at http://getid3.sourceforge.net //
5// or http://www.getid3.org //
6// also https://github.com/JamesHeinrich/getID3 //
8// See readme.txt for more details //
10// //
11// module.graphic.svg.php //
12// module for analyzing SVG Image files //
13// dependencies: NONE //
14// ///
16
17
19{
20
21
22 public function Analyze() {
23 $info = &$this->getid3->info;
24
25 $this->fseek($info['avdataoffset']);
26
27 $SVGheader = $this->fread(4096);
28 if (preg_match('#<\?xml([^>]+)\?>#i', $SVGheader, $matches)) {
29 $info['svg']['xml']['raw'] = $matches;
30 }
31 if (preg_match('#<\!DOCTYPE([^>]+)>#i', $SVGheader, $matches)) {
32 $info['svg']['doctype']['raw'] = $matches;
33 }
34 if (preg_match('#<svg([^>]+)>#i', $SVGheader, $matches)) {
35 $info['svg']['svg']['raw'] = $matches;
36 }
37 if (isset($info['svg']['svg']['raw'])) {
38
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])) {
42 continue;
43 }
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]);
48 }
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]);
52 }
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);
56 if ($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, '"');
61 }
62 }
63 }
64
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;
70
71 if (!empty($info['svg']['svg']['sections']['width'])) {
72 $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']);
73 }
74 if (!empty($info['svg']['svg']['sections']['height'])) {
75 $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']);
76 }
77 if (!empty($info['svg']['svg']['sections']['version'])) {
78 $info['svg']['version'] = $info['svg']['svg']['sections']['version'];
79 }
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];
84 break;
85 }
86 }
87 }
88
89 if (!empty($info['svg']['width'])) {
90 $info['video']['resolution_x'] = $info['svg']['width'];
91 }
92 if (!empty($info['svg']['height'])) {
93 $info['video']['resolution_y'] = $info['svg']['height'];
94 }
95
96 return true;
97 }
98 $this->error('Did not find expected <svg> tag');
99 return false;
100 }
101
102}
An exception for terminatinating execution or to throw for unit testing.
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1711
fread($bytes)
Definition: getid3.php:1683
error($text)
Definition: getid3.php:1752
getID3() by James Heinrich info@getid3.org //
$key
Definition: croninfo.php:18
$info
Definition: index.php:5