1 | <?php |
---|
2 | ///////////////////////////////////////////////////////////////// |
---|
3 | /// getID3() by James Heinrich <info@getid3.org> // |
---|
4 | // available at http://getid3.sourceforge.net // |
---|
5 | // or http://www.getid3.org // |
---|
6 | ///////////////////////////////////////////////////////////////// |
---|
7 | // See readme.txt for more details // |
---|
8 | ///////////////////////////////////////////////////////////////// |
---|
9 | // // |
---|
10 | // module.graphic.jpg.php // |
---|
11 | // module for analyzing JPEG Image files // |
---|
12 | // dependencies: NONE // |
---|
13 | // /// |
---|
14 | ///////////////////////////////////////////////////////////////// |
---|
15 | |
---|
16 | |
---|
17 | class getid3_jpg |
---|
18 | { |
---|
19 | |
---|
20 | |
---|
21 | function getid3_jpg(&$fd, &$ThisFileInfo) { |
---|
22 | $ThisFileInfo['fileformat'] = 'jpg'; |
---|
23 | $ThisFileInfo['video']['dataformat'] = 'jpg'; |
---|
24 | $ThisFileInfo['video']['lossless'] = false; |
---|
25 | $ThisFileInfo['video']['bits_per_sample'] = 24; |
---|
26 | $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; |
---|
27 | |
---|
28 | fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); |
---|
29 | |
---|
30 | $imageinfo = array(); |
---|
31 | list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize']), $imageinfo); |
---|
32 | |
---|
33 | if (isset($imageinfo['APP13'])) { |
---|
34 | // http://php.net/iptcparse |
---|
35 | // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html |
---|
36 | $iptc_parsed = iptcparse($imageinfo['APP13']); |
---|
37 | if (is_array($iptc_parsed)) { |
---|
38 | foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) { |
---|
39 | list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw); |
---|
40 | $iptc_tagkey = intval(ltrim($iptc_tagkey, '0')); |
---|
41 | foreach ($iptc_values as $key => $value) { |
---|
42 | @$ThisFileInfo['iptc'][$this->IPTCrecordName($iptc_record)][$this->IPTCrecordTagName($iptc_record, $iptc_tagkey)][] = $value; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | //echo '<pre>'.htmlentities(print_r($iptc_parsed, true)).'</pre>'; |
---|
47 | } |
---|
48 | |
---|
49 | switch ($type) { |
---|
50 | case 2: // JPEG |
---|
51 | $ThisFileInfo['video']['resolution_x'] = $width; |
---|
52 | $ThisFileInfo['video']['resolution_y'] = $height; |
---|
53 | |
---|
54 | if (version_compare(phpversion(), '4.2.0', '>=')) { |
---|
55 | |
---|
56 | if (function_exists('exif_read_data')) { |
---|
57 | |
---|
58 | ob_start(); |
---|
59 | $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false); |
---|
60 | $errors = ob_get_contents(); |
---|
61 | if ($errors) { |
---|
62 | $ThisFileInfo['warning'][] = strip_tags($errors); |
---|
63 | unset($ThisFileInfo['jpg']['exif']); |
---|
64 | } |
---|
65 | ob_end_clean(); |
---|
66 | |
---|
67 | } else { |
---|
68 | |
---|
69 | $ThisFileInfo['warning'][] = 'EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif'); |
---|
70 | |
---|
71 | } |
---|
72 | |
---|
73 | } else { |
---|
74 | |
---|
75 | $ThisFileInfo['warning'][] = 'EXIF parsing only available in PHP v4.2.0 and higher compiled with --enable-exif (or php_exif.dll enabled for Windows). You are using PHP v'.phpversion(); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | return true; |
---|
80 | break; |
---|
81 | |
---|
82 | default: |
---|
83 | break; |
---|
84 | } |
---|
85 | |
---|
86 | unset($ThisFileInfo['fileformat']); |
---|
87 | return false; |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | function IPTCrecordName($iptc_record) { |
---|
92 | // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html |
---|
93 | static $IPTCrecordName = array(); |
---|
94 | if (empty($IPTCrecordName)) { |
---|
95 | $IPTCrecordName = array( |
---|
96 | 1 => 'IPTCEnvelope', |
---|
97 | 2 => 'IPTCApplication', |
---|
98 | 3 => 'IPTCNewsPhoto', |
---|
99 | 7 => 'IPTCPreObjectData', |
---|
100 | 8 => 'IPTCObjectData', |
---|
101 | 9 => 'IPTCPostObjectData', |
---|
102 | ); |
---|
103 | } |
---|
104 | return (isset($IPTCrecordName[$iptc_record]) ? $IPTCrecordName[$iptc_record] : ''); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | function IPTCrecordTagName($iptc_record, $iptc_tagkey) { |
---|
109 | // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html |
---|
110 | static $IPTCrecordTagName = array(); |
---|
111 | if (empty($IPTCrecordTagName)) { |
---|
112 | $IPTCrecordTagName = array( |
---|
113 | 1 => array( // IPTC EnvelopeRecord Tags |
---|
114 | 0 => 'EnvelopeRecordVersion', |
---|
115 | 5 => 'Destination', |
---|
116 | 20 => 'FileFormat', |
---|
117 | 22 => 'FileVersion', |
---|
118 | 30 => 'ServiceIdentifier', |
---|
119 | 40 => 'EnvelopeNumber', |
---|
120 | 50 => 'ProductID', |
---|
121 | 60 => 'EnvelopePriority', |
---|
122 | 70 => 'DateSent', |
---|
123 | 80 => 'TimeSent', |
---|
124 | 90 => 'CodedCharacterSet', |
---|
125 | 100 => 'UniqueObjectName', |
---|
126 | 120 => 'ARMIdentifier', |
---|
127 | 122 => 'ARMVersion', |
---|
128 | ), |
---|
129 | 2 => array( // IPTC ApplicationRecord Tags |
---|
130 | 0 => 'ApplicationRecordVersion', |
---|
131 | 3 => 'ObjectTypeReference', |
---|
132 | 4 => 'ObjectAttributeReference', |
---|
133 | 5 => 'ObjectName', |
---|
134 | 7 => 'EditStatus', |
---|
135 | 8 => 'EditorialUpdate', |
---|
136 | 10 => 'Urgency', |
---|
137 | 12 => 'SubjectReference', |
---|
138 | 15 => 'Category', |
---|
139 | 20 => 'SupplementalCategories', |
---|
140 | 22 => 'FixtureIdentifier', |
---|
141 | 25 => 'Keywords', |
---|
142 | 26 => 'ContentLocationCode', |
---|
143 | 27 => 'ContentLocationName', |
---|
144 | 30 => 'ReleaseDate', |
---|
145 | 35 => 'ReleaseTime', |
---|
146 | 37 => 'ExpirationDate', |
---|
147 | 38 => 'ExpirationTime', |
---|
148 | 40 => 'SpecialInstructions', |
---|
149 | 42 => 'ActionAdvised', |
---|
150 | 45 => 'ReferenceService', |
---|
151 | 47 => 'ReferenceDate', |
---|
152 | 50 => 'ReferenceNumber', |
---|
153 | 55 => 'DateCreated', |
---|
154 | 60 => 'TimeCreated', |
---|
155 | 62 => 'DigitalCreationDate', |
---|
156 | 63 => 'DigitalCreationTime', |
---|
157 | 65 => 'OriginatingProgram', |
---|
158 | 70 => 'ProgramVersion', |
---|
159 | 75 => 'ObjectCycle', |
---|
160 | 80 => 'By-line', |
---|
161 | 85 => 'By-lineTitle', |
---|
162 | 90 => 'City', |
---|
163 | 92 => 'Sub-location', |
---|
164 | 95 => 'Province-State', |
---|
165 | 100 => 'Country-PrimaryLocationCode', |
---|
166 | 101 => 'Country-PrimaryLocationName', |
---|
167 | 103 => 'OriginalTransmissionReference', |
---|
168 | 105 => 'Headline', |
---|
169 | 110 => 'Credit', |
---|
170 | 115 => 'Source', |
---|
171 | 116 => 'CopyrightNotice', |
---|
172 | 118 => 'Contact', |
---|
173 | 120 => 'Caption-Abstract', |
---|
174 | 121 => 'LocalCaption', |
---|
175 | 122 => 'Writer-Editor', |
---|
176 | 125 => 'RasterizedCaption', |
---|
177 | 130 => 'ImageType', |
---|
178 | 131 => 'ImageOrientation', |
---|
179 | 135 => 'LanguageIdentifier', |
---|
180 | 150 => 'AudioType', |
---|
181 | 151 => 'AudioSamplingRate', |
---|
182 | 152 => 'AudioSamplingResolution', |
---|
183 | 153 => 'AudioDuration', |
---|
184 | 154 => 'AudioOutcue', |
---|
185 | 184 => 'JobID', |
---|
186 | 185 => 'MasterDocumentID', |
---|
187 | 186 => 'ShortDocumentID', |
---|
188 | 187 => 'UniqueDocumentID', |
---|
189 | 188 => 'OwnerID', |
---|
190 | 200 => 'ObjectPreviewFileFormat', |
---|
191 | 201 => 'ObjectPreviewFileVersion', |
---|
192 | 202 => 'ObjectPreviewData', |
---|
193 | 221 => 'Prefs', |
---|
194 | 225 => 'ClassifyState', |
---|
195 | 228 => 'SimilarityIndex', |
---|
196 | 230 => 'DocumentNotes', |
---|
197 | 231 => 'DocumentHistory', |
---|
198 | 232 => 'ExifCameraInfo', |
---|
199 | ), |
---|
200 | 3 => array( // IPTC NewsPhoto Tags |
---|
201 | 0 => 'NewsPhotoVersion', |
---|
202 | 10 => 'IPTCPictureNumber', |
---|
203 | 20 => 'IPTCImageWidth', |
---|
204 | 30 => 'IPTCImageHeight', |
---|
205 | 40 => 'IPTCPixelWidth', |
---|
206 | 50 => 'IPTCPixelHeight', |
---|
207 | 55 => 'SupplementalType', |
---|
208 | 60 => 'ColorRepresentation', |
---|
209 | 64 => 'InterchangeColorSpace', |
---|
210 | 65 => 'ColorSequence', |
---|
211 | 66 => 'ICC_Profile', |
---|
212 | 70 => 'ColorCalibrationMatrix', |
---|
213 | 80 => 'LookupTable', |
---|
214 | 84 => 'NumIndexEntries', |
---|
215 | 85 => 'ColorPalette', |
---|
216 | 86 => 'IPTCBitsPerSample', |
---|
217 | 90 => 'SampleStructure', |
---|
218 | 100 => 'ScanningDirection', |
---|
219 | 102 => 'IPTCImageRotation', |
---|
220 | 110 => 'DataCompressionMethod', |
---|
221 | 120 => 'QuantizationMethod', |
---|
222 | 125 => 'EndPoints', |
---|
223 | 130 => 'ExcursionTolerance', |
---|
224 | 135 => 'BitsPerComponent', |
---|
225 | 140 => 'MaximumDensityRange', |
---|
226 | 145 => 'GammaCompensatedValue', |
---|
227 | ), |
---|
228 | 7 => array( // IPTC PreObjectData Tags |
---|
229 | 10 => 'SizeMode', |
---|
230 | 20 => 'MaxSubfileSize', |
---|
231 | 90 => 'ObjectSizeAnnounced', |
---|
232 | 95 => 'MaximumObjectSize', |
---|
233 | ), |
---|
234 | 8 => array( // IPTC ObjectData Tags |
---|
235 | 10 => 'SubFile', |
---|
236 | ), |
---|
237 | 9 => array( // IPTC PostObjectData Tags |
---|
238 | 10 => 'ConfirmedObjectSize', |
---|
239 | ), |
---|
240 | ); |
---|
241 | |
---|
242 | } |
---|
243 | return (isset($IPTCrecordTagName[$iptc_record][$iptc_tagkey]) ? $IPTCrecordTagName[$iptc_record][$iptc_tagkey] : $iptc_tagkey); |
---|
244 | } |
---|
245 | |
---|
246 | } |
---|
247 | |
---|
248 | |
---|
249 | ?> |
---|