3 * JPEG metadata reader/writer
5 * @license BSD <http://www.opensource.org/licenses/bsd-license.php>
6 * @link http://github.com/sd/jpeg-php
7 * @author Sebastian Delmont <sdelmont@zonageek.com>
8 * @author Andreas Gohr <andi@splitbrain.org>
9 * @author Hakan Sandell <hakan.sandell@mydata.se>
10 * @todo Add support for Maker Notes, Extend for GIF and PNG metadata
13 // Original copyright notice:
15 // Copyright (c) 2003 Sebastian Delmont <sdelmont@zonageek.com>
16 // All rights reserved.
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions
21 // 1. Redistributions of source code must retain the above copyright
22 // notice, this list of conditions and the following disclaimer.
23 // 2. Redistributions in binary form must reproduce the above copyright
24 // notice, this list of conditions and the following disclaimer in the
25 // documentation and/or other materials provided with the distribution.
26 // 3. Neither the name of the author nor the names of its contributors
27 // may be used to endorse or promote products derived from this software
28 // without specific prior written permission.
30 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
31 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
33 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
36 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
46 var $_type = 'unknown';
55 * @author Sebastian Delmont <sdelmont@zonageek.com>
59 function __construct($fileName) {
61 $this->_fileName
= $fileName;
64 $this->_type
= 'unknown';
67 unset($this->_markers
);
71 * Returns all gathered info as multidim array
73 * @author Sebastian Delmont <sdelmont@zonageek.com>
75 function & getRawInfo() {
78 if ($this->_markers
== null) {
86 * Returns basic image info
88 * @author Sebastian Delmont <sdelmont@zonageek.com>
90 function & getBasicInfo() {
95 if ($this->_markers
== null) {
99 $info['Name'] = $this->_info
['file']['Name'];
100 if (isset($this->_info
['file']['Url'])) {
101 $info['Url'] = $this->_info
['file']['Url'];
102 $info['NiceSize'] = "???KB";
104 $info['Size'] = $this->_info
['file']['Size'];
105 $info['NiceSize'] = $this->_info
['file']['NiceSize'];
108 if (@isset
($this->_info
['sof']['Format'])) {
109 $info['Format'] = $this->_info
['sof']['Format'] . " JPEG";
111 $info['Format'] = $this->_info
['sof']['Format'] . " JPEG";
114 if (@isset
($this->_info
['sof']['ColorChannels'])) {
115 $info['ColorMode'] = ($this->_info
['sof']['ColorChannels'] > 1) ?
"Color" : "B&W";
118 $info['Width'] = $this->getWidth();
119 $info['Height'] = $this->getHeight();
120 $info['DimStr'] = $this->getDimStr();
122 $dates = $this->getDates();
124 $info['DateTime'] = $dates['EarliestTime'];
125 $info['DateTimeStr'] = $dates['EarliestTimeStr'];
127 $info['HasThumbnail'] = $this->hasThumbnail();
134 * Convinience function to access nearly all available Data
135 * through one function
137 * @author Andreas Gohr <andi@splitbrain.org>
139 * @param array|string $fields field name or array with field names
140 * @return bool|string
142 function getField($fields) {
143 if(!is_array($fields)) $fields = array($fields);
145 foreach($fields as $field){
146 if(strtolower(substr($field,0,5)) == 'iptc.'){
147 $info = $this->getIPTCField(substr($field,5));
148 }elseif(strtolower(substr($field,0,5)) == 'exif.'){
149 $info = $this->getExifField(substr($field,5));
150 }elseif(strtolower(substr($field,0,4)) == 'xmp.'){
151 $info = $this->getXmpField(substr($field,4));
152 }elseif(strtolower(substr($field,0,5)) == 'file.'){
153 $info = $this->getFileField(substr($field,5));
154 }elseif(strtolower(substr($field,0,5)) == 'date.'){
155 $info = $this->getDateField(substr($field,5));
156 }elseif(strtolower($field) == 'simple.camera'){
157 $info = $this->getCamera();
158 }elseif(strtolower($field) == 'simple.raw'){
159 return $this->getRawInfo();
160 }elseif(strtolower($field) == 'simple.title'){
161 $info = $this->getTitle();
162 }elseif(strtolower($field) == 'simple.shutterspeed'){
163 $info = $this->getShutterSpeed();
165 $info = $this->getExifField($field);
167 if($info != false) break;
170 if($info === false) $info = '';
172 if(isset($info['val'])){
173 $info = $info['val'];
176 foreach($info as $part){
178 if(isset($part['val'])){
179 $arr[] = $part['val'];
181 $arr[] = join(', ',$part);
187 $info = join(', ',$arr);
194 * Convinience function to set nearly all available Data
195 * through one function
197 * @author Andreas Gohr <andi@splitbrain.org>
199 * @param string $field field name
200 * @param string $value
201 * @return bool success or fail
203 function setField($field, $value) {
204 if(strtolower(substr($field,0,5)) == 'iptc.'){
205 return $this->setIPTCField(substr($field,5),$value);
206 }elseif(strtolower(substr($field,0,5)) == 'exif.'){
207 return $this->setExifField(substr($field,5),$value);
209 return $this->setExifField($field,$value);
214 * Convinience function to delete nearly all available Data
215 * through one function
217 * @author Andreas Gohr <andi@splitbrain.org>
219 * @param string $field field name
222 function deleteField($field) {
223 if(strtolower(substr($field,0,5)) == 'iptc.'){
224 return $this->deleteIPTCField(substr($field,5));
225 }elseif(strtolower(substr($field,0,5)) == 'exif.'){
226 return $this->deleteExifField(substr($field,5));
228 return $this->deleteExifField($field);
233 * Return a date field
235 * @author Andreas Gohr <andi@splitbrain.org>
237 * @param string $field
238 * @return false|string
240 function getDateField($field) {
241 if (!isset($this->_info
['dates'])) {
242 $this->_info
['dates'] = $this->getDates();
245 if (isset($this->_info
['dates'][$field])) {
246 return $this->_info
['dates'][$field];
253 * Return a file info field
255 * @author Andreas Gohr <andi@splitbrain.org>
257 * @param string $field field name
258 * @return false|string
260 function getFileField($field) {
261 if (!isset($this->_info
['file'])) {
262 $this->_parseFileInfo();
265 if (isset($this->_info
['file'][$field])) {
266 return $this->_info
['file'][$field];
273 * Return the camera info (Maker and Model)
275 * @author Andreas Gohr <andi@splitbrain.org>
276 * @todo handle makernotes
278 * @return false|string
280 function getCamera(){
281 $make = $this->getField(array('Exif.Make','Exif.TIFFMake'));
282 $model = $this->getField(array('Exif.Model','Exif.TIFFModel'));
283 $cam = trim("$make $model");
284 if(empty($cam)) return false;
289 * Return shutter speed as a ratio
291 * @author Joe Lapp <joe.lapp@pobox.com>
295 function getShutterSpeed() {
296 if (!isset($this->_info
['exif'])) {
297 $this->_parseMarkerExif();
299 if(!isset($this->_info
['exif']['ExposureTime'])){
303 $field = $this->_info
['exif']['ExposureTime'];
304 if($field['den'] == 1) return $field['num'];
305 return $field['num'].'/'.$field['den'];
309 * Return an EXIF field
311 * @author Sebastian Delmont <sdelmont@zonageek.com>
313 * @param string $field field name
314 * @return false|string
316 function getExifField($field) {
317 if (!isset($this->_info
['exif'])) {
318 $this->_parseMarkerExif();
321 if ($this->_markers
== null) {
325 if (isset($this->_info
['exif'][$field])) {
326 return $this->_info
['exif'][$field];
333 * Return an XMP field
335 * @author Hakan Sandell <hakan.sandell@mydata.se>
337 * @param string $field field name
338 * @return false|string
340 function getXmpField($field) {
341 if (!isset($this->_info
['xmp'])) {
342 $this->_parseMarkerXmp();
345 if ($this->_markers
== null) {
349 if (isset($this->_info
['xmp'][$field])) {
350 return $this->_info
['xmp'][$field];
357 * Return an Adobe Field
359 * @author Sebastian Delmont <sdelmont@zonageek.com>
361 * @param string $field field name
362 * @return false|string
364 function getAdobeField($field) {
365 if (!isset($this->_info
['adobe'])) {
366 $this->_parseMarkerAdobe();
369 if ($this->_markers
== null) {
373 if (isset($this->_info
['adobe'][$field])) {
374 return $this->_info
['adobe'][$field];
381 * Return an IPTC field
383 * @author Sebastian Delmont <sdelmont@zonageek.com>
385 * @param string $field field name
386 * @return false|string
388 function getIPTCField($field) {
389 if (!isset($this->_info
['iptc'])) {
390 $this->_parseMarkerAdobe();
393 if ($this->_markers
== null) {
397 if (isset($this->_info
['iptc'][$field])) {
398 return $this->_info
['iptc'][$field];
407 * @author Sebastian Delmont <sdelmont@zonageek.com>
408 * @author Joe Lapp <joe.lapp@pobox.com>
410 * @param string $field field name
411 * @param string $value
414 function setExifField($field, $value) {
415 if (!isset($this->_info
['exif'])) {
416 $this->_parseMarkerExif();
419 if ($this->_markers
== null) {
423 if ($this->_info
['exif'] == false) {
424 $this->_info
['exif'] = array();
427 // make sure datetimes are in correct format
428 if(strlen($field) >= 8 && strtolower(substr($field, 0, 8)) == 'datetime') {
429 if(strlen($value) < 8 ||
$value[4] != ':' ||
$value[7] != ':') {
430 $value = date('Y:m:d H:i:s', strtotime($value));
434 $this->_info
['exif'][$field] = $value;
442 * @author Sebastian Delmont <sdelmont@zonageek.com>
444 * @param string $field field name
445 * @param string $value
448 function setAdobeField($field, $value) {
449 if (!isset($this->_info
['adobe'])) {
450 $this->_parseMarkerAdobe();
453 if ($this->_markers
== null) {
457 if ($this->_info
['adobe'] == false) {
458 $this->_info
['adobe'] = array();
461 $this->_info
['adobe'][$field] = $value;
467 * Calculates the multiplier needed to resize the image to the given
470 * @author Andreas Gohr <andi@splitbrain.org>
472 * @param int $maxwidth
473 * @param int $maxheight
476 function getResizeRatio($maxwidth,$maxheight=0){
477 if(!$maxheight) $maxheight = $maxwidth;
479 $w = $this->getField('File.Width');
480 $h = $this->getField('File.Height');
485 $ratio = $maxwidth/$w;
486 }elseif($h > $maxheight){
487 $ratio = $maxheight/$h;
490 if($h >= $maxheight){
491 $ratio = $maxheight/$h;
492 }elseif($w > $maxwidth){
493 $ratio = $maxwidth/$w;
503 * @author Sebastian Delmont <sdelmont@zonageek.com>
505 * @param string $field field name
506 * @param string $value
509 function setIPTCField($field, $value) {
510 if (!isset($this->_info
['iptc'])) {
511 $this->_parseMarkerAdobe();
514 if ($this->_markers
== null) {
518 if ($this->_info
['iptc'] == false) {
519 $this->_info
['iptc'] = array();
522 $this->_info
['iptc'][$field] = $value;
528 * Delete an EXIF field
530 * @author Sebastian Delmont <sdelmont@zonageek.com>
532 * @param string $field field name
535 function deleteExifField($field) {
536 if (!isset($this->_info
['exif'])) {
537 $this->_parseMarkerAdobe();
540 if ($this->_markers
== null) {
544 if ($this->_info
['exif'] != false) {
545 unset($this->_info
['exif'][$field]);
552 * Delete an Adobe field
554 * @author Sebastian Delmont <sdelmont@zonageek.com>
556 * @param string $field field name
559 function deleteAdobeField($field) {
560 if (!isset($this->_info
['adobe'])) {
561 $this->_parseMarkerAdobe();
564 if ($this->_markers
== null) {
568 if ($this->_info
['adobe'] != false) {
569 unset($this->_info
['adobe'][$field]);
576 * Delete an IPTC field
578 * @author Sebastian Delmont <sdelmont@zonageek.com>
580 * @param string $field field name
583 function deleteIPTCField($field) {
584 if (!isset($this->_info
['iptc'])) {
585 $this->_parseMarkerAdobe();
588 if ($this->_markers
== null) {
592 if ($this->_info
['iptc'] != false) {
593 unset($this->_info
['iptc'][$field]);
600 * Get the image's title, tries various fields
602 * @param int $max maximum number chars (keeps words)
603 * @return false|string
605 * @author Andreas Gohr <andi@splitbrain.org>
607 function getTitle($max=80){
608 // try various fields
609 $cap = $this->getField(array('Iptc.Headline',
613 'Exif.TIFFUserComment',
614 'Exif.TIFFImageDescription',
616 if (empty($cap)) return false;
618 if(!$max) return $cap;
619 // Shorten to 80 chars (keeping words)
620 $new = preg_replace('/\n.+$/','',wordwrap($cap, $max));
621 if($new != $cap) $new .= '...';
627 * Gather various date fields
629 * @author Sebastian Delmont <sdelmont@zonageek.com>
633 function getDates() {
635 if ($this->_markers
== null) {
636 if (@isset
($this->_info
['file']['UnixTime'])) {
638 $dates['FileModified'] = $this->_info
['file']['UnixTime'];
639 $dates['Time'] = $this->_info
['file']['UnixTime'];
640 $dates['TimeSource'] = 'FileModified';
641 $dates['TimeStr'] = date("Y-m-d H:i:s", $this->_info
['file']['UnixTime']);
642 $dates['EarliestTime'] = $this->_info
['file']['UnixTime'];
643 $dates['EarliestTimeSource'] = 'FileModified';
644 $dates['EarliestTimeStr'] = date("Y-m-d H:i:s", $this->_info
['file']['UnixTime']);
645 $dates['LatestTime'] = $this->_info
['file']['UnixTime'];
646 $dates['LatestTimeSource'] = 'FileModified';
647 $dates['LatestTimeStr'] = date("Y-m-d H:i:s", $this->_info
['file']['UnixTime']);
656 $latestTimeSource = "";
657 $earliestTime = time();
658 $earliestTimeSource = "";
660 if (@isset
($this->_info
['exif']['DateTime'])) {
661 $dates['ExifDateTime'] = $this->_info
['exif']['DateTime'];
663 $aux = $this->_info
['exif']['DateTime'];
666 $t = strtotime($aux);
668 if ($t && $t > $latestTime) {
670 $latestTimeSource = "ExifDateTime";
673 if ($t && $t < $earliestTime) {
675 $earliestTimeSource = "ExifDateTime";
679 if (@isset
($this->_info
['exif']['DateTimeOriginal'])) {
680 $dates['ExifDateTimeOriginal'] = $this->_info
['exif']['DateTimeOriginal'];
682 $aux = $this->_info
['exif']['DateTimeOriginal'];
685 $t = strtotime($aux);
687 if ($t && $t > $latestTime) {
689 $latestTimeSource = "ExifDateTimeOriginal";
692 if ($t && $t < $earliestTime) {
694 $earliestTimeSource = "ExifDateTimeOriginal";
698 if (@isset
($this->_info
['exif']['DateTimeDigitized'])) {
699 $dates['ExifDateTimeDigitized'] = $this->_info
['exif']['DateTimeDigitized'];
701 $aux = $this->_info
['exif']['DateTimeDigitized'];
704 $t = strtotime($aux);
706 if ($t && $t > $latestTime) {
708 $latestTimeSource = "ExifDateTimeDigitized";
711 if ($t && $t < $earliestTime) {
713 $earliestTimeSource = "ExifDateTimeDigitized";
717 if (@isset
($this->_info
['iptc']['DateCreated'])) {
718 $dates['IPTCDateCreated'] = $this->_info
['iptc']['DateCreated'];
720 $aux = $this->_info
['iptc']['DateCreated'];
721 $aux = substr($aux, 0, 4) . "-" . substr($aux, 4, 2) . "-" . substr($aux, 6, 2);
722 $t = strtotime($aux);
724 if ($t && $t > $latestTime) {
726 $latestTimeSource = "IPTCDateCreated";
729 if ($t && $t < $earliestTime) {
731 $earliestTimeSource = "IPTCDateCreated";
735 if (@isset
($this->_info
['file']['UnixTime'])) {
736 $dates['FileModified'] = $this->_info
['file']['UnixTime'];
738 $t = $this->_info
['file']['UnixTime'];
740 if ($t && $t > $latestTime) {
742 $latestTimeSource = "FileModified";
745 if ($t && $t < $earliestTime) {
747 $earliestTimeSource = "FileModified";
751 $dates['Time'] = $earliestTime;
752 $dates['TimeSource'] = $earliestTimeSource;
753 $dates['TimeStr'] = date("Y-m-d H:i:s", $earliestTime);
754 $dates['EarliestTime'] = $earliestTime;
755 $dates['EarliestTimeSource'] = $earliestTimeSource;
756 $dates['EarliestTimeStr'] = date("Y-m-d H:i:s", $earliestTime);
757 $dates['LatestTime'] = $latestTime;
758 $dates['LatestTimeSource'] = $latestTimeSource;
759 $dates['LatestTimeStr'] = date("Y-m-d H:i:s", $latestTime);
765 * Get the image width, tries various fields
767 * @author Sebastian Delmont <sdelmont@zonageek.com>
769 * @return false|string
771 function getWidth() {
772 if (!isset($this->_info
['sof'])) {
773 $this->_parseMarkerSOF();
776 if ($this->_markers
== null) {
780 if (isset($this->_info
['sof']['ImageWidth'])) {
781 return $this->_info
['sof']['ImageWidth'];
784 if (!isset($this->_info
['exif'])) {
785 $this->_parseMarkerExif();
788 if (isset($this->_info
['exif']['PixelXDimension'])) {
789 return $this->_info
['exif']['PixelXDimension'];
796 * Get the image height, tries various fields
798 * @author Sebastian Delmont <sdelmont@zonageek.com>
800 * @return false|string
802 function getHeight() {
803 if (!isset($this->_info
['sof'])) {
804 $this->_parseMarkerSOF();
807 if ($this->_markers
== null) {
811 if (isset($this->_info
['sof']['ImageHeight'])) {
812 return $this->_info
['sof']['ImageHeight'];
815 if (!isset($this->_info
['exif'])) {
816 $this->_parseMarkerExif();
819 if (isset($this->_info
['exif']['PixelYDimension'])) {
820 return $this->_info
['exif']['PixelYDimension'];
827 * Get an dimension string for use in img tag
829 * @author Sebastian Delmont <sdelmont@zonageek.com>
831 * @return false|string
833 function getDimStr() {
834 if ($this->_markers
== null) {
838 $w = $this->getWidth();
839 $h = $this->getHeight();
841 return "width='" . $w . "' height='" . $h . "'";
845 * Checks for an embedded thumbnail
847 * @author Sebastian Delmont <sdelmont@zonageek.com>
849 * @param string $which possible values: 'any', 'exif' or 'adobe'
850 * @return false|string
852 function hasThumbnail($which = 'any') {
853 if (($which == 'any') ||
($which == 'exif')) {
854 if (!isset($this->_info
['exif'])) {
855 $this->_parseMarkerExif();
858 if ($this->_markers
== null) {
862 if (isset($this->_info
['exif']) && is_array($this->_info
['exif'])) {
863 if (isset($this->_info
['exif']['JFIFThumbnail'])) {
869 if ($which == 'adobe') {
870 if (!isset($this->_info
['adobe'])) {
871 $this->_parseMarkerAdobe();
874 if ($this->_markers
== null) {
878 if (isset($this->_info
['adobe']) && is_array($this->_info
['adobe'])) {
879 if (isset($this->_info
['adobe']['ThumbnailData'])) {
889 * Send embedded thumbnail to browser
891 * @author Sebastian Delmont <sdelmont@zonageek.com>
893 * @param string $which possible values: 'any', 'exif' or 'adobe'
896 function sendThumbnail($which = 'any') {
899 if (($which == 'any') ||
($which == 'exif')) {
900 if (!isset($this->_info
['exif'])) {
901 $this->_parseMarkerExif();
904 if ($this->_markers
== null) {
908 if (isset($this->_info
['exif']) && is_array($this->_info
['exif'])) {
909 if (isset($this->_info
['exif']['JFIFThumbnail'])) {
910 $data =& $this->_info
['exif']['JFIFThumbnail'];
915 if (($which == 'adobe') ||
($data == null)){
916 if (!isset($this->_info
['adobe'])) {
917 $this->_parseMarkerAdobe();
920 if ($this->_markers
== null) {
924 if (isset($this->_info
['adobe']) && is_array($this->_info
['adobe'])) {
925 if (isset($this->_info
['adobe']['ThumbnailData'])) {
926 $data =& $this->_info
['adobe']['ThumbnailData'];
932 header("Content-type: image/jpeg");
941 * Save changed Metadata
943 * @author Sebastian Delmont <sdelmont@zonageek.com>
944 * @author Andreas Gohr <andi@splitbrain.org>
946 * @param string $fileName file name or empty string for a random name
949 function save($fileName = "") {
950 if ($fileName == "") {
951 $tmpName = tempnam(dirname($this->_fileName
),'_metatemp_');
952 $this->_writeJPEG($tmpName);
953 if (file_exists($tmpName)) {
954 return io_rename($tmpName, $this->_fileName
);
957 return $this->_writeJPEG($fileName);
962 /*************************************************************/
963 /* PRIVATE FUNCTIONS (Internal Use Only!) */
964 /*************************************************************/
966 /*************************************************************/
967 function _dispose($fileName = "") {
968 $this->_fileName
= $fileName;
971 $this->_type
= 'unknown';
973 unset($this->_markers
);
977 /*************************************************************/
978 function _readJPEG() {
979 unset($this->_markers
);
980 //unset($this->_info);
981 $this->_markers
= array();
982 //$this->_info = array();
984 $this->_fp
= @fopen
($this->_fileName
, 'rb');
986 if (file_exists($this->_fileName
)) {
987 $this->_type
= 'file';
990 $this->_type
= 'url';
994 return false; // ERROR: Can't open file
997 // Check for the JPEG signature
998 $c1 = ord(fgetc($this->_fp
));
999 $c2 = ord(fgetc($this->_fp
));
1001 if ($c1 != 0xFF ||
$c2 != 0xD8) { // (0xFF + SOI)
1002 $this->_markers
= null;
1003 return false; // ERROR: File is not a JPEG
1014 // First, skip any non 0xFF bytes
1016 $c = ord(fgetc($this->_fp
));
1017 while (!feof($this->_fp
) && ($c != 0xFF)) {
1019 $c = ord(fgetc($this->_fp
));
1021 // Then skip all 0xFF until the marker byte
1023 $marker = ord(fgetc($this->_fp
));
1024 } while (!feof($this->_fp
) && ($marker == 0xFF));
1026 if (feof($this->_fp
)) {
1027 return false; // ERROR: Unexpected EOF
1029 if ($discarded != 0) {
1030 return false; // ERROR: Extraneous data
1033 $length = ord(fgetc($this->_fp
)) * 256 +
ord(fgetc($this->_fp
));
1034 if (feof($this->_fp
)) {
1035 return false; // ERROR: Unexpected EOF
1038 return false; // ERROR: Extraneous data
1040 $length = $length - 2; // The length we got counts itself
1047 case 0xE0: // APP0: JFIF data
1048 case 0xE1: // APP1: EXIF or XMP data
1049 case 0xED: // APP13: IPTC / Photoshop data
1052 case 0xDA: // SOS: Start of scan... the image itself and the last block on the file
1054 $length = -1; // This field has no length... it includes all data until EOF
1058 $capture = true;//false;
1062 $this->_markers
[$count] = array();
1063 $this->_markers
[$count]['marker'] = $marker;
1064 $this->_markers
[$count]['length'] = $length;
1068 $this->_markers
[$count]['data'] = fread($this->_fp
, $length);
1070 $this->_markers
[$count]['data'] = "";
1073 $result = @fseek
($this->_fp
, $length, SEEK_CUR
);
1074 // fseek doesn't seem to like HTTP 'files', but fgetc has no problem
1075 if (!($result === 0)) {
1076 for ($i = 0; $i < $length; $i++
) {
1092 /*************************************************************/
1093 function _parseAll() {
1094 if (!isset($this->_info
['file'])) {
1095 $this->_parseFileInfo();
1097 if (!isset($this->_markers
)) {
1101 if ($this->_markers
== null) {
1105 if (!isset($this->_info
['jfif'])) {
1106 $this->_parseMarkerJFIF();
1108 if (!isset($this->_info
['jpeg'])) {
1109 $this->_parseMarkerSOF();
1111 if (!isset($this->_info
['exif'])) {
1112 $this->_parseMarkerExif();
1114 if (!isset($this->_info
['xmp'])) {
1115 $this->_parseMarkerXmp();
1117 if (!isset($this->_info
['adobe'])) {
1118 $this->_parseMarkerAdobe();
1122 /*************************************************************/
1125 * @param string $outputName
1129 function _writeJPEG($outputName) {
1133 $wroteAdobe = false;
1135 $this->_fp
= @fopen
($this->_fileName
, 'r');
1137 if (file_exists($this->_fileName
)) {
1138 $this->_type
= 'file';
1141 $this->_type
= 'url';
1145 return false; // ERROR: Can't open file
1148 $this->_fpout
= fopen($outputName, 'wb');
1149 if (!$this->_fpout
) {
1150 $this->_fpout
= null;
1153 return false; // ERROR: Can't open output file
1156 // Check for the JPEG signature
1157 $c1 = ord(fgetc($this->_fp
));
1158 $c2 = ord(fgetc($this->_fp
));
1160 if ($c1 != 0xFF ||
$c2 != 0xD8) { // (0xFF + SOI)
1161 return false; // ERROR: File is not a JPEG
1164 fputs($this->_fpout
, chr(0xFF), 1);
1165 fputs($this->_fpout
, chr(0xD8), 1); // (0xFF + SOI)
1173 // First, skip any non 0xFF bytes
1175 $c = ord(fgetc($this->_fp
));
1176 while (!feof($this->_fp
) && ($c != 0xFF)) {
1178 $c = ord(fgetc($this->_fp
));
1180 // Then skip all 0xFF until the marker byte
1182 $marker = ord(fgetc($this->_fp
));
1183 } while (!feof($this->_fp
) && ($marker == 0xFF));
1185 if (feof($this->_fp
)) {
1187 break; // ERROR: Unexpected EOF
1189 if ($discarded != 0) {
1191 break; // ERROR: Extraneous data
1194 $length = ord(fgetc($this->_fp
)) * 256 +
ord(fgetc($this->_fp
));
1195 if (feof($this->_fp
)) {
1197 break; // ERROR: Unexpected EOF
1201 break; // ERROR: Extraneous data
1203 $length = $length - 2; // The length we got counts itself
1206 if ($marker == 0xE1) { // APP1: EXIF data
1207 $data =& $this->_createMarkerEXIF();
1210 elseif ($marker == 0xED) { // APP13: IPTC / Photoshop data
1211 $data =& $this->_createMarkerAdobe();
1214 elseif ($marker == 0xDA) { // SOS: Start of scan... the image itself and the last block on the file
1218 if (!$wroteEXIF && (($marker < 0xE0) ||
($marker > 0xEF))) {
1219 if (isset($this->_info
['exif']) && is_array($this->_info
['exif'])) {
1220 $exif =& $this->_createMarkerEXIF();
1221 $this->_writeJPEGMarker(0xE1, strlen($exif), $exif, 0);
1227 if (!$wroteAdobe && (($marker < 0xE0) ||
($marker > 0xEF))) {
1228 if ((isset($this->_info
['adobe']) && is_array($this->_info
['adobe']))
1229 ||
(isset($this->_info
['iptc']) && is_array($this->_info
['iptc']))) {
1230 $adobe =& $this->_createMarkerAdobe();
1231 $this->_writeJPEGMarker(0xED, strlen($adobe), $adobe, 0);
1237 $origLength = $length;
1239 $length = strlen($data);
1242 if ($marker != -1) {
1243 $this->_writeJPEGMarker($marker, $length, $data, $origLength);
1252 if ($this->_fpout
) {
1253 fclose($this->_fpout
);
1254 $this->_fpout
= null;
1260 /*************************************************************/
1263 * @param integer $marker
1264 * @param integer $length
1265 * @param string $data
1266 * @param integer $origLength
1270 function _writeJPEGMarker($marker, $length, &$data, $origLength) {
1275 fputs($this->_fpout
, chr(0xFF), 1);
1276 fputs($this->_fpout
, chr($marker), 1);
1277 fputs($this->_fpout
, chr((($length +
2) & 0x0000FF00) >> 8), 1);
1278 fputs($this->_fpout
, chr((($length +
2) & 0x000000FF) >> 0), 1);
1281 // Copy the generated data
1282 fputs($this->_fpout
, $data, $length);
1284 if ($origLength > 0) { // Skip the original data
1285 $result = @fseek
($this->_fp
, $origLength, SEEK_CUR
);
1286 // fseek doesn't seem to like HTTP 'files', but fgetc has no problem
1288 for ($i = 0; $i < $origLength; $i++
) {
1294 if ($marker == 0xDA) { // Copy until EOF
1295 while (!feof($this->_fp
)) {
1296 $data = fread($this->_fp
, 1024 * 16);
1297 fputs($this->_fpout
, $data, strlen($data));
1299 } else { // Copy only $length bytes
1300 $data = @fread
($this->_fp
, $length);
1301 fputs($this->_fpout
, $data, $length);
1309 * Gets basic info from the file - should work with non-JPEGs
1311 * @author Sebastian Delmont <sdelmont@zonageek.com>
1312 * @author Andreas Gohr <andi@splitbrain.org>
1314 function _parseFileInfo() {
1315 if (file_exists($this->_fileName
) && is_file($this->_fileName
)) {
1316 $this->_info
['file'] = array();
1317 $this->_info
['file']['Name'] = utf8_decodeFN(\dokuwiki\Utf8\PhpString
::basename($this->_fileName
));
1318 $this->_info
['file']['Path'] = fullpath($this->_fileName
);
1319 $this->_info
['file']['Size'] = filesize($this->_fileName
);
1320 if ($this->_info
['file']['Size'] < 1024) {
1321 $this->_info
['file']['NiceSize'] = $this->_info
['file']['Size'] . 'B';
1322 } elseif ($this->_info
['file']['Size'] < (1024 * 1024)) {
1323 $this->_info
['file']['NiceSize'] = round($this->_info
['file']['Size'] / 1024) . 'KB';
1324 } elseif ($this->_info
['file']['Size'] < (1024 * 1024 * 1024)) {
1325 $this->_info
['file']['NiceSize'] = round($this->_info
['file']['Size'] / (1024*1024)) . 'MB';
1327 $this->_info
['file']['NiceSize'] = $this->_info
['file']['Size'] . 'B';
1329 $this->_info
['file']['UnixTime'] = filemtime($this->_fileName
);
1331 // get image size directly from file
1332 if ($size = getimagesize($this->_fileName
)) {
1333 $this->_info
['file']['Width'] = $size[0];
1334 $this->_info
['file']['Height'] = $size[1];
1336 // set mime types and formats
1337 // http://php.net/manual/en/function.getimagesize.php
1338 // http://php.net/manual/en/function.image-type-to-mime-type.php
1341 $this->_info
['file']['Mime'] = 'image/gif';
1342 $this->_info
['file']['Format'] = 'GIF';
1345 $this->_info
['file']['Mime'] = 'image/jpeg';
1346 $this->_info
['file']['Format'] = 'JPEG';
1349 $this->_info
['file']['Mime'] = 'image/png';
1350 $this->_info
['file']['Format'] = 'PNG';
1353 $this->_info
['file']['Mime'] = 'application/x-shockwave-flash';
1354 $this->_info
['file']['Format'] = 'SWF';
1357 $this->_info
['file']['Mime'] = 'image/psd';
1358 $this->_info
['file']['Format'] = 'PSD';
1361 $this->_info
['file']['Mime'] = 'image/bmp';
1362 $this->_info
['file']['Format'] = 'BMP';
1365 $this->_info
['file']['Mime'] = 'image/tiff';
1366 $this->_info
['file']['Format'] = 'TIFF (Intel)';
1369 $this->_info
['file']['Mime'] = 'image/tiff';
1370 $this->_info
['file']['Format'] = 'TIFF (Motorola)';
1373 $this->_info
['file']['Mime'] = 'application/octet-stream';
1374 $this->_info
['file']['Format'] = 'JPC';
1377 $this->_info
['file']['Mime'] = 'image/jp2';
1378 $this->_info
['file']['Format'] = 'JP2';
1381 $this->_info
['file']['Mime'] = 'application/octet-stream';
1382 $this->_info
['file']['Format'] = 'JPX';
1385 $this->_info
['file']['Mime'] = 'application/octet-stream';
1386 $this->_info
['file']['Format'] = 'JB2';
1389 $this->_info
['file']['Mime'] = 'application/x-shockwave-flash';
1390 $this->_info
['file']['Format'] = 'SWC';
1393 $this->_info
['file']['Mime'] = 'image/iff';
1394 $this->_info
['file']['Format'] = 'IFF';
1397 $this->_info
['file']['Mime'] = 'image/vnd.wap.wbmp';
1398 $this->_info
['file']['Format'] = 'WBMP';
1401 $this->_info
['file']['Mime'] = 'image/xbm';
1402 $this->_info
['file']['Format'] = 'XBM';
1405 $this->_info
['file']['Mime'] = 'image/unknown';
1409 $this->_info
['file'] = array();
1410 $this->_info
['file']['Name'] = \dokuwiki\Utf8\PhpString
::basename($this->_fileName
);
1411 $this->_info
['file']['Url'] = $this->_fileName
;
1417 /*************************************************************/
1418 function _parseMarkerJFIF() {
1419 if (!isset($this->_markers
)) {
1423 if ($this->_markers
== null ||
$this->_isMarkerDisabled(('jfif'))) {
1429 $count = count($this->_markers
);
1430 for ($i = 0; $i < $count; $i++
) {
1431 if ($this->_markers
[$i]['marker'] == 0xE0) {
1432 $signature = $this->_getFixedString($this->_markers
[$i]['data'], 0, 4);
1433 if ($signature == 'JFIF') {
1434 $data =& $this->_markers
[$i]['data'];
1440 if ($data == null) {
1441 $this->_info
['jfif'] = false;
1445 $this->_info
['jfif'] = array();
1447 $vmaj = $this->_getByte($data, 5);
1448 $vmin = $this->_getByte($data, 6);
1450 $this->_info
['jfif']['Version'] = sprintf('%d.%02d', $vmaj, $vmin);
1452 $units = $this->_getByte($data, 7);
1455 $this->_info
['jfif']['Units'] = 'pixels';
1458 $this->_info
['jfif']['Units'] = 'dpi';
1461 $this->_info
['jfif']['Units'] = 'dpcm';
1464 $this->_info
['jfif']['Units'] = 'unknown';
1468 $xdens = $this->_getShort($data, 8);
1469 $ydens = $this->_getShort($data, 10);
1471 $this->_info
['jfif']['XDensity'] = $xdens;
1472 $this->_info
['jfif']['YDensity'] = $ydens;
1474 $thumbx = $this->_getByte($data, 12);
1475 $thumby = $this->_getByte($data, 13);
1477 $this->_info
['jfif']['ThumbnailWidth'] = $thumbx;
1478 $this->_info
['jfif']['ThumbnailHeight'] = $thumby;
1479 } catch(Exception
$e) {
1480 $this->_handleMarkerParsingException($e);
1481 $this->_info
['jfif'] = false;
1488 /*************************************************************/
1489 function _parseMarkerSOF() {
1490 if (!isset($this->_markers
)) {
1494 if ($this->_markers
== null ||
$this->_isMarkerDisabled(('sof'))) {
1500 $count = count($this->_markers
);
1501 for ($i = 0; $i < $count; $i++
) {
1502 switch ($this->_markers
[$i]['marker']) {
1507 $data =& $this->_markers
[$i]['data'];
1508 $marker = $this->_markers
[$i]['marker'];
1513 if ($data == null) {
1514 $this->_info
['sof'] = false;
1519 $this->_info
['sof'] = array();
1523 $format = 'Baseline';
1526 $format = 'Progessive';
1529 $format = 'Non-baseline';
1532 $format = 'Arithmetic';
1538 $this->_info
['sof']['Format'] = $format;
1539 $this->_info
['sof']['SamplePrecision'] = $this->_getByte($data, $pos +
0);
1540 $this->_info
['sof']['ImageHeight'] = $this->_getShort($data, $pos +
1);
1541 $this->_info
['sof']['ImageWidth'] = $this->_getShort($data, $pos +
3);
1542 $this->_info
['sof']['ColorChannels'] = $this->_getByte($data, $pos +
5);
1543 } catch(Exception
$e) {
1544 $this->_handleMarkerParsingException($e);
1545 $this->_info
['sof'] = false;
1553 * Parses the XMP data
1555 * @author Hakan Sandell <hakan.sandell@mydata.se>
1557 function _parseMarkerXmp() {
1558 if (!isset($this->_markers
)) {
1562 if ($this->_markers
== null ||
$this->_isMarkerDisabled(('xmp'))) {
1568 $count = count($this->_markers
);
1569 for ($i = 0; $i < $count; $i++
) {
1570 if ($this->_markers
[$i]['marker'] == 0xE1) {
1571 $signature = $this->_getFixedString($this->_markers
[$i]['data'], 0, 29);
1572 if ($signature == "http://ns.adobe.com/xap/1.0/\0") {
1573 $data = substr($this->_markers
[$i]['data'], 29);
1579 if ($data == null) {
1580 $this->_info
['xmp'] = false;
1584 $parser = xml_parser_create();
1585 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING
, 0);
1586 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE
, 1);
1587 $result = xml_parse_into_struct($parser, $data, $values, $tags);
1588 xml_parser_free($parser);
1591 $this->_info
['xmp'] = false;
1595 $this->_info
['xmp'] = array();
1596 $count = count($values);
1597 for ($i = 0; $i < $count; $i++
) {
1598 if ($values[$i]['tag'] == 'rdf:Description' && $values[$i]['type'] == 'open') {
1600 while ((++
$i < $count) && ($values[$i]['tag'] != 'rdf:Description')) {
1601 $this->_parseXmpNode($values, $i, $this->_info
['xmp'][$values[$i]['tag']], $count);
1605 } catch (Exception
$e) {
1606 $this->_handleMarkerParsingException($e);
1607 $this->_info
['xmp'] = false;
1615 * Parses XMP nodes by recursion
1617 * @author Hakan Sandell <hakan.sandell@mydata.se>
1619 * @param array $values
1621 * @param mixed $meta
1622 * @param integer $count
1624 function _parseXmpNode($values, &$i, &$meta, $count) {
1625 if ($values[$i]['type'] == 'close') return;
1627 if ($values[$i]['type'] == 'complete') {
1628 // Simple Type property
1629 $meta = $values[$i]['value'] ??
'';
1634 if ($i >= $count) return;
1636 if ($values[$i]['tag'] == 'rdf:Bag' ||
$values[$i]['tag'] == 'rdf:Seq') {
1639 while ($values[++
$i]['tag'] == 'rdf:li') {
1640 $this->_parseXmpNode($values, $i, $meta[], $count);
1642 $i++
; // skip closing Bag/Seq tag
1644 } elseif ($values[$i]['tag'] == 'rdf:Alt') {
1645 // Language Alternative property, only the first (default) value is used
1646 if ($values[$i]['type'] == 'open') {
1648 $this->_parseXmpNode($values, $i, $meta, $count);
1649 while ((++
$i < $count) && ($values[$i]['tag'] != 'rdf:Alt'));
1650 $i++
; // skip closing Alt tag
1654 // Structure property
1656 $startTag = $values[$i-1]['tag'];
1658 $this->_parseXmpNode($values, $i, $meta[$values[$i]['tag']], $count);
1659 } while ((++
$i < $count) && ($values[$i]['tag'] != $startTag));
1663 /*************************************************************/
1664 function _parseMarkerExif() {
1665 if (!isset($this->_markers
)) {
1669 if ($this->_markers
== null ||
$this->_isMarkerDisabled(('exif'))) {
1675 $count = count($this->_markers
);
1676 for ($i = 0; $i < $count; $i++
) {
1677 if ($this->_markers
[$i]['marker'] == 0xE1) {
1678 $signature = $this->_getFixedString($this->_markers
[$i]['data'], 0, 6);
1679 if ($signature == "Exif\0\0") {
1680 $data =& $this->_markers
[$i]['data'];
1686 if ($data == null) {
1687 $this->_info
['exif'] = false;
1691 $this->_info
['exif'] = array();
1693 // We don't increment $pos after this because Exif uses offsets relative to this point
1695 $byteAlign = $this->_getShort($data, $pos +
0);
1697 if ($byteAlign == 0x4949) { // "II"
1698 $isBigEndian = false;
1699 } elseif ($byteAlign == 0x4D4D) { // "MM"
1700 $isBigEndian = true;
1702 return false; // Unexpected data
1705 $alignCheck = $this->_getShort($data, $pos +
2, $isBigEndian);
1706 if ($alignCheck != 0x002A) // That's the expected value
1707 return false; // Unexpected data
1710 $this->_info
['exif']['ByteAlign'] = "Big Endian";
1712 $this->_info
['exif']['ByteAlign'] = "Little Endian";
1715 $offsetIFD0 = $this->_getLong($data, $pos +
4, $isBigEndian);
1716 if ($offsetIFD0 < 8)
1717 return false; // Unexpected data
1719 $offsetIFD1 = $this->_readIFD($data, $pos, $offsetIFD0, $isBigEndian, 'ifd0');
1720 if ($offsetIFD1 != 0)
1721 $this->_readIFD($data, $pos, $offsetIFD1, $isBigEndian, 'ifd1');
1722 } catch(Exception
$e) {
1723 $this->_handleMarkerParsingException($e);
1724 $this->_info
['exif'] = false;
1731 /*************************************************************/
1734 * @param mixed $data
1735 * @param integer $base
1736 * @param integer $offset
1737 * @param boolean $isBigEndian
1738 * @param string $mode
1742 function _readIFD($data, $base, $offset, $isBigEndian, $mode) {
1743 $EXIFTags = $this->_exifTagNames($mode);
1745 $numEntries = $this->_getShort($data, $base +
$offset, $isBigEndian);
1748 $exifTIFFOffset = 0;
1749 $exifTIFFLength = 0;
1750 $exifThumbnailOffset = 0;
1751 $exifThumbnailLength = 0;
1753 for ($i = 0; $i < $numEntries; $i++
) {
1754 $tag = $this->_getShort($data, $base +
$offset, $isBigEndian);
1756 $type = $this->_getShort($data, $base +
$offset, $isBigEndian);
1758 $count = $this->_getLong($data, $base +
$offset, $isBigEndian);
1761 if (($type < 1) ||
($type > 12))
1762 return false; // Unexpected Type
1764 $typeLengths = array( -1, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8 );
1766 $dataLength = $typeLengths[$type] * $count;
1767 if ($dataLength > 4) {
1768 $dataOffset = $this->_getLong($data, $base +
$offset, $isBigEndian);
1769 $rawValue = $this->_getFixedString($data, $base +
$dataOffset, $dataLength);
1771 $rawValue = $this->_getFixedString($data, $base +
$offset, $dataLength);
1778 $value = $this->_getByte($rawValue, 0);
1781 for ($j = 0; $j < $count; $j++
)
1782 $value[$j] = $this->_getByte($rawValue, $j);
1790 $value = $this->_getShort($rawValue, 0, $isBigEndian);
1793 for ($j = 0; $j < $count; $j++
)
1794 $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian);
1799 $value = $this->_getLong($rawValue, 0, $isBigEndian);
1802 for ($j = 0; $j < $count; $j++
)
1803 $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian);
1806 case 5: // URATIONAL
1808 $a = $this->_getLong($rawValue, 0, $isBigEndian);
1809 $b = $this->_getLong($rawValue, 4, $isBigEndian);
1814 if (($a != 0) && ($b != 0)) {
1815 $value['val'] = $a / $b;
1819 for ($j = 0; $j < $count; $j++
) {
1820 $a = $this->_getLong($rawValue, $j * 8, $isBigEndian);
1821 $b = $this->_getLong($rawValue, ($j * 8) +
4, $isBigEndian);
1823 $value[$j]['val'] = 0;
1824 $value[$j]['num'] = $a;
1825 $value[$j]['den'] = $b;
1826 if (($a != 0) && ($b != 0))
1827 $value[$j]['val'] = $a / $b;
1833 $value = $this->_getByte($rawValue, 0);
1836 for ($j = 0; $j < $count; $j++
)
1837 $value[$j] = $this->_getByte($rawValue, $j);
1840 case 7: // UNDEFINED
1845 $value = $this->_getShort($rawValue, 0, $isBigEndian);
1848 for ($j = 0; $j < $count; $j++
)
1849 $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian);
1854 $value = $this->_getLong($rawValue, 0, $isBigEndian);
1857 for ($j = 0; $j < $count; $j++
)
1858 $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian);
1861 case 10: // SRATIONAL
1863 $a = $this->_getLong($rawValue, 0, $isBigEndian);
1864 $b = $this->_getLong($rawValue, 4, $isBigEndian);
1869 if (($a != 0) && ($b != 0))
1870 $value['val'] = $a / $b;
1873 for ($j = 0; $j < $count; $j++
) {
1874 $a = $this->_getLong($rawValue, $j * 8, $isBigEndian);
1875 $b = $this->_getLong($rawValue, ($j * 8) +
4, $isBigEndian);
1877 $value[$j]['val'] = 0;
1878 $value[$j]['num'] = $a;
1879 $value[$j]['den'] = $b;
1880 if (($a != 0) && ($b != 0))
1881 $value[$j]['val'] = $a / $b;
1893 return false; // Unexpected Type
1897 if (($mode == 'ifd0') && ($tag == 0x8769)) { // ExifIFDOffset
1898 $this->_readIFD($data, $base, $value, $isBigEndian, 'exif');
1899 } elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset
1900 $this->_readIFD($data, $base, $value, $isBigEndian, 'gps');
1901 } elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets
1902 $exifTIFFOffset = $value;
1903 } elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts
1904 $exifTIFFLength = $value;
1905 } elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset
1906 $exifThumbnailOffset = $value;
1907 } elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength
1908 $exifThumbnailLength = $value;
1909 } elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset
1910 $this->_readIFD($data, $base, $value, $isBigEndian, 'interop');
1912 // elseif (($mode == 'exif') && ($tag == 0x927C)) { // MakerNote
1915 if (isset($EXIFTags[$tag])) {
1916 $tagName = $EXIFTags[$tag];
1917 if (isset($this->_info
['exif'][$tagName])) {
1918 if (!is_array($this->_info
['exif'][$tagName])) {
1920 $aux[0] = $this->_info
['exif'][$tagName];
1921 $this->_info
['exif'][$tagName] = $aux;
1924 $this->_info
['exif'][$tagName][count($this->_info
['exif'][$tagName])] = $value;
1926 $this->_info
['exif'][$tagName] = $value;
1931 echo sprintf("<h1>Unknown tag %02x (t: %d l: %d) %s in %s</h1>", $tag, $type, $count, $mode, $this->_fileName);
1932 // Unknown Tags will be ignored!!!
1933 // That's because the tag might be a pointer (like the Exif tag)
1934 // and saving it without saving the data it points to might
1935 // create an invalid file.
1941 if (($exifThumbnailOffset > 0) && ($exifThumbnailLength > 0)) {
1942 $this->_info
['exif']['JFIFThumbnail'] = $this->_getFixedString($data, $base +
$exifThumbnailOffset, $exifThumbnailLength);
1945 if (($exifTIFFOffset > 0) && ($exifTIFFLength > 0)) {
1946 $this->_info
['exif']['TIFFStrips'] = $this->_getFixedString($data, $base +
$exifTIFFOffset, $exifTIFFLength);
1949 $nextOffset = $this->_getLong($data, $base +
$offset, $isBigEndian);
1953 /*************************************************************/
1954 function & _createMarkerExif() {
1956 $count = count($this->_markers
);
1957 for ($i = 0; $i < $count; $i++
) {
1958 if ($this->_markers
[$i]['marker'] == 0xE1) {
1959 $signature = $this->_getFixedString($this->_markers
[$i]['data'], 0, 6);
1960 if ($signature == "Exif\0\0") {
1961 $data =& $this->_markers
[$i]['data'];
1967 if (!isset($this->_info
['exif'])) {
1975 if (isset($this->_info
['exif']['ByteAlign']) && ($this->_info
['exif']['ByteAlign'] == "Big Endian")) {
1976 $isBigEndian = true;
1978 $pos = $this->_putString($data, $pos, $aux);
1980 $isBigEndian = false;
1982 $pos = $this->_putString($data, $pos, $aux);
1984 $pos = $this->_putShort($data, $pos, 0x002A, $isBigEndian);
1985 $pos = $this->_putLong($data, $pos, 0x00000008, $isBigEndian); // IFD0 Offset is always 8
1987 $ifd0 =& $this->_getIFDEntries($isBigEndian, 'ifd0');
1988 $ifd1 =& $this->_getIFDEntries($isBigEndian, 'ifd1');
1990 $pos = $this->_writeIFD($data, $pos, $offsetBase, $ifd0, $isBigEndian, true);
1991 $pos = $this->_writeIFD($data, $pos, $offsetBase, $ifd1, $isBigEndian, false);
1996 /*************************************************************/
1999 * @param mixed $data
2000 * @param integer $pos
2001 * @param integer $offsetBase
2002 * @param array $entries
2003 * @param boolean $isBigEndian
2004 * @param boolean $hasNext
2008 function _writeIFD(&$data, $pos, $offsetBase, &$entries, $isBigEndian, $hasNext) {
2010 $tiffDataOffsetPos = -1;
2012 $entryCount = count($entries);
2014 $dataPos = $pos +
2 +
($entryCount * 12) +
4;
2015 $pos = $this->_putShort($data, $pos, $entryCount, $isBigEndian);
2017 for ($i = 0; $i < $entryCount; $i++
) {
2018 $tag = $entries[$i]['tag'];
2019 $type = $entries[$i]['type'];
2021 if ($type == -99) { // SubIFD
2022 $pos = $this->_putShort($data, $pos, $tag, $isBigEndian);
2023 $pos = $this->_putShort($data, $pos, 0x04, $isBigEndian); // LONG
2024 $pos = $this->_putLong($data, $pos, 0x01, $isBigEndian); // Count = 1
2025 $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian);
2027 $dataPos = $this->_writeIFD($data, $dataPos, $offsetBase, $entries[$i]['value'], $isBigEndian, false);
2028 } elseif ($type == -98) { // TIFF Data
2029 $pos = $this->_putShort($data, $pos, $tag, $isBigEndian);
2030 $pos = $this->_putShort($data, $pos, 0x04, $isBigEndian); // LONG
2031 $pos = $this->_putLong($data, $pos, 0x01, $isBigEndian); // Count = 1
2032 $tiffDataOffsetPos = $pos;
2033 $pos = $this->_putLong($data, $pos, 0x00, $isBigEndian); // For Now
2034 $tiffData =& $entries[$i]['value'] ;
2035 } else { // Regular Entry
2036 $pos = $this->_putShort($data, $pos, $tag, $isBigEndian);
2037 $pos = $this->_putShort($data, $pos, $type, $isBigEndian);
2038 $pos = $this->_putLong($data, $pos, $entries[$i]['count'], $isBigEndian);
2039 if (strlen($entries[$i]['value']) > 4) {
2040 $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian);
2041 $dataPos = $this->_putString($data, $dataPos, $entries[$i]['value']);
2043 $val = str_pad($entries[$i]['value'], 4, "\0");
2044 $pos = $this->_putString($data, $pos, $val);
2049 if ($tiffData != null) {
2050 $this->_putLong($data, $tiffDataOffsetPos, $dataPos - $offsetBase, $isBigEndian);
2051 $dataPos = $this->_putString($data, $dataPos, $tiffData);
2055 $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian);
2057 $pos = $this->_putLong($data, $pos, 0, $isBigEndian);
2063 /*************************************************************/
2066 * @param boolean $isBigEndian
2067 * @param string $mode
2071 function & _getIFDEntries($isBigEndian, $mode) {
2072 $EXIFNames = $this->_exifTagNames($mode);
2073 $EXIFTags = $this->_exifNameTags($mode);
2074 $EXIFTypeInfo = $this->_exifTagTypes($mode);
2076 $ifdEntries = array();
2079 foreach($EXIFNames as $tag => $name) {
2080 $type = $EXIFTypeInfo[$tag][0];
2081 $count = $EXIFTypeInfo[$tag][1];
2084 if (($mode == 'ifd0') && ($tag == 0x8769)) { // ExifIFDOffset
2085 if (isset($this->_info
['exif']['EXIFVersion'])) {
2086 $value =& $this->_getIFDEntries($isBigEndian, "exif");
2092 } elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset
2093 if (isset($this->_info
['exif']['GPSVersionID'])) {
2094 $value =& $this->_getIFDEntries($isBigEndian, "gps");
2099 } elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets
2100 if (isset($this->_info
['exif']['TIFFStrips'])) {
2101 $value =& $this->_info
['exif']['TIFFStrips'];
2106 } elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts
2107 if (isset($this->_info
['exif']['TIFFStrips'])) {
2108 $value = strlen($this->_info
['exif']['TIFFStrips']);
2112 } elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset
2113 if (isset($this->_info
['exif']['JFIFThumbnail'])) {
2114 $value =& $this->_info
['exif']['JFIFThumbnail'];
2119 } elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength
2120 if (isset($this->_info
['exif']['JFIFThumbnail'])) {
2121 $value = strlen($this->_info
['exif']['JFIFThumbnail']);
2125 } elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset
2126 if (isset($this->_info
['exif']['InteroperabilityIndex'])) {
2127 $value =& $this->_getIFDEntries($isBigEndian, "interop");
2132 } elseif (isset($this->_info
['exif'][$name])) {
2133 $origValue =& $this->_info
['exif'][$name];
2135 // This makes it easier to process variable size elements
2136 if (!is_array($origValue) ||
isset($origValue['val'])) {
2137 unset($origValue); // Break the reference
2138 $origValue = array($this->_info
['exif'][$name]);
2140 $origCount = count($origValue);
2142 if ($origCount == 0 ) {
2143 $type = -1; // To ignore this field
2151 $count = $origCount;
2155 while (($j < $count) && ($j < $origCount)) {
2157 $this->_putByte($value, $j, $origValue[$j]);
2161 while ($j < $count) {
2162 $this->_putByte($value, $j, 0);
2167 $v = strval($origValue[0]);
2168 if (($count != 0) && (strlen($v) > $count)) {
2169 $v = substr($v, 0, $count);
2171 elseif (($count > 0) && (strlen($v) < $count)) {
2172 $v = str_pad($v, $count, "\0");
2175 $count = strlen($v);
2177 $this->_putString($value, 0, $v);
2181 $count = $origCount;
2185 while (($j < $count) && ($j < $origCount)) {
2186 $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian);
2190 while ($j < $count) {
2191 $this->_putShort($value, $j * 2, 0, $isBigEndian);
2197 $count = $origCount;
2201 while (($j < $count) && ($j < $origCount)) {
2202 $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian);
2206 while ($j < $count) {
2207 $this->_putLong($value, $j * 4, 0, $isBigEndian);
2211 case 5: // URATIONAL
2213 $count = $origCount;
2217 while (($j < $count) && ($j < $origCount)) {
2218 $v = $origValue[$j];
2226 // TODO: Allow other types and convert them
2228 $this->_putLong($value, $j * 8, $a, $isBigEndian);
2229 $this->_putLong($value, ($j * 8) +
4, $b, $isBigEndian);
2233 while ($j < $count) {
2234 $this->_putLong($value, $j * 8, 0, $isBigEndian);
2235 $this->_putLong($value, ($j * 8) +
4, 0, $isBigEndian);
2241 $count = $origCount;
2245 while (($j < $count) && ($j < $origCount)) {
2246 $this->_putByte($value, $j, $origValue[$j]);
2250 while ($j < $count) {
2251 $this->_putByte($value, $j, 0);
2255 case 7: // UNDEFINED
2256 $v = strval($origValue[0]);
2257 if (($count != 0) && (strlen($v) > $count)) {
2258 $v = substr($v, 0, $count);
2260 elseif (($count > 0) && (strlen($v) < $count)) {
2261 $v = str_pad($v, $count, "\0");
2264 $count = strlen($v);
2266 $this->_putString($value, 0, $v);
2270 $count = $origCount;
2274 while (($j < $count) && ($j < $origCount)) {
2275 $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian);
2279 while ($j < $count) {
2280 $this->_putShort($value, $j * 2, 0, $isBigEndian);
2286 $count = $origCount;
2290 while (($j < $count) && ($j < $origCount)) {
2291 $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian);
2295 while ($j < $count) {
2296 $this->_putLong($value, $j * 4, 0, $isBigEndian);
2300 case 10: // SRATIONAL
2302 $count = $origCount;
2306 while (($j < $count) && ($j < $origCount)) {
2307 $v = $origValue[$j];
2315 // TODO: Allow other types and convert them
2318 $this->_putLong($value, $j * 8, $a, $isBigEndian);
2319 $this->_putLong($value, ($j * 8) +
4, $b, $isBigEndian);
2323 while ($j < $count) {
2324 $this->_putLong($value, $j * 8, 0, $isBigEndian);
2325 $this->_putLong($value, ($j * 8) +
4, 0, $isBigEndian);
2331 $count = $origCount;
2335 while (($j < $count) && ($j < $origCount)) {
2336 $v = strval($origValue[$j]);
2337 if (strlen($v) > 4) {
2338 $v = substr($v, 0, 4);
2340 elseif (strlen($v) < 4) {
2341 $v = str_pad($v, 4, "\0");
2343 $this->_putString($value, $j * 4, $v);
2347 while ($j < $count) {
2349 $this->_putString($value, $j * 4, $v);
2355 $count = $origCount;
2359 while (($j < $count) && ($j < $origCount)) {
2360 $v = strval($origValue[$j]);
2361 if (strlen($v) > 8) {
2362 $v = substr($v, 0, 8);
2364 elseif (strlen($v) < 8) {
2365 $v = str_pad($v, 8, "\0");
2367 $this->_putString($value, $j * 8, $v);
2371 while ($j < $count) {
2372 $v = "\0\0\0\0\0\0\0\0";
2373 $this->_putString($value, $j * 8, $v);
2383 if ($value != null) {
2384 $ifdEntries[$entryCount] = array();
2385 $ifdEntries[$entryCount]['tag'] = $tag;
2386 $ifdEntries[$entryCount]['type'] = $type;
2387 $ifdEntries[$entryCount]['count'] = $count;
2388 $ifdEntries[$entryCount]['value'] = $value;
2396 /*************************************************************/
2397 function _handleMarkerParsingException($e) {
2398 \dokuwiki\ErrorHandler
::logException($e, $this->_fileName
);
2401 /*************************************************************/
2402 function _isMarkerDisabled($name) {
2403 if (!isset($this->_info
)) return false;
2404 return isset($this->_info
[$name]) && $this->_info
[$name] === false;
2407 /*************************************************************/
2408 function _parseMarkerAdobe() {
2409 if (!isset($this->_markers
)) {
2413 if ($this->_markers
== null ||
$this->_isMarkerDisabled('adobe')) {
2418 $count = count($this->_markers
);
2419 for ($i = 0; $i < $count; $i++
) {
2420 if ($this->_markers
[$i]['marker'] == 0xED) {
2421 $signature = $this->_getFixedString($this->_markers
[$i]['data'], 0, 14);
2422 if ($signature == "Photoshop 3.0\0") {
2423 $data =& $this->_markers
[$i]['data'];
2429 if ($data == null) {
2430 $this->_info
['adobe'] = false;
2431 $this->_info
['iptc'] = false;
2435 $this->_info
['adobe'] = array();
2436 $this->_info
['adobe']['raw'] = array();
2437 $this->_info
['iptc'] = array();
2439 $datasize = strlen($data);
2441 while ($pos < $datasize) {
2442 $signature = $this->_getFixedString($data, $pos, 4);
2443 if ($signature != '8BIM')
2447 $type = $this->_getShort($data, $pos);
2450 $strlen = $this->_getByte($data, $pos);
2453 for ($i = 0; $i < $strlen; $i++
) {
2454 $header .= $data[$pos +
$i];
2456 $pos +
= $strlen +
1 - ($strlen %
2); // The string is padded to even length, counting the length byte itself
2458 $length = $this->_getLong($data, $pos);
2464 case 0x0404: // Caption (IPTC Data)
2465 $pos = $this->_readIPTC($data, $pos);
2469 case 0x040A: // CopyrightFlag
2470 $this->_info
['adobe']['CopyrightFlag'] = $this->_getByte($data, $pos);
2473 case 0x040B: // ImageURL
2474 $this->_info
['adobe']['ImageURL'] = $this->_getFixedString($data, $pos, $length);
2477 case 0x040C: // Thumbnail
2478 $aux = $this->_getLong($data, $pos);
2481 $this->_info
['adobe']['ThumbnailWidth'] = $this->_getLong($data, $pos);
2483 $this->_info
['adobe']['ThumbnailHeight'] = $this->_getLong($data, $pos);
2486 $pos +
= 16; // Skip some data
2488 $this->_info
['adobe']['ThumbnailData'] = $this->_getFixedString($data, $pos, $length - 28);
2489 $pos +
= $length - 28;
2496 // We save all blocks, even those we recognized
2497 $label = sprintf('8BIM_0x%04x', $type);
2498 $this->_info
['adobe']['raw'][$label] = array();
2499 $this->_info
['adobe']['raw'][$label]['type'] = $type;
2500 $this->_info
['adobe']['raw'][$label]['header'] = $header;
2501 $this->_info
['adobe']['raw'][$label]['data'] =& $this->_getFixedString($data, $basePos, $length);
2503 $pos = $basePos +
$length +
($length %
2); // Even padding
2505 } catch(Exception
$e) {
2506 $this->_handleMarkerParsingException($e);
2507 $this->_info
['adobe'] = false;
2508 $this->_info
['iptc'] = false;
2513 /*************************************************************/
2514 function _readIPTC(&$data, $pos = 0) {
2515 $totalLength = strlen($data);
2517 $IPTCTags = $this->_iptcTagNames();
2519 while ($pos < ($totalLength - 5)) {
2520 $signature = $this->_getShort($data, $pos);
2521 if ($signature != 0x1C02)
2525 $type = $this->_getByte($data, $pos);
2527 $length = $this->_getShort($data, $pos);
2533 if (isset($IPTCTags[$type])) {
2534 $label = $IPTCTags[$type];
2536 $label = sprintf('IPTC_0x%02x', $type);
2540 if (isset($this->_info
['iptc'][$label])) {
2541 if (!is_array($this->_info
['iptc'][$label])) {
2543 $aux[0] = $this->_info
['iptc'][$label];
2544 $this->_info
['iptc'][$label] = $aux;
2546 $this->_info
['iptc'][$label][ count($this->_info
['iptc'][$label]) ] = $this->_getFixedString($data, $pos, $length);
2548 $this->_info
['iptc'][$label] = $this->_getFixedString($data, $pos, $length);
2552 $pos = $basePos +
$length; // No padding
2557 /*************************************************************/
2558 function & _createMarkerAdobe() {
2559 if (isset($this->_info
['iptc'])) {
2560 if (!isset($this->_info
['adobe'])) {
2561 $this->_info
['adobe'] = array();
2563 if (!isset($this->_info
['adobe']['raw'])) {
2564 $this->_info
['adobe']['raw'] = array();
2566 if (!isset($this->_info
['adobe']['raw']['8BIM_0x0404'])) {
2567 $this->_info
['adobe']['raw']['8BIM_0x0404'] = array();
2569 $this->_info
['adobe']['raw']['8BIM_0x0404']['type'] = 0x0404;
2570 $this->_info
['adobe']['raw']['8BIM_0x0404']['header'] = "Caption";
2571 $this->_info
['adobe']['raw']['8BIM_0x0404']['data'] =& $this->_writeIPTC();
2574 if (isset($this->_info
['adobe']['raw']) && (count($this->_info
['adobe']['raw']) > 0)) {
2575 $data = "Photoshop 3.0\0";
2578 reset($this->_info
['adobe']['raw']);
2579 foreach ($this->_info
['adobe']['raw'] as $value){
2580 $pos = $this->_write8BIM(
2592 /*************************************************************/
2595 * @param mixed $data
2596 * @param integer $pos
2598 * @param string $type
2599 * @param string $header
2600 * @param mixed $value
2604 function _write8BIM(&$data, $pos, $type, $header, &$value) {
2605 $signature = "8BIM";
2607 $pos = $this->_putString($data, $pos, $signature);
2608 $pos = $this->_putShort($data, $pos, $type);
2610 $len = strlen($header);
2612 $pos = $this->_putByte($data, $pos, $len);
2613 $pos = $this->_putString($data, $pos, $header);
2614 if (($len %
2) == 0) { // Even padding, including the length byte
2615 $pos = $this->_putByte($data, $pos, 0);
2618 $len = strlen($value);
2619 $pos = $this->_putLong($data, $pos, $len);
2620 $pos = $this->_putString($data, $pos, $value);
2621 if (($len %
2) != 0) { // Even padding
2622 $pos = $this->_putByte($data, $pos, 0);
2627 /*************************************************************/
2628 function & _writeIPTC() {
2632 $IPTCNames =& $this->_iptcNameTags();
2634 foreach($this->_info
['iptc'] as $label => $value) {
2635 $value =& $this->_info
['iptc'][$label];
2638 if (isset($IPTCNames[$label])) {
2639 $type = $IPTCNames[$label];
2641 elseif (substr($label, 0, 7) == "IPTC_0x") {
2642 $type = hexdec(substr($label, 7, 2));
2646 if (is_array($value)) {
2647 $vcnt = count($value);
2648 for ($i = 0; $i < $vcnt; $i++
) {
2649 $pos = $this->_writeIPTCEntry($data, $pos, $type, $value[$i]);
2653 $pos = $this->_writeIPTCEntry($data, $pos, $type, $value);
2661 /*************************************************************/
2664 * @param mixed $data
2665 * @param integer $pos
2667 * @param string $type
2668 * @param mixed $value
2672 function _writeIPTCEntry(&$data, $pos, $type, &$value) {
2673 $pos = $this->_putShort($data, $pos, 0x1C02);
2674 $pos = $this->_putByte($data, $pos, $type);
2675 $pos = $this->_putShort($data, $pos, strlen($value));
2676 $pos = $this->_putString($data, $pos, $value);
2681 /*************************************************************/
2682 function _exifTagNames($mode) {
2685 if ($mode == 'ifd0') {
2686 $tags[0x010E] = 'ImageDescription';
2687 $tags[0x010F] = 'Make';
2688 $tags[0x0110] = 'Model';
2689 $tags[0x0112] = 'Orientation';
2690 $tags[0x011A] = 'XResolution';
2691 $tags[0x011B] = 'YResolution';
2692 $tags[0x0128] = 'ResolutionUnit';
2693 $tags[0x0131] = 'Software';
2694 $tags[0x0132] = 'DateTime';
2695 $tags[0x013B] = 'Artist';
2696 $tags[0x013E] = 'WhitePoint';
2697 $tags[0x013F] = 'PrimaryChromaticities';
2698 $tags[0x0211] = 'YCbCrCoefficients';
2699 $tags[0x0212] = 'YCbCrSubSampling';
2700 $tags[0x0213] = 'YCbCrPositioning';
2701 $tags[0x0214] = 'ReferenceBlackWhite';
2702 $tags[0x8298] = 'Copyright';
2703 $tags[0x8769] = 'ExifIFDOffset';
2704 $tags[0x8825] = 'GPSIFDOffset';
2706 if ($mode == 'ifd1') {
2707 $tags[0x00FE] = 'TIFFNewSubfileType';
2708 $tags[0x00FF] = 'TIFFSubfileType';
2709 $tags[0x0100] = 'TIFFImageWidth';
2710 $tags[0x0101] = 'TIFFImageHeight';
2711 $tags[0x0102] = 'TIFFBitsPerSample';
2712 $tags[0x0103] = 'TIFFCompression';
2713 $tags[0x0106] = 'TIFFPhotometricInterpretation';
2714 $tags[0x0107] = 'TIFFThreshholding';
2715 $tags[0x0108] = 'TIFFCellWidth';
2716 $tags[0x0109] = 'TIFFCellLength';
2717 $tags[0x010A] = 'TIFFFillOrder';
2718 $tags[0x010E] = 'TIFFImageDescription';
2719 $tags[0x010F] = 'TIFFMake';
2720 $tags[0x0110] = 'TIFFModel';
2721 $tags[0x0111] = 'TIFFStripOffsets';
2722 $tags[0x0112] = 'TIFFOrientation';
2723 $tags[0x0115] = 'TIFFSamplesPerPixel';
2724 $tags[0x0116] = 'TIFFRowsPerStrip';
2725 $tags[0x0117] = 'TIFFStripByteCounts';
2726 $tags[0x0118] = 'TIFFMinSampleValue';
2727 $tags[0x0119] = 'TIFFMaxSampleValue';
2728 $tags[0x011A] = 'TIFFXResolution';
2729 $tags[0x011B] = 'TIFFYResolution';
2730 $tags[0x011C] = 'TIFFPlanarConfiguration';
2731 $tags[0x0122] = 'TIFFGrayResponseUnit';
2732 $tags[0x0123] = 'TIFFGrayResponseCurve';
2733 $tags[0x0128] = 'TIFFResolutionUnit';
2734 $tags[0x0131] = 'TIFFSoftware';
2735 $tags[0x0132] = 'TIFFDateTime';
2736 $tags[0x013B] = 'TIFFArtist';
2737 $tags[0x013C] = 'TIFFHostComputer';
2738 $tags[0x0140] = 'TIFFColorMap';
2739 $tags[0x0152] = 'TIFFExtraSamples';
2740 $tags[0x0201] = 'TIFFJFIFOffset';
2741 $tags[0x0202] = 'TIFFJFIFLength';
2742 $tags[0x0211] = 'TIFFYCbCrCoefficients';
2743 $tags[0x0212] = 'TIFFYCbCrSubSampling';
2744 $tags[0x0213] = 'TIFFYCbCrPositioning';
2745 $tags[0x0214] = 'TIFFReferenceBlackWhite';
2746 $tags[0x8298] = 'TIFFCopyright';
2747 $tags[0x9286] = 'TIFFUserComment';
2748 } elseif ($mode == 'exif') {
2749 $tags[0x829A] = 'ExposureTime';
2750 $tags[0x829D] = 'FNumber';
2751 $tags[0x8822] = 'ExposureProgram';
2752 $tags[0x8824] = 'SpectralSensitivity';
2753 $tags[0x8827] = 'ISOSpeedRatings';
2754 $tags[0x8828] = 'OECF';
2755 $tags[0x9000] = 'EXIFVersion';
2756 $tags[0x9003] = 'DateTimeOriginal';
2757 $tags[0x9004] = 'DateTimeDigitized';
2758 $tags[0x9101] = 'ComponentsConfiguration';
2759 $tags[0x9102] = 'CompressedBitsPerPixel';
2760 $tags[0x9201] = 'ShutterSpeedValue';
2761 $tags[0x9202] = 'ApertureValue';
2762 $tags[0x9203] = 'BrightnessValue';
2763 $tags[0x9204] = 'ExposureBiasValue';
2764 $tags[0x9205] = 'MaxApertureValue';
2765 $tags[0x9206] = 'SubjectDistance';
2766 $tags[0x9207] = 'MeteringMode';
2767 $tags[0x9208] = 'LightSource';
2768 $tags[0x9209] = 'Flash';
2769 $tags[0x920A] = 'FocalLength';
2770 $tags[0x927C] = 'MakerNote';
2771 $tags[0x9286] = 'UserComment';
2772 $tags[0x9290] = 'SubSecTime';
2773 $tags[0x9291] = 'SubSecTimeOriginal';
2774 $tags[0x9292] = 'SubSecTimeDigitized';
2775 $tags[0xA000] = 'FlashPixVersion';
2776 $tags[0xA001] = 'ColorSpace';
2777 $tags[0xA002] = 'PixelXDimension';
2778 $tags[0xA003] = 'PixelYDimension';
2779 $tags[0xA004] = 'RelatedSoundFile';
2780 $tags[0xA005] = 'InteropIFDOffset';
2781 $tags[0xA20B] = 'FlashEnergy';
2782 $tags[0xA20C] = 'SpatialFrequencyResponse';
2783 $tags[0xA20E] = 'FocalPlaneXResolution';
2784 $tags[0xA20F] = 'FocalPlaneYResolution';
2785 $tags[0xA210] = 'FocalPlaneResolutionUnit';
2786 $tags[0xA214] = 'SubjectLocation';
2787 $tags[0xA215] = 'ExposureIndex';
2788 $tags[0xA217] = 'SensingMethod';
2789 $tags[0xA300] = 'FileSource';
2790 $tags[0xA301] = 'SceneType';
2791 $tags[0xA302] = 'CFAPattern';
2792 } elseif ($mode == 'interop') {
2793 $tags[0x0001] = 'InteroperabilityIndex';
2794 $tags[0x0002] = 'InteroperabilityVersion';
2795 $tags[0x1000] = 'RelatedImageFileFormat';
2796 $tags[0x1001] = 'RelatedImageWidth';
2797 $tags[0x1002] = 'RelatedImageLength';
2798 } elseif ($mode == 'gps') {
2799 $tags[0x0000] = 'GPSVersionID';
2800 $tags[0x0001] = 'GPSLatitudeRef';
2801 $tags[0x0002] = 'GPSLatitude';
2802 $tags[0x0003] = 'GPSLongitudeRef';
2803 $tags[0x0004] = 'GPSLongitude';
2804 $tags[0x0005] = 'GPSAltitudeRef';
2805 $tags[0x0006] = 'GPSAltitude';
2806 $tags[0x0007] = 'GPSTimeStamp';
2807 $tags[0x0008] = 'GPSSatellites';
2808 $tags[0x0009] = 'GPSStatus';
2809 $tags[0x000A] = 'GPSMeasureMode';
2810 $tags[0x000B] = 'GPSDOP';
2811 $tags[0x000C] = 'GPSSpeedRef';
2812 $tags[0x000D] = 'GPSSpeed';
2813 $tags[0x000E] = 'GPSTrackRef';
2814 $tags[0x000F] = 'GPSTrack';
2815 $tags[0x0010] = 'GPSImgDirectionRef';
2816 $tags[0x0011] = 'GPSImgDirection';
2817 $tags[0x0012] = 'GPSMapDatum';
2818 $tags[0x0013] = 'GPSDestLatitudeRef';
2819 $tags[0x0014] = 'GPSDestLatitude';
2820 $tags[0x0015] = 'GPSDestLongitudeRef';
2821 $tags[0x0016] = 'GPSDestLongitude';
2822 $tags[0x0017] = 'GPSDestBearingRef';
2823 $tags[0x0018] = 'GPSDestBearing';
2824 $tags[0x0019] = 'GPSDestDistanceRef';
2825 $tags[0x001A] = 'GPSDestDistance';
2831 /*************************************************************/
2832 function _exifTagTypes($mode) {
2835 if ($mode == 'ifd0') {
2836 $tags[0x010E] = array(2, 0); // ImageDescription -> ASCII, Any
2837 $tags[0x010F] = array(2, 0); // Make -> ASCII, Any
2838 $tags[0x0110] = array(2, 0); // Model -> ASCII, Any
2839 $tags[0x0112] = array(3, 1); // Orientation -> SHORT, 1
2840 $tags[0x011A] = array(5, 1); // XResolution -> RATIONAL, 1
2841 $tags[0x011B] = array(5, 1); // YResolution -> RATIONAL, 1
2842 $tags[0x0128] = array(3, 1); // ResolutionUnit -> SHORT
2843 $tags[0x0131] = array(2, 0); // Software -> ASCII, Any
2844 $tags[0x0132] = array(2, 20); // DateTime -> ASCII, 20
2845 $tags[0x013B] = array(2, 0); // Artist -> ASCII, Any
2846 $tags[0x013E] = array(5, 2); // WhitePoint -> RATIONAL, 2
2847 $tags[0x013F] = array(5, 6); // PrimaryChromaticities -> RATIONAL, 6
2848 $tags[0x0211] = array(5, 3); // YCbCrCoefficients -> RATIONAL, 3
2849 $tags[0x0212] = array(3, 2); // YCbCrSubSampling -> SHORT, 2
2850 $tags[0x0213] = array(3, 1); // YCbCrPositioning -> SHORT, 1
2851 $tags[0x0214] = array(5, 6); // ReferenceBlackWhite -> RATIONAL, 6
2852 $tags[0x8298] = array(2, 0); // Copyright -> ASCII, Any
2853 $tags[0x8769] = array(4, 1); // ExifIFDOffset -> LONG, 1
2854 $tags[0x8825] = array(4, 1); // GPSIFDOffset -> LONG, 1
2856 if ($mode == 'ifd1') {
2857 $tags[0x00FE] = array(4, 1); // TIFFNewSubfileType -> LONG, 1
2858 $tags[0x00FF] = array(3, 1); // TIFFSubfileType -> SHORT, 1
2859 $tags[0x0100] = array(4, 1); // TIFFImageWidth -> LONG (or SHORT), 1
2860 $tags[0x0101] = array(4, 1); // TIFFImageHeight -> LONG (or SHORT), 1
2861 $tags[0x0102] = array(3, 3); // TIFFBitsPerSample -> SHORT, 3
2862 $tags[0x0103] = array(3, 1); // TIFFCompression -> SHORT, 1
2863 $tags[0x0106] = array(3, 1); // TIFFPhotometricInterpretation -> SHORT, 1
2864 $tags[0x0107] = array(3, 1); // TIFFThreshholding -> SHORT, 1
2865 $tags[0x0108] = array(3, 1); // TIFFCellWidth -> SHORT, 1
2866 $tags[0x0109] = array(3, 1); // TIFFCellLength -> SHORT, 1
2867 $tags[0x010A] = array(3, 1); // TIFFFillOrder -> SHORT, 1
2868 $tags[0x010E] = array(2, 0); // TIFFImageDescription -> ASCII, Any
2869 $tags[0x010F] = array(2, 0); // TIFFMake -> ASCII, Any
2870 $tags[0x0110] = array(2, 0); // TIFFModel -> ASCII, Any
2871 $tags[0x0111] = array(4, 0); // TIFFStripOffsets -> LONG (or SHORT), Any (one per strip)
2872 $tags[0x0112] = array(3, 1); // TIFFOrientation -> SHORT, 1
2873 $tags[0x0115] = array(3, 1); // TIFFSamplesPerPixel -> SHORT, 1
2874 $tags[0x0116] = array(4, 1); // TIFFRowsPerStrip -> LONG (or SHORT), 1
2875 $tags[0x0117] = array(4, 0); // TIFFStripByteCounts -> LONG (or SHORT), Any (one per strip)
2876 $tags[0x0118] = array(3, 0); // TIFFMinSampleValue -> SHORT, Any (SamplesPerPixel)
2877 $tags[0x0119] = array(3, 0); // TIFFMaxSampleValue -> SHORT, Any (SamplesPerPixel)
2878 $tags[0x011A] = array(5, 1); // TIFFXResolution -> RATIONAL, 1
2879 $tags[0x011B] = array(5, 1); // TIFFYResolution -> RATIONAL, 1
2880 $tags[0x011C] = array(3, 1); // TIFFPlanarConfiguration -> SHORT, 1
2881 $tags[0x0122] = array(3, 1); // TIFFGrayResponseUnit -> SHORT, 1
2882 $tags[0x0123] = array(3, 0); // TIFFGrayResponseCurve -> SHORT, Any (2^BitsPerSample)
2883 $tags[0x0128] = array(3, 1); // TIFFResolutionUnit -> SHORT, 1
2884 $tags[0x0131] = array(2, 0); // TIFFSoftware -> ASCII, Any
2885 $tags[0x0132] = array(2, 20); // TIFFDateTime -> ASCII, 20
2886 $tags[0x013B] = array(2, 0); // TIFFArtist -> ASCII, Any
2887 $tags[0x013C] = array(2, 0); // TIFFHostComputer -> ASCII, Any
2888 $tags[0x0140] = array(3, 0); // TIFFColorMap -> SHORT, Any (3 * 2^BitsPerSample)
2889 $tags[0x0152] = array(3, 0); // TIFFExtraSamples -> SHORT, Any (SamplesPerPixel - 3)
2890 $tags[0x0201] = array(4, 1); // TIFFJFIFOffset -> LONG, 1
2891 $tags[0x0202] = array(4, 1); // TIFFJFIFLength -> LONG, 1
2892 $tags[0x0211] = array(5, 3); // TIFFYCbCrCoefficients -> RATIONAL, 3
2893 $tags[0x0212] = array(3, 2); // TIFFYCbCrSubSampling -> SHORT, 2
2894 $tags[0x0213] = array(3, 1); // TIFFYCbCrPositioning -> SHORT, 1
2895 $tags[0x0214] = array(5, 6); // TIFFReferenceBlackWhite -> RATIONAL, 6
2896 $tags[0x8298] = array(2, 0); // TIFFCopyright -> ASCII, Any
2897 $tags[0x9286] = array(2, 0); // TIFFUserComment -> ASCII, Any
2898 } elseif ($mode == 'exif') {
2899 $tags[0x829A] = array(5, 1); // ExposureTime -> RATIONAL, 1
2900 $tags[0x829D] = array(5, 1); // FNumber -> RATIONAL, 1
2901 $tags[0x8822] = array(3, 1); // ExposureProgram -> SHORT, 1
2902 $tags[0x8824] = array(2, 0); // SpectralSensitivity -> ASCII, Any
2903 $tags[0x8827] = array(3, 0); // ISOSpeedRatings -> SHORT, Any
2904 $tags[0x8828] = array(7, 0); // OECF -> UNDEFINED, Any
2905 $tags[0x9000] = array(7, 4); // EXIFVersion -> UNDEFINED, 4
2906 $tags[0x9003] = array(2, 20); // DateTimeOriginal -> ASCII, 20
2907 $tags[0x9004] = array(2, 20); // DateTimeDigitized -> ASCII, 20
2908 $tags[0x9101] = array(7, 4); // ComponentsConfiguration -> UNDEFINED, 4
2909 $tags[0x9102] = array(5, 1); // CompressedBitsPerPixel -> RATIONAL, 1
2910 $tags[0x9201] = array(10, 1); // ShutterSpeedValue -> SRATIONAL, 1
2911 $tags[0x9202] = array(5, 1); // ApertureValue -> RATIONAL, 1
2912 $tags[0x9203] = array(10, 1); // BrightnessValue -> SRATIONAL, 1
2913 $tags[0x9204] = array(10, 1); // ExposureBiasValue -> SRATIONAL, 1
2914 $tags[0x9205] = array(5, 1); // MaxApertureValue -> RATIONAL, 1
2915 $tags[0x9206] = array(5, 1); // SubjectDistance -> RATIONAL, 1
2916 $tags[0x9207] = array(3, 1); // MeteringMode -> SHORT, 1
2917 $tags[0x9208] = array(3, 1); // LightSource -> SHORT, 1
2918 $tags[0x9209] = array(3, 1); // Flash -> SHORT, 1
2919 $tags[0x920A] = array(5, 1); // FocalLength -> RATIONAL, 1
2920 $tags[0x927C] = array(7, 0); // MakerNote -> UNDEFINED, Any
2921 $tags[0x9286] = array(7, 0); // UserComment -> UNDEFINED, Any
2922 $tags[0x9290] = array(2, 0); // SubSecTime -> ASCII, Any
2923 $tags[0x9291] = array(2, 0); // SubSecTimeOriginal -> ASCII, Any
2924 $tags[0x9292] = array(2, 0); // SubSecTimeDigitized -> ASCII, Any
2925 $tags[0xA000] = array(7, 4); // FlashPixVersion -> UNDEFINED, 4
2926 $tags[0xA001] = array(3, 1); // ColorSpace -> SHORT, 1
2927 $tags[0xA002] = array(4, 1); // PixelXDimension -> LONG (or SHORT), 1
2928 $tags[0xA003] = array(4, 1); // PixelYDimension -> LONG (or SHORT), 1
2929 $tags[0xA004] = array(2, 13); // RelatedSoundFile -> ASCII, 13
2930 $tags[0xA005] = array(4, 1); // InteropIFDOffset -> LONG, 1
2931 $tags[0xA20B] = array(5, 1); // FlashEnergy -> RATIONAL, 1
2932 $tags[0xA20C] = array(7, 0); // SpatialFrequencyResponse -> UNDEFINED, Any
2933 $tags[0xA20E] = array(5, 1); // FocalPlaneXResolution -> RATIONAL, 1
2934 $tags[0xA20F] = array(5, 1); // FocalPlaneYResolution -> RATIONAL, 1
2935 $tags[0xA210] = array(3, 1); // FocalPlaneResolutionUnit -> SHORT, 1
2936 $tags[0xA214] = array(3, 2); // SubjectLocation -> SHORT, 2
2937 $tags[0xA215] = array(5, 1); // ExposureIndex -> RATIONAL, 1
2938 $tags[0xA217] = array(3, 1); // SensingMethod -> SHORT, 1
2939 $tags[0xA300] = array(7, 1); // FileSource -> UNDEFINED, 1
2940 $tags[0xA301] = array(7, 1); // SceneType -> UNDEFINED, 1
2941 $tags[0xA302] = array(7, 0); // CFAPattern -> UNDEFINED, Any
2942 } elseif ($mode == 'interop') {
2943 $tags[0x0001] = array(2, 0); // InteroperabilityIndex -> ASCII, Any
2944 $tags[0x0002] = array(7, 4); // InteroperabilityVersion -> UNKNOWN, 4
2945 $tags[0x1000] = array(2, 0); // RelatedImageFileFormat -> ASCII, Any
2946 $tags[0x1001] = array(4, 1); // RelatedImageWidth -> LONG (or SHORT), 1
2947 $tags[0x1002] = array(4, 1); // RelatedImageLength -> LONG (or SHORT), 1
2948 } elseif ($mode == 'gps') {
2949 $tags[0x0000] = array(1, 4); // GPSVersionID -> BYTE, 4
2950 $tags[0x0001] = array(2, 2); // GPSLatitudeRef -> ASCII, 2
2951 $tags[0x0002] = array(5, 3); // GPSLatitude -> RATIONAL, 3
2952 $tags[0x0003] = array(2, 2); // GPSLongitudeRef -> ASCII, 2
2953 $tags[0x0004] = array(5, 3); // GPSLongitude -> RATIONAL, 3
2954 $tags[0x0005] = array(2, 2); // GPSAltitudeRef -> ASCII, 2
2955 $tags[0x0006] = array(5, 1); // GPSAltitude -> RATIONAL, 1
2956 $tags[0x0007] = array(5, 3); // GPSTimeStamp -> RATIONAL, 3
2957 $tags[0x0008] = array(2, 0); // GPSSatellites -> ASCII, Any
2958 $tags[0x0009] = array(2, 2); // GPSStatus -> ASCII, 2
2959 $tags[0x000A] = array(2, 2); // GPSMeasureMode -> ASCII, 2
2960 $tags[0x000B] = array(5, 1); // GPSDOP -> RATIONAL, 1
2961 $tags[0x000C] = array(2, 2); // GPSSpeedRef -> ASCII, 2
2962 $tags[0x000D] = array(5, 1); // GPSSpeed -> RATIONAL, 1
2963 $tags[0x000E] = array(2, 2); // GPSTrackRef -> ASCII, 2
2964 $tags[0x000F] = array(5, 1); // GPSTrack -> RATIONAL, 1
2965 $tags[0x0010] = array(2, 2); // GPSImgDirectionRef -> ASCII, 2
2966 $tags[0x0011] = array(5, 1); // GPSImgDirection -> RATIONAL, 1
2967 $tags[0x0012] = array(2, 0); // GPSMapDatum -> ASCII, Any
2968 $tags[0x0013] = array(2, 2); // GPSDestLatitudeRef -> ASCII, 2
2969 $tags[0x0014] = array(5, 3); // GPSDestLatitude -> RATIONAL, 3
2970 $tags[0x0015] = array(2, 2); // GPSDestLongitudeRef -> ASCII, 2
2971 $tags[0x0016] = array(5, 3); // GPSDestLongitude -> RATIONAL, 3
2972 $tags[0x0017] = array(2, 2); // GPSDestBearingRef -> ASCII, 2
2973 $tags[0x0018] = array(5, 1); // GPSDestBearing -> RATIONAL, 1
2974 $tags[0x0019] = array(2, 2); // GPSDestDistanceRef -> ASCII, 2
2975 $tags[0x001A] = array(5, 1); // GPSDestDistance -> RATIONAL, 1
2981 /*************************************************************/
2982 function _exifNameTags($mode) {
2983 $tags = $this->_exifTagNames($mode);
2984 return $this->_names2Tags($tags);
2987 /*************************************************************/
2988 function _iptcTagNames() {
2990 $tags[0x14] = 'SuplementalCategories';
2991 $tags[0x19] = 'Keywords';
2992 $tags[0x78] = 'Caption';
2993 $tags[0x7A] = 'CaptionWriter';
2994 $tags[0x69] = 'Headline';
2995 $tags[0x28] = 'SpecialInstructions';
2996 $tags[0x0F] = 'Category';
2997 $tags[0x50] = 'Byline';
2998 $tags[0x55] = 'BylineTitle';
2999 $tags[0x6E] = 'Credit';
3000 $tags[0x73] = 'Source';
3001 $tags[0x74] = 'CopyrightNotice';
3002 $tags[0x05] = 'ObjectName';
3003 $tags[0x5A] = 'City';
3004 $tags[0x5C] = 'Sublocation';
3005 $tags[0x5F] = 'ProvinceState';
3006 $tags[0x65] = 'CountryName';
3007 $tags[0x67] = 'OriginalTransmissionReference';
3008 $tags[0x37] = 'DateCreated';
3009 $tags[0x0A] = 'CopyrightFlag';
3014 /*************************************************************/
3015 function & _iptcNameTags() {
3016 $tags = $this->_iptcTagNames();
3017 return $this->_names2Tags($tags);
3020 /*************************************************************/
3021 function _names2Tags($tags2Names) {
3022 $names2Tags = array();
3024 foreach($tags2Names as $tag => $name) {
3025 $names2Tags[$name] = $tag;
3031 /*************************************************************/
3035 * @param integer $pos
3039 function _getByte(&$data, $pos) {
3040 if (!isset($data[$pos])) {
3041 throw new Exception("Requested byte at ".$pos.". Reading outside of file's boundaries.");
3044 return ord($data[$pos]);
3047 /*************************************************************/
3050 * @param mixed $data
3051 * @param integer $pos
3057 function _putByte(&$data, $pos, $val) {
3058 $val = intval($val);
3060 $data[$pos] = chr($val);
3065 /*************************************************************/
3066 function _getShort(&$data, $pos, $bigEndian = true) {
3067 if (!isset($data[$pos]) ||
!isset($data[$pos +
1])) {
3068 throw new Exception("Requested short at ".$pos.". Reading outside of file's boundaries.");
3072 return (ord($data[$pos]) << 8)
3073 +
ord($data[$pos +
1]);
3075 return ord($data[$pos])
3076 +
(ord($data[$pos +
1]) << 8);
3080 /*************************************************************/
3081 function _putShort(&$data, $pos = 0, $val = 0, $bigEndian = true) {
3082 $val = intval($val);
3085 $data[$pos +
0] = chr(($val & 0x0000FF00) >> 8);
3086 $data[$pos +
1] = chr(($val & 0x000000FF) >> 0);
3088 $data[$pos +
0] = chr(($val & 0x00FF) >> 0);
3089 $data[$pos +
1] = chr(($val & 0xFF00) >> 8);
3095 /*************************************************************/
3098 * @param mixed $data
3099 * @param integer $pos
3101 * @param bool $bigEndian
3105 function _getLong(&$data, $pos, $bigEndian = true) {
3106 // Assume that if the start and end bytes are defined, the bytes inbetween are defined as well.
3107 if (!isset($data[$pos]) ||
!isset($data[$pos +
3])){
3108 throw new Exception("Requested long at ".$pos.". Reading outside of file's boundaries.");
3111 return (ord($data[$pos]) << 24)
3112 +
(ord($data[$pos +
1]) << 16)
3113 +
(ord($data[$pos +
2]) << 8)
3114 +
ord($data[$pos +
3]);
3116 return ord($data[$pos])
3117 +
(ord($data[$pos +
1]) << 8)
3118 +
(ord($data[$pos +
2]) << 16)
3119 +
(ord($data[$pos +
3]) << 24);
3123 /*************************************************************/
3126 * @param mixed $data
3127 * @param integer $pos
3130 * @param bool $bigEndian
3134 function _putLong(&$data, $pos, $val, $bigEndian = true) {
3135 $val = intval($val);
3138 $data[$pos +
0] = chr(($val & 0xFF000000) >> 24);
3139 $data[$pos +
1] = chr(($val & 0x00FF0000) >> 16);
3140 $data[$pos +
2] = chr(($val & 0x0000FF00) >> 8);
3141 $data[$pos +
3] = chr(($val & 0x000000FF) >> 0);
3143 $data[$pos +
0] = chr(($val & 0x000000FF) >> 0);
3144 $data[$pos +
1] = chr(($val & 0x0000FF00) >> 8);
3145 $data[$pos +
2] = chr(($val & 0x00FF0000) >> 16);
3146 $data[$pos +
3] = chr(($val & 0xFF000000) >> 24);
3152 /*************************************************************/
3153 function & _getNullString(&$data, $pos) {
3155 $max = strlen($data);
3157 while ($pos < $max) {
3158 if (!isset($data[$pos])) {
3159 throw new Exception("Requested null-terminated string at offset ".$pos.". File terminated before the null-byte.");
3161 if (ord($data[$pos]) == 0) {
3164 $str .= $data[$pos];
3172 /*************************************************************/
3173 function & _getFixedString(&$data, $pos, $length = -1) {
3174 if ($length == -1) {
3175 $length = strlen($data) - $pos;
3178 $rv = substr($data, $pos, $length);
3179 if (strlen($rv) != $length) {
3180 throw new ErrorException(sprintf(
3181 "JPEGMeta failed parsing image metadata of %s. Got %d instead of %d bytes at offset %d.",
3182 $this->_fileName
, strlen($rv), $length, $pos
3188 /*************************************************************/
3189 function _putString(&$data, $pos, &$str) {
3190 $len = strlen($str);
3191 for ($i = 0; $i < $len; $i++
) {
3192 $data[$pos +
$i] = $str[$i];
3198 /*************************************************************/
3199 function _hexDump(&$data, $start = 0, $length = -1) {
3200 if (($length == -1) ||
(($length +
$start) > strlen($data))) {
3201 $end = strlen($data);
3203 $end = $start +
$length;
3211 while ($start < $end) {
3212 if (($count %
16) == 0) {
3213 echo sprintf('%04d', $count) . ': ';
3216 $c = ord($data[$start]);
3221 if (strlen($aux) == 1)
3236 if (($count %
4) == 0) {
3240 if (($count %
16) == 0) {
3241 echo ': ' . $ascii . "<br>\n";
3247 while (($count %
16) != 0) {
3250 if (($count %
4) == 0) {
3254 echo ': ' . $ascii . "<br>\n";
3260 /*****************************************************************/
3263 /* vim: set expandtab tabstop=4 shiftwidth=4: */