155efc227SAndreas Gohr<?php 255efc227SAndreas Gohr/** 355efc227SAndreas Gohr * JPEG metadata reader/writer 455efc227SAndreas Gohr * 52bd74074SAndreas Gohr * @license BSD <http://www.opensource.org/licenses/bsd-license.php> 62bd74074SAndreas Gohr * @link http://github.com/sd/jpeg-php 755efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 9431c7fc8Shakan.sandell * @author Hakan Sandell <hakan.sandell@mydata.se> 1036df6fa3SAndreas Gohr * @todo Add support for Maker Notes, Extend for GIF and PNG metadata 1155efc227SAndreas Gohr */ 1255efc227SAndreas Gohr 132bd74074SAndreas Gohr// Original copyright notice: 1455efc227SAndreas Gohr// 152bd74074SAndreas Gohr// Copyright (c) 2003 Sebastian Delmont <sdelmont@zonageek.com> 162bd74074SAndreas Gohr// All rights reserved. 172bd74074SAndreas Gohr// 182bd74074SAndreas Gohr// Redistribution and use in source and binary forms, with or without 192bd74074SAndreas Gohr// modification, are permitted provided that the following conditions 202bd74074SAndreas Gohr// are met: 212bd74074SAndreas Gohr// 1. Redistributions of source code must retain the above copyright 222bd74074SAndreas Gohr// notice, this list of conditions and the following disclaimer. 232bd74074SAndreas Gohr// 2. Redistributions in binary form must reproduce the above copyright 242bd74074SAndreas Gohr// notice, this list of conditions and the following disclaimer in the 252bd74074SAndreas Gohr// documentation and/or other materials provided with the distribution. 262bd74074SAndreas Gohr// 3. Neither the name of the author nor the names of its contributors 272bd74074SAndreas Gohr// may be used to endorse or promote products derived from this software 282bd74074SAndreas Gohr// without specific prior written permission. 292bd74074SAndreas Gohr// 302bd74074SAndreas Gohr// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 312bd74074SAndreas Gohr// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 322bd74074SAndreas Gohr// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 332bd74074SAndreas Gohr// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 342bd74074SAndreas Gohr// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 352bd74074SAndreas Gohr// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 362bd74074SAndreas Gohr// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 372bd74074SAndreas Gohr// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 382bd74074SAndreas Gohr// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 392bd74074SAndreas Gohr// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 402bd74074SAndreas Gohr// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 4155efc227SAndreas Gohr 420b17fdc6SAndreas Gohrclass JpegMeta { 4355efc227SAndreas Gohr var $_fileName; 4455efc227SAndreas Gohr var $_fp = null; 4559bc3b48SGerrit Uitslag var $_fpout = null; 4655efc227SAndreas Gohr var $_type = 'unknown'; 4755efc227SAndreas Gohr 4855efc227SAndreas Gohr var $_markers; 4955efc227SAndreas Gohr var $_info; 5055efc227SAndreas Gohr 5155efc227SAndreas Gohr 5255efc227SAndreas Gohr /** 5355efc227SAndreas Gohr * Constructor 5455efc227SAndreas Gohr * 5555efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 5655efc227SAndreas Gohr */ 575c3b310dSChristopher Smith function __construct($fileName) { 5855efc227SAndreas Gohr 5955efc227SAndreas Gohr $this->_fileName = $fileName; 6055efc227SAndreas Gohr 6155efc227SAndreas Gohr $this->_fp = null; 6255efc227SAndreas Gohr $this->_type = 'unknown'; 6355efc227SAndreas Gohr 6455efc227SAndreas Gohr unset($this->_info); 6555efc227SAndreas Gohr unset($this->_markers); 6655efc227SAndreas Gohr } 6755efc227SAndreas Gohr 6855efc227SAndreas Gohr /** 6955efc227SAndreas Gohr * Returns all gathered info as multidim array 7055efc227SAndreas Gohr * 7155efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 7255efc227SAndreas Gohr */ 730b17fdc6SAndreas Gohr function & getRawInfo() { 7455efc227SAndreas Gohr $this->_parseAll(); 7555efc227SAndreas Gohr 7655efc227SAndreas Gohr if ($this->_markers == null) { 7755efc227SAndreas Gohr return false; 7855efc227SAndreas Gohr } 7955efc227SAndreas Gohr 8055efc227SAndreas Gohr return $this->_info; 8155efc227SAndreas Gohr } 8255efc227SAndreas Gohr 8355efc227SAndreas Gohr /** 8455efc227SAndreas Gohr * Returns basic image info 8555efc227SAndreas Gohr * 8655efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 8755efc227SAndreas Gohr */ 880b17fdc6SAndreas Gohr function & getBasicInfo() { 8955efc227SAndreas Gohr $this->_parseAll(); 9055efc227SAndreas Gohr 9155efc227SAndreas Gohr $info = array(); 9255efc227SAndreas Gohr 9355efc227SAndreas Gohr if ($this->_markers == null) { 9455efc227SAndreas Gohr return false; 9555efc227SAndreas Gohr } 9655efc227SAndreas Gohr 9755efc227SAndreas Gohr $info['Name'] = $this->_info['file']['Name']; 9855efc227SAndreas Gohr if (isset($this->_info['file']['Url'])) { 9955efc227SAndreas Gohr $info['Url'] = $this->_info['file']['Url']; 10055efc227SAndreas Gohr $info['NiceSize'] = "???KB"; 1010b17fdc6SAndreas Gohr } else { 10255efc227SAndreas Gohr $info['Size'] = $this->_info['file']['Size']; 10355efc227SAndreas Gohr $info['NiceSize'] = $this->_info['file']['NiceSize']; 10455efc227SAndreas Gohr } 10555efc227SAndreas Gohr 10655efc227SAndreas Gohr if (@isset($this->_info['sof']['Format'])) { 10755efc227SAndreas Gohr $info['Format'] = $this->_info['sof']['Format'] . " JPEG"; 1080b17fdc6SAndreas Gohr } else { 10955efc227SAndreas Gohr $info['Format'] = $this->_info['sof']['Format'] . " JPEG"; 11055efc227SAndreas Gohr } 11155efc227SAndreas Gohr 11255efc227SAndreas Gohr if (@isset($this->_info['sof']['ColorChannels'])) { 11355efc227SAndreas Gohr $info['ColorMode'] = ($this->_info['sof']['ColorChannels'] > 1) ? "Color" : "B&W"; 11455efc227SAndreas Gohr } 11555efc227SAndreas Gohr 11655efc227SAndreas Gohr $info['Width'] = $this->getWidth(); 11755efc227SAndreas Gohr $info['Height'] = $this->getHeight(); 11855efc227SAndreas Gohr $info['DimStr'] = $this->getDimStr(); 11955efc227SAndreas Gohr 12055efc227SAndreas Gohr $dates = $this->getDates(); 12155efc227SAndreas Gohr 12255efc227SAndreas Gohr $info['DateTime'] = $dates['EarliestTime']; 12355efc227SAndreas Gohr $info['DateTimeStr'] = $dates['EarliestTimeStr']; 12455efc227SAndreas Gohr 12555efc227SAndreas Gohr $info['HasThumbnail'] = $this->hasThumbnail(); 12655efc227SAndreas Gohr 12755efc227SAndreas Gohr return $info; 12855efc227SAndreas Gohr } 12955efc227SAndreas Gohr 13055efc227SAndreas Gohr 13155efc227SAndreas Gohr /** 13255efc227SAndreas Gohr * Convinience function to access nearly all available Data 13355efc227SAndreas Gohr * through one function 13455efc227SAndreas Gohr * 13555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13642ea7f44SGerrit Uitslag * 13742ea7f44SGerrit Uitslag * @param array|string $fields field name or array with field names 13842ea7f44SGerrit Uitslag * @return bool|string 13955efc227SAndreas Gohr */ 1400b17fdc6SAndreas Gohr function getField($fields) { 14155efc227SAndreas Gohr if(!is_array($fields)) $fields = array($fields); 14255efc227SAndreas Gohr $info = false; 14355efc227SAndreas Gohr foreach($fields as $field){ 14455efc227SAndreas Gohr if(strtolower(substr($field,0,5)) == 'iptc.'){ 14555efc227SAndreas Gohr $info = $this->getIPTCField(substr($field,5)); 14655efc227SAndreas Gohr }elseif(strtolower(substr($field,0,5)) == 'exif.'){ 14755efc227SAndreas Gohr $info = $this->getExifField(substr($field,5)); 148431c7fc8Shakan.sandell }elseif(strtolower(substr($field,0,4)) == 'xmp.'){ 149431c7fc8Shakan.sandell $info = $this->getXmpField(substr($field,4)); 15055efc227SAndreas Gohr }elseif(strtolower(substr($field,0,5)) == 'file.'){ 15155efc227SAndreas Gohr $info = $this->getFileField(substr($field,5)); 15255efc227SAndreas Gohr }elseif(strtolower(substr($field,0,5)) == 'date.'){ 15355efc227SAndreas Gohr $info = $this->getDateField(substr($field,5)); 15455efc227SAndreas Gohr }elseif(strtolower($field) == 'simple.camera'){ 15555efc227SAndreas Gohr $info = $this->getCamera(); 15655efc227SAndreas Gohr }elseif(strtolower($field) == 'simple.raw'){ 15755efc227SAndreas Gohr return $this->getRawInfo(); 15855efc227SAndreas Gohr }elseif(strtolower($field) == 'simple.title'){ 15955efc227SAndreas Gohr $info = $this->getTitle(); 1606db72d46SJoe Lapp }elseif(strtolower($field) == 'simple.shutterspeed'){ 1616db72d46SJoe Lapp $info = $this->getShutterSpeed(); 16255efc227SAndreas Gohr }else{ 16355efc227SAndreas Gohr $info = $this->getExifField($field); 16455efc227SAndreas Gohr } 16555efc227SAndreas Gohr if($info != false) break; 16655efc227SAndreas Gohr } 16755efc227SAndreas Gohr 1685aaca723SGerrit Uitslag if($info === false) $info = ''; 16955efc227SAndreas Gohr if(is_array($info)){ 17055efc227SAndreas Gohr if(isset($info['val'])){ 17155efc227SAndreas Gohr $info = $info['val']; 17255efc227SAndreas Gohr }else{ 17355efc227SAndreas Gohr $info = join(', ',$info); 17455efc227SAndreas Gohr } 17555efc227SAndreas Gohr } 17655efc227SAndreas Gohr return trim($info); 17755efc227SAndreas Gohr } 17855efc227SAndreas Gohr 17955efc227SAndreas Gohr /** 18036df6fa3SAndreas Gohr * Convinience function to set nearly all available Data 18136df6fa3SAndreas Gohr * through one function 18236df6fa3SAndreas Gohr * 18336df6fa3SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 18442ea7f44SGerrit Uitslag * 18542ea7f44SGerrit Uitslag * @param string $field field name 18642ea7f44SGerrit Uitslag * @param string $value 18742ea7f44SGerrit Uitslag * @return bool success or fail 18836df6fa3SAndreas Gohr */ 1890b17fdc6SAndreas Gohr function setField($field, $value) { 19036df6fa3SAndreas Gohr if(strtolower(substr($field,0,5)) == 'iptc.'){ 19136df6fa3SAndreas Gohr return $this->setIPTCField(substr($field,5),$value); 19236df6fa3SAndreas Gohr }elseif(strtolower(substr($field,0,5)) == 'exif.'){ 19336df6fa3SAndreas Gohr return $this->setExifField(substr($field,5),$value); 19436df6fa3SAndreas Gohr }else{ 19536df6fa3SAndreas Gohr return $this->setExifField($field,$value); 19636df6fa3SAndreas Gohr } 19736df6fa3SAndreas Gohr } 19836df6fa3SAndreas Gohr 19936df6fa3SAndreas Gohr /** 20036df6fa3SAndreas Gohr * Convinience function to delete nearly all available Data 20136df6fa3SAndreas Gohr * through one function 20236df6fa3SAndreas Gohr * 20336df6fa3SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 20442ea7f44SGerrit Uitslag * 20542ea7f44SGerrit Uitslag * @param string $field field name 20642ea7f44SGerrit Uitslag * @return bool 20736df6fa3SAndreas Gohr */ 2080b17fdc6SAndreas Gohr function deleteField($field) { 20936df6fa3SAndreas Gohr if(strtolower(substr($field,0,5)) == 'iptc.'){ 21036df6fa3SAndreas Gohr return $this->deleteIPTCField(substr($field,5)); 21136df6fa3SAndreas Gohr }elseif(strtolower(substr($field,0,5)) == 'exif.'){ 21236df6fa3SAndreas Gohr return $this->deleteExifField(substr($field,5)); 21336df6fa3SAndreas Gohr }else{ 21436df6fa3SAndreas Gohr return $this->deleteExifField($field); 21536df6fa3SAndreas Gohr } 21636df6fa3SAndreas Gohr } 21736df6fa3SAndreas Gohr 21836df6fa3SAndreas Gohr /** 21955efc227SAndreas Gohr * Return a date field 22055efc227SAndreas Gohr * 22155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 22242ea7f44SGerrit Uitslag * 22342ea7f44SGerrit Uitslag * @param string $field 22442ea7f44SGerrit Uitslag * @return false|string 22555efc227SAndreas Gohr */ 2260b17fdc6SAndreas Gohr function getDateField($field) { 22755efc227SAndreas Gohr if (!isset($this->_info['dates'])) { 22855efc227SAndreas Gohr $this->_info['dates'] = $this->getDates(); 22955efc227SAndreas Gohr } 23055efc227SAndreas Gohr 23155efc227SAndreas Gohr if (isset($this->_info['dates'][$field])) { 23255efc227SAndreas Gohr return $this->_info['dates'][$field]; 23355efc227SAndreas Gohr } 23455efc227SAndreas Gohr 23555efc227SAndreas Gohr return false; 23655efc227SAndreas Gohr } 23755efc227SAndreas Gohr 23855efc227SAndreas Gohr /** 23955efc227SAndreas Gohr * Return a file info field 24055efc227SAndreas Gohr * 24155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 24242ea7f44SGerrit Uitslag * 24342ea7f44SGerrit Uitslag * @param string $field field name 24442ea7f44SGerrit Uitslag * @return false|string 24555efc227SAndreas Gohr */ 2460b17fdc6SAndreas Gohr function getFileField($field) { 24755efc227SAndreas Gohr if (!isset($this->_info['file'])) { 24855efc227SAndreas Gohr $this->_parseFileInfo(); 24955efc227SAndreas Gohr } 25055efc227SAndreas Gohr 25155efc227SAndreas Gohr if (isset($this->_info['file'][$field])) { 25255efc227SAndreas Gohr return $this->_info['file'][$field]; 25355efc227SAndreas Gohr } 25455efc227SAndreas Gohr 25555efc227SAndreas Gohr return false; 25655efc227SAndreas Gohr } 25755efc227SAndreas Gohr 25855efc227SAndreas Gohr /** 25955efc227SAndreas Gohr * Return the camera info (Maker and Model) 26055efc227SAndreas Gohr * 26155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 26255efc227SAndreas Gohr * @todo handle makernotes 26342ea7f44SGerrit Uitslag * 26442ea7f44SGerrit Uitslag * @return false|string 26555efc227SAndreas Gohr */ 26655efc227SAndreas Gohr function getCamera(){ 26755efc227SAndreas Gohr $make = $this->getField(array('Exif.Make','Exif.TIFFMake')); 26855efc227SAndreas Gohr $model = $this->getField(array('Exif.Model','Exif.TIFFModel')); 26955efc227SAndreas Gohr $cam = trim("$make $model"); 27055efc227SAndreas Gohr if(empty($cam)) return false; 27155efc227SAndreas Gohr return $cam; 27255efc227SAndreas Gohr } 27355efc227SAndreas Gohr 27455efc227SAndreas Gohr /** 2756db72d46SJoe Lapp * Return shutter speed as a ratio 2766db72d46SJoe Lapp * 2776db72d46SJoe Lapp * @author Joe Lapp <joe.lapp@pobox.com> 27842ea7f44SGerrit Uitslag * 27942ea7f44SGerrit Uitslag * @return string 2806db72d46SJoe Lapp */ 2810b17fdc6SAndreas Gohr function getShutterSpeed() { 2826db72d46SJoe Lapp if (!isset($this->_info['exif'])) { 2836db72d46SJoe Lapp $this->_parseMarkerExif(); 2846db72d46SJoe Lapp } 2856db72d46SJoe Lapp if(!isset($this->_info['exif']['ExposureTime'])){ 2866db72d46SJoe Lapp return ''; 2876db72d46SJoe Lapp } 2886db72d46SJoe Lapp 2896db72d46SJoe Lapp $field = $this->_info['exif']['ExposureTime']; 2906db72d46SJoe Lapp if($field['den'] == 1) return $field['num']; 2916db72d46SJoe Lapp return $field['num'].'/'.$field['den']; 2926db72d46SJoe Lapp } 2936db72d46SJoe Lapp 2946db72d46SJoe Lapp /** 29555efc227SAndreas Gohr * Return an EXIF field 29655efc227SAndreas Gohr * 29755efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 29842ea7f44SGerrit Uitslag * 29942ea7f44SGerrit Uitslag * @param string $field field name 30042ea7f44SGerrit Uitslag * @return false|string 30155efc227SAndreas Gohr */ 3020b17fdc6SAndreas Gohr function getExifField($field) { 30355efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 30455efc227SAndreas Gohr $this->_parseMarkerExif(); 30555efc227SAndreas Gohr } 30655efc227SAndreas Gohr 30755efc227SAndreas Gohr if ($this->_markers == null) { 30855efc227SAndreas Gohr return false; 30955efc227SAndreas Gohr } 31055efc227SAndreas Gohr 31155efc227SAndreas Gohr if (isset($this->_info['exif'][$field])) { 31255efc227SAndreas Gohr return $this->_info['exif'][$field]; 31355efc227SAndreas Gohr } 31455efc227SAndreas Gohr 31555efc227SAndreas Gohr return false; 31655efc227SAndreas Gohr } 31755efc227SAndreas Gohr 31855efc227SAndreas Gohr /** 319431c7fc8Shakan.sandell * Return an XMP field 320431c7fc8Shakan.sandell * 321431c7fc8Shakan.sandell * @author Hakan Sandell <hakan.sandell@mydata.se> 32242ea7f44SGerrit Uitslag * 32342ea7f44SGerrit Uitslag * @param string $field field name 32442ea7f44SGerrit Uitslag * @return false|string 325431c7fc8Shakan.sandell */ 3260b17fdc6SAndreas Gohr function getXmpField($field) { 327431c7fc8Shakan.sandell if (!isset($this->_info['xmp'])) { 328431c7fc8Shakan.sandell $this->_parseMarkerXmp(); 329431c7fc8Shakan.sandell } 330431c7fc8Shakan.sandell 331431c7fc8Shakan.sandell if ($this->_markers == null) { 332431c7fc8Shakan.sandell return false; 333431c7fc8Shakan.sandell } 334431c7fc8Shakan.sandell 335431c7fc8Shakan.sandell if (isset($this->_info['xmp'][$field])) { 336431c7fc8Shakan.sandell return $this->_info['xmp'][$field]; 337431c7fc8Shakan.sandell } 338431c7fc8Shakan.sandell 339431c7fc8Shakan.sandell return false; 340431c7fc8Shakan.sandell } 341431c7fc8Shakan.sandell 342431c7fc8Shakan.sandell /** 34355efc227SAndreas Gohr * Return an Adobe Field 34455efc227SAndreas Gohr * 34555efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 34642ea7f44SGerrit Uitslag * 34742ea7f44SGerrit Uitslag * @param string $field field name 34842ea7f44SGerrit Uitslag * @return false|string 34955efc227SAndreas Gohr */ 3500b17fdc6SAndreas Gohr function getAdobeField($field) { 35155efc227SAndreas Gohr if (!isset($this->_info['adobe'])) { 35255efc227SAndreas Gohr $this->_parseMarkerAdobe(); 35355efc227SAndreas Gohr } 35455efc227SAndreas Gohr 35555efc227SAndreas Gohr if ($this->_markers == null) { 35655efc227SAndreas Gohr return false; 35755efc227SAndreas Gohr } 35855efc227SAndreas Gohr 35955efc227SAndreas Gohr if (isset($this->_info['adobe'][$field])) { 36055efc227SAndreas Gohr return $this->_info['adobe'][$field]; 36155efc227SAndreas Gohr } 36255efc227SAndreas Gohr 36355efc227SAndreas Gohr return false; 36455efc227SAndreas Gohr } 36555efc227SAndreas Gohr 36655efc227SAndreas Gohr /** 36755efc227SAndreas Gohr * Return an IPTC field 36855efc227SAndreas Gohr * 36955efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 37042ea7f44SGerrit Uitslag * 37142ea7f44SGerrit Uitslag * @param string $field field name 37242ea7f44SGerrit Uitslag * @return false|string 37355efc227SAndreas Gohr */ 3740b17fdc6SAndreas Gohr function getIPTCField($field) { 37555efc227SAndreas Gohr if (!isset($this->_info['iptc'])) { 37655efc227SAndreas Gohr $this->_parseMarkerAdobe(); 37755efc227SAndreas Gohr } 37855efc227SAndreas Gohr 37955efc227SAndreas Gohr if ($this->_markers == null) { 38055efc227SAndreas Gohr return false; 38155efc227SAndreas Gohr } 38255efc227SAndreas Gohr 38355efc227SAndreas Gohr if (isset($this->_info['iptc'][$field])) { 38455efc227SAndreas Gohr return $this->_info['iptc'][$field]; 38555efc227SAndreas Gohr } 38655efc227SAndreas Gohr 38755efc227SAndreas Gohr return false; 38855efc227SAndreas Gohr } 38955efc227SAndreas Gohr 39055efc227SAndreas Gohr /** 39155efc227SAndreas Gohr * Set an EXIF field 39255efc227SAndreas Gohr * 39355efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 394b5a81756SJoe Lapp * @author Joe Lapp <joe.lapp@pobox.com> 39542ea7f44SGerrit Uitslag * 39642ea7f44SGerrit Uitslag * @param string $field field name 39742ea7f44SGerrit Uitslag * @param string $value 39842ea7f44SGerrit Uitslag * @return bool 39955efc227SAndreas Gohr */ 4000b17fdc6SAndreas Gohr function setExifField($field, $value) { 40155efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 40255efc227SAndreas Gohr $this->_parseMarkerExif(); 40355efc227SAndreas Gohr } 40455efc227SAndreas Gohr 40555efc227SAndreas Gohr if ($this->_markers == null) { 40655efc227SAndreas Gohr return false; 40755efc227SAndreas Gohr } 40855efc227SAndreas Gohr 40955efc227SAndreas Gohr if ($this->_info['exif'] == false) { 41055efc227SAndreas Gohr $this->_info['exif'] = array(); 41155efc227SAndreas Gohr } 41255efc227SAndreas Gohr 413b5a81756SJoe Lapp // make sure datetimes are in correct format 414b5a81756SJoe Lapp if(strlen($field) >= 8 && strtolower(substr($field, 0, 8)) == 'datetime') { 415b5a81756SJoe Lapp if(strlen($value) < 8 || $value{4} != ':' || $value{7} != ':') { 416b5a81756SJoe Lapp $value = date('Y:m:d H:i:s', strtotime($value)); 417b5a81756SJoe Lapp } 418b5a81756SJoe Lapp } 419b5a81756SJoe Lapp 42055efc227SAndreas Gohr $this->_info['exif'][$field] = $value; 42155efc227SAndreas Gohr 42255efc227SAndreas Gohr return true; 42355efc227SAndreas Gohr } 42455efc227SAndreas Gohr 42555efc227SAndreas Gohr /** 42655efc227SAndreas Gohr * Set an Adobe Field 42755efc227SAndreas Gohr * 42855efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 42942ea7f44SGerrit Uitslag * 43042ea7f44SGerrit Uitslag * @param string $field field name 43142ea7f44SGerrit Uitslag * @param string $value 43242ea7f44SGerrit Uitslag * @return bool 43355efc227SAndreas Gohr */ 4340b17fdc6SAndreas Gohr function setAdobeField($field, $value) { 43555efc227SAndreas Gohr if (!isset($this->_info['adobe'])) { 43655efc227SAndreas Gohr $this->_parseMarkerAdobe(); 43755efc227SAndreas Gohr } 43855efc227SAndreas Gohr 43955efc227SAndreas Gohr if ($this->_markers == null) { 44055efc227SAndreas Gohr return false; 44155efc227SAndreas Gohr } 44255efc227SAndreas Gohr 44355efc227SAndreas Gohr if ($this->_info['adobe'] == false) { 44455efc227SAndreas Gohr $this->_info['adobe'] = array(); 44555efc227SAndreas Gohr } 44655efc227SAndreas Gohr 44755efc227SAndreas Gohr $this->_info['adobe'][$field] = $value; 44855efc227SAndreas Gohr 44955efc227SAndreas Gohr return true; 45055efc227SAndreas Gohr } 45155efc227SAndreas Gohr 45255efc227SAndreas Gohr /** 45323a34783SAndreas Gohr * Calculates the multiplier needed to resize the image to the given 45423a34783SAndreas Gohr * dimensions 45523a34783SAndreas Gohr * 45623a34783SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 45742ea7f44SGerrit Uitslag * 45842ea7f44SGerrit Uitslag * @param int $maxwidth 45942ea7f44SGerrit Uitslag * @param int $maxheight 46042ea7f44SGerrit Uitslag * @return float|int 46123a34783SAndreas Gohr */ 46223a34783SAndreas Gohr function getResizeRatio($maxwidth,$maxheight=0){ 46323a34783SAndreas Gohr if(!$maxheight) $maxheight = $maxwidth; 46423a34783SAndreas Gohr 46523a34783SAndreas Gohr $w = $this->getField('File.Width'); 46623a34783SAndreas Gohr $h = $this->getField('File.Height'); 46723a34783SAndreas Gohr 46823a34783SAndreas Gohr $ratio = 1; 46923a34783SAndreas Gohr if($w >= $h){ 47023a34783SAndreas Gohr if($w >= $maxwidth){ 47123a34783SAndreas Gohr $ratio = $maxwidth/$w; 47223a34783SAndreas Gohr }elseif($h > $maxheight){ 47323a34783SAndreas Gohr $ratio = $maxheight/$h; 47423a34783SAndreas Gohr } 47523a34783SAndreas Gohr }else{ 47623a34783SAndreas Gohr if($h >= $maxheight){ 47723a34783SAndreas Gohr $ratio = $maxheight/$h; 47823a34783SAndreas Gohr }elseif($w > $maxwidth){ 47923a34783SAndreas Gohr $ratio = $maxwidth/$w; 48023a34783SAndreas Gohr } 48123a34783SAndreas Gohr } 48223a34783SAndreas Gohr return $ratio; 48323a34783SAndreas Gohr } 48423a34783SAndreas Gohr 48523a34783SAndreas Gohr 48623a34783SAndreas Gohr /** 48755efc227SAndreas Gohr * Set an IPTC field 48855efc227SAndreas Gohr * 48955efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 49042ea7f44SGerrit Uitslag * 49142ea7f44SGerrit Uitslag * @param string $field field name 49242ea7f44SGerrit Uitslag * @param string $value 49342ea7f44SGerrit Uitslag * @return bool 49455efc227SAndreas Gohr */ 4950b17fdc6SAndreas Gohr function setIPTCField($field, $value) { 49655efc227SAndreas Gohr if (!isset($this->_info['iptc'])) { 49755efc227SAndreas Gohr $this->_parseMarkerAdobe(); 49855efc227SAndreas Gohr } 49955efc227SAndreas Gohr 50055efc227SAndreas Gohr if ($this->_markers == null) { 50155efc227SAndreas Gohr return false; 50255efc227SAndreas Gohr } 50355efc227SAndreas Gohr 50455efc227SAndreas Gohr if ($this->_info['iptc'] == false) { 50555efc227SAndreas Gohr $this->_info['iptc'] = array(); 50655efc227SAndreas Gohr } 50755efc227SAndreas Gohr 50855efc227SAndreas Gohr $this->_info['iptc'][$field] = $value; 50955efc227SAndreas Gohr 51055efc227SAndreas Gohr return true; 51155efc227SAndreas Gohr } 51255efc227SAndreas Gohr 51355efc227SAndreas Gohr /** 51455efc227SAndreas Gohr * Delete an EXIF field 51555efc227SAndreas Gohr * 51655efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 51742ea7f44SGerrit Uitslag * 51842ea7f44SGerrit Uitslag * @param string $field field name 51942ea7f44SGerrit Uitslag * @return bool 52055efc227SAndreas Gohr */ 5210b17fdc6SAndreas Gohr function deleteExifField($field) { 52255efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 52355efc227SAndreas Gohr $this->_parseMarkerAdobe(); 52455efc227SAndreas Gohr } 52555efc227SAndreas Gohr 52655efc227SAndreas Gohr if ($this->_markers == null) { 52755efc227SAndreas Gohr return false; 52855efc227SAndreas Gohr } 52955efc227SAndreas Gohr 53055efc227SAndreas Gohr if ($this->_info['exif'] != false) { 53155efc227SAndreas Gohr unset($this->_info['exif'][$field]); 53255efc227SAndreas Gohr } 53355efc227SAndreas Gohr 53455efc227SAndreas Gohr return true; 53555efc227SAndreas Gohr } 53655efc227SAndreas Gohr 53755efc227SAndreas Gohr /** 53855efc227SAndreas Gohr * Delete an Adobe field 53955efc227SAndreas Gohr * 54055efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 54142ea7f44SGerrit Uitslag * 54242ea7f44SGerrit Uitslag * @param string $field field name 54342ea7f44SGerrit Uitslag * @return bool 54455efc227SAndreas Gohr */ 5450b17fdc6SAndreas Gohr function deleteAdobeField($field) { 54655efc227SAndreas Gohr if (!isset($this->_info['adobe'])) { 54755efc227SAndreas Gohr $this->_parseMarkerAdobe(); 54855efc227SAndreas Gohr } 54955efc227SAndreas Gohr 55055efc227SAndreas Gohr if ($this->_markers == null) { 55155efc227SAndreas Gohr return false; 55255efc227SAndreas Gohr } 55355efc227SAndreas Gohr 55455efc227SAndreas Gohr if ($this->_info['adobe'] != false) { 55555efc227SAndreas Gohr unset($this->_info['adobe'][$field]); 55655efc227SAndreas Gohr } 55755efc227SAndreas Gohr 55855efc227SAndreas Gohr return true; 55955efc227SAndreas Gohr } 56055efc227SAndreas Gohr 56155efc227SAndreas Gohr /** 56255efc227SAndreas Gohr * Delete an IPTC field 56355efc227SAndreas Gohr * 56455efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 56542ea7f44SGerrit Uitslag * 56642ea7f44SGerrit Uitslag * @param string $field field name 56742ea7f44SGerrit Uitslag * @return bool 56855efc227SAndreas Gohr */ 5690b17fdc6SAndreas Gohr function deleteIPTCField($field) { 57055efc227SAndreas Gohr if (!isset($this->_info['iptc'])) { 57155efc227SAndreas Gohr $this->_parseMarkerAdobe(); 57255efc227SAndreas Gohr } 57355efc227SAndreas Gohr 57455efc227SAndreas Gohr if ($this->_markers == null) { 57555efc227SAndreas Gohr return false; 57655efc227SAndreas Gohr } 57755efc227SAndreas Gohr 57855efc227SAndreas Gohr if ($this->_info['iptc'] != false) { 57955efc227SAndreas Gohr unset($this->_info['iptc'][$field]); 58055efc227SAndreas Gohr } 58155efc227SAndreas Gohr 58255efc227SAndreas Gohr return true; 58355efc227SAndreas Gohr } 58455efc227SAndreas Gohr 58555efc227SAndreas Gohr /** 58655efc227SAndreas Gohr * Get the image's title, tries various fields 58755efc227SAndreas Gohr * 58855efc227SAndreas Gohr * @param int $max maximum number chars (keeps words) 58942ea7f44SGerrit Uitslag * @return false|string 59059bc3b48SGerrit Uitslag * 59155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 59255efc227SAndreas Gohr */ 59355efc227SAndreas Gohr function getTitle($max=80){ 59455efc227SAndreas Gohr // try various fields 59555efc227SAndreas Gohr $cap = $this->getField(array('Iptc.Headline', 59655efc227SAndreas Gohr 'Iptc.Caption', 597431c7fc8Shakan.sandell 'Xmp.dc:title', 59855efc227SAndreas Gohr 'Exif.UserComment', 59955efc227SAndreas Gohr 'Exif.TIFFUserComment', 6002684e50aSAndreas Gohr 'Exif.TIFFImageDescription', 6012684e50aSAndreas Gohr 'File.Name')); 60255efc227SAndreas Gohr if (empty($cap)) return false; 60355efc227SAndreas Gohr 60455efc227SAndreas Gohr if(!$max) return $cap; 60555efc227SAndreas Gohr // Shorten to 80 chars (keeping words) 60655efc227SAndreas Gohr $new = preg_replace('/\n.+$/','',wordwrap($cap, $max)); 60755efc227SAndreas Gohr if($new != $cap) $new .= '...'; 60855efc227SAndreas Gohr 60955efc227SAndreas Gohr return $new; 61055efc227SAndreas Gohr } 61155efc227SAndreas Gohr 61255efc227SAndreas Gohr /** 61355efc227SAndreas Gohr * Gather various date fields 61455efc227SAndreas Gohr * 61555efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 61642ea7f44SGerrit Uitslag * 61742ea7f44SGerrit Uitslag * @return array|bool 61855efc227SAndreas Gohr */ 6190b17fdc6SAndreas Gohr function getDates() { 62055efc227SAndreas Gohr $this->_parseAll(); 62155efc227SAndreas Gohr if ($this->_markers == null) { 622a73b5b7eSAndreas Gohr if (@isset($this->_info['file']['UnixTime'])) { 62359bc3b48SGerrit Uitslag $dates = array(); 624a73b5b7eSAndreas Gohr $dates['FileModified'] = $this->_info['file']['UnixTime']; 625a73b5b7eSAndreas Gohr $dates['Time'] = $this->_info['file']['UnixTime']; 626a73b5b7eSAndreas Gohr $dates['TimeSource'] = 'FileModified'; 627a73b5b7eSAndreas Gohr $dates['TimeStr'] = date("Y-m-d H:i:s", $this->_info['file']['UnixTime']); 628a73b5b7eSAndreas Gohr $dates['EarliestTime'] = $this->_info['file']['UnixTime']; 629a73b5b7eSAndreas Gohr $dates['EarliestTimeSource'] = 'FileModified'; 630a73b5b7eSAndreas Gohr $dates['EarliestTimeStr'] = date("Y-m-d H:i:s", $this->_info['file']['UnixTime']); 631a73b5b7eSAndreas Gohr $dates['LatestTime'] = $this->_info['file']['UnixTime']; 632a73b5b7eSAndreas Gohr $dates['LatestTimeSource'] = 'FileModified'; 633a73b5b7eSAndreas Gohr $dates['LatestTimeStr'] = date("Y-m-d H:i:s", $this->_info['file']['UnixTime']); 634a73b5b7eSAndreas Gohr return $dates; 635a73b5b7eSAndreas Gohr } 63655efc227SAndreas Gohr return false; 63755efc227SAndreas Gohr } 63855efc227SAndreas Gohr 63955efc227SAndreas Gohr $dates = array(); 64055efc227SAndreas Gohr 64155efc227SAndreas Gohr $latestTime = 0; 64255efc227SAndreas Gohr $latestTimeSource = ""; 64355efc227SAndreas Gohr $earliestTime = time(); 64455efc227SAndreas Gohr $earliestTimeSource = ""; 64555efc227SAndreas Gohr 64655efc227SAndreas Gohr if (@isset($this->_info['exif']['DateTime'])) { 64755efc227SAndreas Gohr $dates['ExifDateTime'] = $this->_info['exif']['DateTime']; 64855efc227SAndreas Gohr 64955efc227SAndreas Gohr $aux = $this->_info['exif']['DateTime']; 65055efc227SAndreas Gohr $aux{4} = "-"; 65155efc227SAndreas Gohr $aux{7} = "-"; 65255efc227SAndreas Gohr $t = strtotime($aux); 65355efc227SAndreas Gohr 6542114dafdSAndreas Gohr if ($t && $t > $latestTime) { 65555efc227SAndreas Gohr $latestTime = $t; 65655efc227SAndreas Gohr $latestTimeSource = "ExifDateTime"; 65755efc227SAndreas Gohr } 65855efc227SAndreas Gohr 6592114dafdSAndreas Gohr if ($t && $t < $earliestTime) { 66055efc227SAndreas Gohr $earliestTime = $t; 66155efc227SAndreas Gohr $earliestTimeSource = "ExifDateTime"; 66255efc227SAndreas Gohr } 66355efc227SAndreas Gohr } 66455efc227SAndreas Gohr 66555efc227SAndreas Gohr if (@isset($this->_info['exif']['DateTimeOriginal'])) { 66655efc227SAndreas Gohr $dates['ExifDateTimeOriginal'] = $this->_info['exif']['DateTime']; 66755efc227SAndreas Gohr 66855efc227SAndreas Gohr $aux = $this->_info['exif']['DateTimeOriginal']; 66955efc227SAndreas Gohr $aux{4} = "-"; 67055efc227SAndreas Gohr $aux{7} = "-"; 67155efc227SAndreas Gohr $t = strtotime($aux); 67255efc227SAndreas Gohr 6732114dafdSAndreas Gohr if ($t && $t > $latestTime) { 67455efc227SAndreas Gohr $latestTime = $t; 67555efc227SAndreas Gohr $latestTimeSource = "ExifDateTimeOriginal"; 67655efc227SAndreas Gohr } 67755efc227SAndreas Gohr 6782114dafdSAndreas Gohr if ($t && $t < $earliestTime) { 67955efc227SAndreas Gohr $earliestTime = $t; 68055efc227SAndreas Gohr $earliestTimeSource = "ExifDateTimeOriginal"; 68155efc227SAndreas Gohr } 68255efc227SAndreas Gohr } 68355efc227SAndreas Gohr 68455efc227SAndreas Gohr if (@isset($this->_info['exif']['DateTimeDigitized'])) { 68555efc227SAndreas Gohr $dates['ExifDateTimeDigitized'] = $this->_info['exif']['DateTime']; 68655efc227SAndreas Gohr 68755efc227SAndreas Gohr $aux = $this->_info['exif']['DateTimeDigitized']; 68855efc227SAndreas Gohr $aux{4} = "-"; 68955efc227SAndreas Gohr $aux{7} = "-"; 69055efc227SAndreas Gohr $t = strtotime($aux); 69155efc227SAndreas Gohr 6922114dafdSAndreas Gohr if ($t && $t > $latestTime) { 69355efc227SAndreas Gohr $latestTime = $t; 69455efc227SAndreas Gohr $latestTimeSource = "ExifDateTimeDigitized"; 69555efc227SAndreas Gohr } 69655efc227SAndreas Gohr 6972114dafdSAndreas Gohr if ($t && $t < $earliestTime) { 69855efc227SAndreas Gohr $earliestTime = $t; 69955efc227SAndreas Gohr $earliestTimeSource = "ExifDateTimeDigitized"; 70055efc227SAndreas Gohr } 70155efc227SAndreas Gohr } 70255efc227SAndreas Gohr 70355efc227SAndreas Gohr if (@isset($this->_info['iptc']['DateCreated'])) { 70455efc227SAndreas Gohr $dates['IPTCDateCreated'] = $this->_info['iptc']['DateCreated']; 70555efc227SAndreas Gohr 70655efc227SAndreas Gohr $aux = $this->_info['iptc']['DateCreated']; 70755efc227SAndreas Gohr $aux = substr($aux, 0, 4) . "-" . substr($aux, 4, 2) . "-" . substr($aux, 6, 2); 70855efc227SAndreas Gohr $t = strtotime($aux); 70955efc227SAndreas Gohr 7102114dafdSAndreas Gohr if ($t && $t > $latestTime) { 71155efc227SAndreas Gohr $latestTime = $t; 71255efc227SAndreas Gohr $latestTimeSource = "IPTCDateCreated"; 71355efc227SAndreas Gohr } 71455efc227SAndreas Gohr 7152114dafdSAndreas Gohr if ($t && $t < $earliestTime) { 71655efc227SAndreas Gohr $earliestTime = $t; 71755efc227SAndreas Gohr $earliestTimeSource = "IPTCDateCreated"; 71855efc227SAndreas Gohr } 71955efc227SAndreas Gohr } 72055efc227SAndreas Gohr 72155efc227SAndreas Gohr if (@isset($this->_info['file']['UnixTime'])) { 72255efc227SAndreas Gohr $dates['FileModified'] = $this->_info['file']['UnixTime']; 72355efc227SAndreas Gohr 72455efc227SAndreas Gohr $t = $this->_info['file']['UnixTime']; 72555efc227SAndreas Gohr 7262114dafdSAndreas Gohr if ($t && $t > $latestTime) { 72755efc227SAndreas Gohr $latestTime = $t; 72855efc227SAndreas Gohr $latestTimeSource = "FileModified"; 72955efc227SAndreas Gohr } 73055efc227SAndreas Gohr 7312114dafdSAndreas Gohr if ($t && $t < $earliestTime) { 73255efc227SAndreas Gohr $earliestTime = $t; 73355efc227SAndreas Gohr $earliestTimeSource = "FileModified"; 73455efc227SAndreas Gohr } 73555efc227SAndreas Gohr } 73655efc227SAndreas Gohr 73755efc227SAndreas Gohr $dates['Time'] = $earliestTime; 73855efc227SAndreas Gohr $dates['TimeSource'] = $earliestTimeSource; 73955efc227SAndreas Gohr $dates['TimeStr'] = date("Y-m-d H:i:s", $earliestTime); 74055efc227SAndreas Gohr $dates['EarliestTime'] = $earliestTime; 74155efc227SAndreas Gohr $dates['EarliestTimeSource'] = $earliestTimeSource; 74255efc227SAndreas Gohr $dates['EarliestTimeStr'] = date("Y-m-d H:i:s", $earliestTime); 74355efc227SAndreas Gohr $dates['LatestTime'] = $latestTime; 74455efc227SAndreas Gohr $dates['LatestTimeSource'] = $latestTimeSource; 74555efc227SAndreas Gohr $dates['LatestTimeStr'] = date("Y-m-d H:i:s", $latestTime); 74655efc227SAndreas Gohr 74755efc227SAndreas Gohr return $dates; 74855efc227SAndreas Gohr } 74955efc227SAndreas Gohr 75055efc227SAndreas Gohr /** 75155efc227SAndreas Gohr * Get the image width, tries various fields 75255efc227SAndreas Gohr * 75355efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 75442ea7f44SGerrit Uitslag * 75542ea7f44SGerrit Uitslag * @return false|string 75655efc227SAndreas Gohr */ 7570b17fdc6SAndreas Gohr function getWidth() { 75855efc227SAndreas Gohr if (!isset($this->_info['sof'])) { 75955efc227SAndreas Gohr $this->_parseMarkerSOF(); 76055efc227SAndreas Gohr } 76155efc227SAndreas Gohr 76255efc227SAndreas Gohr if ($this->_markers == null) { 76355efc227SAndreas Gohr return false; 76455efc227SAndreas Gohr } 76555efc227SAndreas Gohr 76655efc227SAndreas Gohr if (isset($this->_info['sof']['ImageWidth'])) { 76755efc227SAndreas Gohr return $this->_info['sof']['ImageWidth']; 76855efc227SAndreas Gohr } 76955efc227SAndreas Gohr 77055efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 77155efc227SAndreas Gohr $this->_parseMarkerExif(); 77255efc227SAndreas Gohr } 77355efc227SAndreas Gohr 77455efc227SAndreas Gohr if (isset($this->_info['exif']['PixelXDimension'])) { 77555efc227SAndreas Gohr return $this->_info['exif']['PixelXDimension']; 77655efc227SAndreas Gohr } 77755efc227SAndreas Gohr 77855efc227SAndreas Gohr return false; 77955efc227SAndreas Gohr } 78055efc227SAndreas Gohr 78155efc227SAndreas Gohr /** 78255efc227SAndreas Gohr * Get the image height, tries various fields 78355efc227SAndreas Gohr * 78455efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 78542ea7f44SGerrit Uitslag * 78642ea7f44SGerrit Uitslag * @return false|string 78755efc227SAndreas Gohr */ 7880b17fdc6SAndreas Gohr function getHeight() { 78955efc227SAndreas Gohr if (!isset($this->_info['sof'])) { 79055efc227SAndreas Gohr $this->_parseMarkerSOF(); 79155efc227SAndreas Gohr } 79255efc227SAndreas Gohr 79355efc227SAndreas Gohr if ($this->_markers == null) { 79455efc227SAndreas Gohr return false; 79555efc227SAndreas Gohr } 79655efc227SAndreas Gohr 79755efc227SAndreas Gohr if (isset($this->_info['sof']['ImageHeight'])) { 79855efc227SAndreas Gohr return $this->_info['sof']['ImageHeight']; 79955efc227SAndreas Gohr } 80055efc227SAndreas Gohr 80155efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 80255efc227SAndreas Gohr $this->_parseMarkerExif(); 80355efc227SAndreas Gohr } 80455efc227SAndreas Gohr 80555efc227SAndreas Gohr if (isset($this->_info['exif']['PixelYDimension'])) { 80655efc227SAndreas Gohr return $this->_info['exif']['PixelYDimension']; 80755efc227SAndreas Gohr } 80855efc227SAndreas Gohr 80955efc227SAndreas Gohr return false; 81055efc227SAndreas Gohr } 81155efc227SAndreas Gohr 81255efc227SAndreas Gohr /** 81355efc227SAndreas Gohr * Get an dimension string for use in img tag 81455efc227SAndreas Gohr * 81555efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 81642ea7f44SGerrit Uitslag * 81742ea7f44SGerrit Uitslag * @return false|string 81855efc227SAndreas Gohr */ 8190b17fdc6SAndreas Gohr function getDimStr() { 82055efc227SAndreas Gohr if ($this->_markers == null) { 82155efc227SAndreas Gohr return false; 82255efc227SAndreas Gohr } 82355efc227SAndreas Gohr 82455efc227SAndreas Gohr $w = $this->getWidth(); 82555efc227SAndreas Gohr $h = $this->getHeight(); 82655efc227SAndreas Gohr 82755efc227SAndreas Gohr return "width='" . $w . "' height='" . $h . "'"; 82855efc227SAndreas Gohr } 82955efc227SAndreas Gohr 83055efc227SAndreas Gohr /** 83155efc227SAndreas Gohr * Checks for an embedded thumbnail 83255efc227SAndreas Gohr * 83355efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 83442ea7f44SGerrit Uitslag * 83542ea7f44SGerrit Uitslag * @param string $which possible values: 'any', 'exif' or 'adobe' 83642ea7f44SGerrit Uitslag * @return false|string 83755efc227SAndreas Gohr */ 8380b17fdc6SAndreas Gohr function hasThumbnail($which = 'any') { 83955efc227SAndreas Gohr if (($which == 'any') || ($which == 'exif')) { 84055efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 84155efc227SAndreas Gohr $this->_parseMarkerExif(); 84255efc227SAndreas Gohr } 84355efc227SAndreas Gohr 84455efc227SAndreas Gohr if ($this->_markers == null) { 84555efc227SAndreas Gohr return false; 84655efc227SAndreas Gohr } 84755efc227SAndreas Gohr 84855efc227SAndreas Gohr if (isset($this->_info['exif']) && is_array($this->_info['exif'])) { 84955efc227SAndreas Gohr if (isset($this->_info['exif']['JFIFThumbnail'])) { 85055efc227SAndreas Gohr return 'exif'; 85155efc227SAndreas Gohr } 85255efc227SAndreas Gohr } 85355efc227SAndreas Gohr } 85455efc227SAndreas Gohr 85555efc227SAndreas Gohr if ($which == 'adobe') { 85655efc227SAndreas Gohr if (!isset($this->_info['adobe'])) { 85755efc227SAndreas Gohr $this->_parseMarkerAdobe(); 85855efc227SAndreas Gohr } 85955efc227SAndreas Gohr 86055efc227SAndreas Gohr if ($this->_markers == null) { 86155efc227SAndreas Gohr return false; 86255efc227SAndreas Gohr } 86355efc227SAndreas Gohr 86455efc227SAndreas Gohr if (isset($this->_info['adobe']) && is_array($this->_info['adobe'])) { 86555efc227SAndreas Gohr if (isset($this->_info['adobe']['ThumbnailData'])) { 86655efc227SAndreas Gohr return 'exif'; 86755efc227SAndreas Gohr } 86855efc227SAndreas Gohr } 86955efc227SAndreas Gohr } 87055efc227SAndreas Gohr 87155efc227SAndreas Gohr return false; 87255efc227SAndreas Gohr } 87355efc227SAndreas Gohr 87455efc227SAndreas Gohr /** 87555efc227SAndreas Gohr * Send embedded thumbnail to browser 87655efc227SAndreas Gohr * 87755efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 87842ea7f44SGerrit Uitslag * 87942ea7f44SGerrit Uitslag * @param string $which possible values: 'any', 'exif' or 'adobe' 88042ea7f44SGerrit Uitslag * @return bool 88155efc227SAndreas Gohr */ 8820b17fdc6SAndreas Gohr function sendThumbnail($which = 'any') { 88355efc227SAndreas Gohr $data = null; 88455efc227SAndreas Gohr 88555efc227SAndreas Gohr if (($which == 'any') || ($which == 'exif')) { 88655efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 88755efc227SAndreas Gohr $this->_parseMarkerExif(); 88855efc227SAndreas Gohr } 88955efc227SAndreas Gohr 89055efc227SAndreas Gohr if ($this->_markers == null) { 89155efc227SAndreas Gohr return false; 89255efc227SAndreas Gohr } 89355efc227SAndreas Gohr 89455efc227SAndreas Gohr if (isset($this->_info['exif']) && is_array($this->_info['exif'])) { 89555efc227SAndreas Gohr if (isset($this->_info['exif']['JFIFThumbnail'])) { 89655efc227SAndreas Gohr $data =& $this->_info['exif']['JFIFThumbnail']; 89755efc227SAndreas Gohr } 89855efc227SAndreas Gohr } 89955efc227SAndreas Gohr } 90055efc227SAndreas Gohr 90155efc227SAndreas Gohr if (($which == 'adobe') || ($data == null)){ 90255efc227SAndreas Gohr if (!isset($this->_info['adobe'])) { 90355efc227SAndreas Gohr $this->_parseMarkerAdobe(); 90455efc227SAndreas Gohr } 90555efc227SAndreas Gohr 90655efc227SAndreas Gohr if ($this->_markers == null) { 90755efc227SAndreas Gohr return false; 90855efc227SAndreas Gohr } 90955efc227SAndreas Gohr 91055efc227SAndreas Gohr if (isset($this->_info['adobe']) && is_array($this->_info['adobe'])) { 91155efc227SAndreas Gohr if (isset($this->_info['adobe']['ThumbnailData'])) { 91255efc227SAndreas Gohr $data =& $this->_info['adobe']['ThumbnailData']; 91355efc227SAndreas Gohr } 91455efc227SAndreas Gohr } 91555efc227SAndreas Gohr } 91655efc227SAndreas Gohr 91755efc227SAndreas Gohr if ($data != null) { 91855efc227SAndreas Gohr header("Content-type: image/jpeg"); 91955efc227SAndreas Gohr echo $data; 92055efc227SAndreas Gohr return true; 92155efc227SAndreas Gohr } 92255efc227SAndreas Gohr 92355efc227SAndreas Gohr return false; 92455efc227SAndreas Gohr } 92555efc227SAndreas Gohr 92655efc227SAndreas Gohr /** 92755efc227SAndreas Gohr * Save changed Metadata 92855efc227SAndreas Gohr * 92955efc227SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 93036df6fa3SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 93142ea7f44SGerrit Uitslag * 93242ea7f44SGerrit Uitslag * @param string $fileName file name or empty string for a random name 93342ea7f44SGerrit Uitslag * @return bool 93455efc227SAndreas Gohr */ 93555efc227SAndreas Gohr function save($fileName = "") { 93655efc227SAndreas Gohr if ($fileName == "") { 93736df6fa3SAndreas Gohr $tmpName = tempnam(dirname($this->_fileName),'_metatemp_'); 93855efc227SAndreas Gohr $this->_writeJPEG($tmpName); 93979e79377SAndreas Gohr if (file_exists($tmpName)) { 940bf5e5a5bSAndreas Gohr return io_rename($tmpName, $this->_fileName); 94155efc227SAndreas Gohr } 94236df6fa3SAndreas Gohr } else { 94336df6fa3SAndreas Gohr return $this->_writeJPEG($fileName); 94455efc227SAndreas Gohr } 94536df6fa3SAndreas Gohr return false; 94655efc227SAndreas Gohr } 94755efc227SAndreas Gohr 94855efc227SAndreas Gohr /*************************************************************/ 94955efc227SAndreas Gohr /* PRIVATE FUNCTIONS (Internal Use Only!) */ 95055efc227SAndreas Gohr /*************************************************************/ 95155efc227SAndreas Gohr 95255efc227SAndreas Gohr /*************************************************************/ 9535aaca723SGerrit Uitslag function _dispose($fileName = "") { 95455efc227SAndreas Gohr $this->_fileName = $fileName; 95555efc227SAndreas Gohr 95655efc227SAndreas Gohr $this->_fp = null; 95755efc227SAndreas Gohr $this->_type = 'unknown'; 95855efc227SAndreas Gohr 95955efc227SAndreas Gohr unset($this->_markers); 96055efc227SAndreas Gohr unset($this->_info); 96155efc227SAndreas Gohr } 96255efc227SAndreas Gohr 96355efc227SAndreas Gohr /*************************************************************/ 9640b17fdc6SAndreas Gohr function _readJPEG() { 96555efc227SAndreas Gohr unset($this->_markers); 966a73b5b7eSAndreas Gohr //unset($this->_info); 96755efc227SAndreas Gohr $this->_markers = array(); 968a73b5b7eSAndreas Gohr //$this->_info = array(); 96955efc227SAndreas Gohr 97055efc227SAndreas Gohr $this->_fp = @fopen($this->_fileName, 'rb'); 97155efc227SAndreas Gohr if ($this->_fp) { 97255efc227SAndreas Gohr if (file_exists($this->_fileName)) { 97355efc227SAndreas Gohr $this->_type = 'file'; 97455efc227SAndreas Gohr } 97555efc227SAndreas Gohr else { 97655efc227SAndreas Gohr $this->_type = 'url'; 97755efc227SAndreas Gohr } 9780b17fdc6SAndreas Gohr } else { 97955efc227SAndreas Gohr $this->_fp = null; 98055efc227SAndreas Gohr return false; // ERROR: Can't open file 98155efc227SAndreas Gohr } 98255efc227SAndreas Gohr 98355efc227SAndreas Gohr // Check for the JPEG signature 98455efc227SAndreas Gohr $c1 = ord(fgetc($this->_fp)); 98555efc227SAndreas Gohr $c2 = ord(fgetc($this->_fp)); 98655efc227SAndreas Gohr 98755efc227SAndreas Gohr if ($c1 != 0xFF || $c2 != 0xD8) { // (0xFF + SOI) 98855efc227SAndreas Gohr $this->_markers = null; 98955efc227SAndreas Gohr return false; // ERROR: File is not a JPEG 99055efc227SAndreas Gohr } 99155efc227SAndreas Gohr 99255efc227SAndreas Gohr $count = 0; 99355efc227SAndreas Gohr 99455efc227SAndreas Gohr $done = false; 99555efc227SAndreas Gohr $ok = true; 99655efc227SAndreas Gohr 99755efc227SAndreas Gohr while (!$done) { 99855efc227SAndreas Gohr $capture = false; 99955efc227SAndreas Gohr 100055efc227SAndreas Gohr // First, skip any non 0xFF bytes 100155efc227SAndreas Gohr $discarded = 0; 100255efc227SAndreas Gohr $c = ord(fgetc($this->_fp)); 100355efc227SAndreas Gohr while (!feof($this->_fp) && ($c != 0xFF)) { 100455efc227SAndreas Gohr $discarded++; 100555efc227SAndreas Gohr $c = ord(fgetc($this->_fp)); 100655efc227SAndreas Gohr } 100755efc227SAndreas Gohr // Then skip all 0xFF until the marker byte 100855efc227SAndreas Gohr do { 100955efc227SAndreas Gohr $marker = ord(fgetc($this->_fp)); 101055efc227SAndreas Gohr } while (!feof($this->_fp) && ($marker == 0xFF)); 101155efc227SAndreas Gohr 101255efc227SAndreas Gohr if (feof($this->_fp)) { 101355efc227SAndreas Gohr return false; // ERROR: Unexpected EOF 101455efc227SAndreas Gohr } 101555efc227SAndreas Gohr if ($discarded != 0) { 101655efc227SAndreas Gohr return false; // ERROR: Extraneous data 101755efc227SAndreas Gohr } 101855efc227SAndreas Gohr 101955efc227SAndreas Gohr $length = ord(fgetc($this->_fp)) * 256 + ord(fgetc($this->_fp)); 102055efc227SAndreas Gohr if (feof($this->_fp)) { 102155efc227SAndreas Gohr return false; // ERROR: Unexpected EOF 102255efc227SAndreas Gohr } 102355efc227SAndreas Gohr if ($length < 2) { 102455efc227SAndreas Gohr return false; // ERROR: Extraneous data 102555efc227SAndreas Gohr } 102655efc227SAndreas Gohr $length = $length - 2; // The length we got counts itself 102755efc227SAndreas Gohr 102855efc227SAndreas Gohr switch ($marker) { 102955efc227SAndreas Gohr case 0xC0: // SOF0 103055efc227SAndreas Gohr case 0xC1: // SOF1 103155efc227SAndreas Gohr case 0xC2: // SOF2 103255efc227SAndreas Gohr case 0xC9: // SOF9 103355efc227SAndreas Gohr case 0xE0: // APP0: JFIF data 1034431c7fc8Shakan.sandell case 0xE1: // APP1: EXIF or XMP data 103555efc227SAndreas Gohr case 0xED: // APP13: IPTC / Photoshop data 103655efc227SAndreas Gohr $capture = true; 103755efc227SAndreas Gohr break; 103855efc227SAndreas Gohr case 0xDA: // SOS: Start of scan... the image itself and the last block on the file 103955efc227SAndreas Gohr $capture = false; 104055efc227SAndreas Gohr $length = -1; // This field has no length... it includes all data until EOF 104155efc227SAndreas Gohr $done = true; 104255efc227SAndreas Gohr break; 104355efc227SAndreas Gohr default: 104455efc227SAndreas Gohr $capture = true;//false; 104555efc227SAndreas Gohr break; 104655efc227SAndreas Gohr } 104755efc227SAndreas Gohr 104855efc227SAndreas Gohr $this->_markers[$count] = array(); 104955efc227SAndreas Gohr $this->_markers[$count]['marker'] = $marker; 105055efc227SAndreas Gohr $this->_markers[$count]['length'] = $length; 105155efc227SAndreas Gohr 105255efc227SAndreas Gohr if ($capture) { 1053ed3655c4STom N Harris if ($length) 10540ea5ced2SGerrit Uitslag $this->_markers[$count]['data'] = fread($this->_fp, $length); 1055ed3655c4STom N Harris else 1056ed3655c4STom N Harris $this->_markers[$count]['data'] = ""; 105755efc227SAndreas Gohr } 105855efc227SAndreas Gohr elseif (!$done) { 105955efc227SAndreas Gohr $result = @fseek($this->_fp, $length, SEEK_CUR); 106055efc227SAndreas Gohr // fseek doesn't seem to like HTTP 'files', but fgetc has no problem 106155efc227SAndreas Gohr if (!($result === 0)) { 106255efc227SAndreas Gohr for ($i = 0; $i < $length; $i++) { 106355efc227SAndreas Gohr fgetc($this->_fp); 106455efc227SAndreas Gohr } 106555efc227SAndreas Gohr } 106655efc227SAndreas Gohr } 106755efc227SAndreas Gohr $count++; 106855efc227SAndreas Gohr } 106955efc227SAndreas Gohr 107055efc227SAndreas Gohr if ($this->_fp) { 107155efc227SAndreas Gohr fclose($this->_fp); 107255efc227SAndreas Gohr $this->_fp = null; 107355efc227SAndreas Gohr } 107455efc227SAndreas Gohr 107555efc227SAndreas Gohr return $ok; 107655efc227SAndreas Gohr } 107755efc227SAndreas Gohr 107855efc227SAndreas Gohr /*************************************************************/ 10790b17fdc6SAndreas Gohr function _parseAll() { 10801017ae2eSAndreas Gohr if (!isset($this->_info['file'])) { 10811017ae2eSAndreas Gohr $this->_parseFileInfo(); 10821017ae2eSAndreas Gohr } 108355efc227SAndreas Gohr if (!isset($this->_markers)) { 108455efc227SAndreas Gohr $this->_readJPEG(); 108555efc227SAndreas Gohr } 108655efc227SAndreas Gohr 108755efc227SAndreas Gohr if ($this->_markers == null) { 108855efc227SAndreas Gohr return false; 108955efc227SAndreas Gohr } 109055efc227SAndreas Gohr 109155efc227SAndreas Gohr if (!isset($this->_info['jfif'])) { 109255efc227SAndreas Gohr $this->_parseMarkerJFIF(); 109355efc227SAndreas Gohr } 109455efc227SAndreas Gohr if (!isset($this->_info['jpeg'])) { 109555efc227SAndreas Gohr $this->_parseMarkerSOF(); 109655efc227SAndreas Gohr } 109755efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 109855efc227SAndreas Gohr $this->_parseMarkerExif(); 109955efc227SAndreas Gohr } 1100431c7fc8Shakan.sandell if (!isset($this->_info['xmp'])) { 1101431c7fc8Shakan.sandell $this->_parseMarkerXmp(); 1102431c7fc8Shakan.sandell } 110355efc227SAndreas Gohr if (!isset($this->_info['adobe'])) { 110455efc227SAndreas Gohr $this->_parseMarkerAdobe(); 110555efc227SAndreas Gohr } 110655efc227SAndreas Gohr } 110755efc227SAndreas Gohr 110855efc227SAndreas Gohr /*************************************************************/ 1109276820f7SScrutinizer Auto-Fixer 1110276820f7SScrutinizer Auto-Fixer /** 1111276820f7SScrutinizer Auto-Fixer * @param string $outputName 1112276820f7SScrutinizer Auto-Fixer */ 11130b17fdc6SAndreas Gohr function _writeJPEG($outputName) { 111455efc227SAndreas Gohr $this->_parseAll(); 111555efc227SAndreas Gohr 111655efc227SAndreas Gohr $wroteEXIF = false; 111755efc227SAndreas Gohr $wroteAdobe = false; 111855efc227SAndreas Gohr 111955efc227SAndreas Gohr $this->_fp = @fopen($this->_fileName, 'r'); 112055efc227SAndreas Gohr if ($this->_fp) { 112155efc227SAndreas Gohr if (file_exists($this->_fileName)) { 112255efc227SAndreas Gohr $this->_type = 'file'; 112355efc227SAndreas Gohr } 112455efc227SAndreas Gohr else { 112555efc227SAndreas Gohr $this->_type = 'url'; 112655efc227SAndreas Gohr } 11270b17fdc6SAndreas Gohr } else { 112855efc227SAndreas Gohr $this->_fp = null; 112955efc227SAndreas Gohr return false; // ERROR: Can't open file 113055efc227SAndreas Gohr } 113155efc227SAndreas Gohr 113255efc227SAndreas Gohr $this->_fpout = fopen($outputName, 'wb'); 11330b17fdc6SAndreas Gohr if (!$this->_fpout) { 113455efc227SAndreas Gohr $this->_fpout = null; 113555efc227SAndreas Gohr fclose($this->_fp); 113655efc227SAndreas Gohr $this->_fp = null; 113755efc227SAndreas Gohr return false; // ERROR: Can't open output file 113855efc227SAndreas Gohr } 113955efc227SAndreas Gohr 114055efc227SAndreas Gohr // Check for the JPEG signature 114155efc227SAndreas Gohr $c1 = ord(fgetc($this->_fp)); 114255efc227SAndreas Gohr $c2 = ord(fgetc($this->_fp)); 114355efc227SAndreas Gohr 114455efc227SAndreas Gohr if ($c1 != 0xFF || $c2 != 0xD8) { // (0xFF + SOI) 114555efc227SAndreas Gohr return false; // ERROR: File is not a JPEG 114655efc227SAndreas Gohr } 114755efc227SAndreas Gohr 114855efc227SAndreas Gohr fputs($this->_fpout, chr(0xFF), 1); 114955efc227SAndreas Gohr fputs($this->_fpout, chr(0xD8), 1); // (0xFF + SOI) 115055efc227SAndreas Gohr 115155efc227SAndreas Gohr $count = 0; 115255efc227SAndreas Gohr 115355efc227SAndreas Gohr $done = false; 115455efc227SAndreas Gohr $ok = true; 115555efc227SAndreas Gohr 115655efc227SAndreas Gohr while (!$done) { 115755efc227SAndreas Gohr // First, skip any non 0xFF bytes 115855efc227SAndreas Gohr $discarded = 0; 115955efc227SAndreas Gohr $c = ord(fgetc($this->_fp)); 116055efc227SAndreas Gohr while (!feof($this->_fp) && ($c != 0xFF)) { 116155efc227SAndreas Gohr $discarded++; 116255efc227SAndreas Gohr $c = ord(fgetc($this->_fp)); 116355efc227SAndreas Gohr } 116455efc227SAndreas Gohr // Then skip all 0xFF until the marker byte 116555efc227SAndreas Gohr do { 116655efc227SAndreas Gohr $marker = ord(fgetc($this->_fp)); 116755efc227SAndreas Gohr } while (!feof($this->_fp) && ($marker == 0xFF)); 116855efc227SAndreas Gohr 116955efc227SAndreas Gohr if (feof($this->_fp)) { 117055efc227SAndreas Gohr $ok = false; 117155efc227SAndreas Gohr break; // ERROR: Unexpected EOF 117255efc227SAndreas Gohr } 117355efc227SAndreas Gohr if ($discarded != 0) { 117455efc227SAndreas Gohr $ok = false; 117555efc227SAndreas Gohr break; // ERROR: Extraneous data 117655efc227SAndreas Gohr } 117755efc227SAndreas Gohr 117855efc227SAndreas Gohr $length = ord(fgetc($this->_fp)) * 256 + ord(fgetc($this->_fp)); 117955efc227SAndreas Gohr if (feof($this->_fp)) { 118055efc227SAndreas Gohr $ok = false; 118155efc227SAndreas Gohr break; // ERROR: Unexpected EOF 118255efc227SAndreas Gohr } 118355efc227SAndreas Gohr if ($length < 2) { 118455efc227SAndreas Gohr $ok = false; 118555efc227SAndreas Gohr break; // ERROR: Extraneous data 118655efc227SAndreas Gohr } 118755efc227SAndreas Gohr $length = $length - 2; // The length we got counts itself 118855efc227SAndreas Gohr 118955efc227SAndreas Gohr unset($data); 119055efc227SAndreas Gohr if ($marker == 0xE1) { // APP1: EXIF data 119155efc227SAndreas Gohr $data =& $this->_createMarkerEXIF(); 119255efc227SAndreas Gohr $wroteEXIF = true; 119355efc227SAndreas Gohr } 119455efc227SAndreas Gohr elseif ($marker == 0xED) { // APP13: IPTC / Photoshop data 119555efc227SAndreas Gohr $data =& $this->_createMarkerAdobe(); 119655efc227SAndreas Gohr $wroteAdobe = true; 119755efc227SAndreas Gohr } 119855efc227SAndreas Gohr elseif ($marker == 0xDA) { // SOS: Start of scan... the image itself and the last block on the file 119955efc227SAndreas Gohr $done = true; 120055efc227SAndreas Gohr } 120155efc227SAndreas Gohr 120255efc227SAndreas Gohr if (!$wroteEXIF && (($marker < 0xE0) || ($marker > 0xEF))) { 120355efc227SAndreas Gohr if (isset($this->_info['exif']) && is_array($this->_info['exif'])) { 120455efc227SAndreas Gohr $exif =& $this->_createMarkerEXIF(); 120555efc227SAndreas Gohr $this->_writeJPEGMarker(0xE1, strlen($exif), $exif, 0); 120655efc227SAndreas Gohr unset($exif); 120755efc227SAndreas Gohr } 120855efc227SAndreas Gohr $wroteEXIF = true; 120955efc227SAndreas Gohr } 121055efc227SAndreas Gohr 121155efc227SAndreas Gohr if (!$wroteAdobe && (($marker < 0xE0) || ($marker > 0xEF))) { 121255efc227SAndreas Gohr if ((isset($this->_info['adobe']) && is_array($this->_info['adobe'])) 121355efc227SAndreas Gohr || (isset($this->_info['iptc']) && is_array($this->_info['iptc']))) { 121455efc227SAndreas Gohr $adobe =& $this->_createMarkerAdobe(); 121555efc227SAndreas Gohr $this->_writeJPEGMarker(0xED, strlen($adobe), $adobe, 0); 121655efc227SAndreas Gohr unset($adobe); 121755efc227SAndreas Gohr } 121855efc227SAndreas Gohr $wroteAdobe = true; 121955efc227SAndreas Gohr } 122055efc227SAndreas Gohr 122155efc227SAndreas Gohr $origLength = $length; 122255efc227SAndreas Gohr if (isset($data)) { 122355efc227SAndreas Gohr $length = strlen($data); 122455efc227SAndreas Gohr } 122555efc227SAndreas Gohr 122655efc227SAndreas Gohr if ($marker != -1) { 122755efc227SAndreas Gohr $this->_writeJPEGMarker($marker, $length, $data, $origLength); 122855efc227SAndreas Gohr } 122955efc227SAndreas Gohr } 123055efc227SAndreas Gohr 123155efc227SAndreas Gohr if ($this->_fp) { 123255efc227SAndreas Gohr fclose($this->_fp); 123355efc227SAndreas Gohr $this->_fp = null; 123455efc227SAndreas Gohr } 123555efc227SAndreas Gohr 123655efc227SAndreas Gohr if ($this->_fpout) { 123755efc227SAndreas Gohr fclose($this->_fpout); 123855efc227SAndreas Gohr $this->_fpout = null; 123955efc227SAndreas Gohr } 124055efc227SAndreas Gohr 124155efc227SAndreas Gohr return $ok; 124255efc227SAndreas Gohr } 124355efc227SAndreas Gohr 124455efc227SAndreas Gohr /*************************************************************/ 1245276820f7SScrutinizer Auto-Fixer 1246276820f7SScrutinizer Auto-Fixer /** 1247276820f7SScrutinizer Auto-Fixer * @param integer $marker 1248276820f7SScrutinizer Auto-Fixer * @param integer $length 1249276820f7SScrutinizer Auto-Fixer * @param integer $origLength 1250276820f7SScrutinizer Auto-Fixer */ 12510b17fdc6SAndreas Gohr function _writeJPEGMarker($marker, $length, &$data, $origLength) { 125255efc227SAndreas Gohr if ($length <= 0) { 125355efc227SAndreas Gohr return false; 125455efc227SAndreas Gohr } 125555efc227SAndreas Gohr 125655efc227SAndreas Gohr fputs($this->_fpout, chr(0xFF), 1); 125755efc227SAndreas Gohr fputs($this->_fpout, chr($marker), 1); 125855efc227SAndreas Gohr fputs($this->_fpout, chr((($length + 2) & 0x0000FF00) >> 8), 1); 125955efc227SAndreas Gohr fputs($this->_fpout, chr((($length + 2) & 0x000000FF) >> 0), 1); 126055efc227SAndreas Gohr 126155efc227SAndreas Gohr if (isset($data)) { 126255efc227SAndreas Gohr // Copy the generated data 126355efc227SAndreas Gohr fputs($this->_fpout, $data, $length); 126455efc227SAndreas Gohr 126555efc227SAndreas Gohr if ($origLength > 0) { // Skip the original data 126655efc227SAndreas Gohr $result = @fseek($this->_fp, $origLength, SEEK_CUR); 126755efc227SAndreas Gohr // fseek doesn't seem to like HTTP 'files', but fgetc has no problem 126855efc227SAndreas Gohr if ($result != 0) { 126955efc227SAndreas Gohr for ($i = 0; $i < $origLength; $i++) { 127055efc227SAndreas Gohr fgetc($this->_fp); 127155efc227SAndreas Gohr } 127255efc227SAndreas Gohr } 127355efc227SAndreas Gohr } 12740b17fdc6SAndreas Gohr } else { 127555efc227SAndreas Gohr if ($marker == 0xDA) { // Copy until EOF 127655efc227SAndreas Gohr while (!feof($this->_fp)) { 1277ed3655c4STom N Harris $data = fread($this->_fp, 1024 * 16); 127855efc227SAndreas Gohr fputs($this->_fpout, $data, strlen($data)); 127955efc227SAndreas Gohr } 12800b17fdc6SAndreas Gohr } else { // Copy only $length bytes 1281ed3655c4STom N Harris $data = @fread($this->_fp, $length); 128255efc227SAndreas Gohr fputs($this->_fpout, $data, $length); 128355efc227SAndreas Gohr } 128455efc227SAndreas Gohr } 128555efc227SAndreas Gohr 128655efc227SAndreas Gohr return true; 128755efc227SAndreas Gohr } 128855efc227SAndreas Gohr 128923a34783SAndreas Gohr /** 129023a34783SAndreas Gohr * Gets basic info from the file - should work with non-JPEGs 129123a34783SAndreas Gohr * 129223a34783SAndreas Gohr * @author Sebastian Delmont <sdelmont@zonageek.com> 129323a34783SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 129423a34783SAndreas Gohr */ 12950b17fdc6SAndreas Gohr function _parseFileInfo() { 1296639f8f43SAndreas Gohr if (file_exists($this->_fileName) && is_file($this->_fileName)) { 129755efc227SAndreas Gohr $this->_info['file'] = array(); 129817dcc4abSAndreas Gohr $this->_info['file']['Name'] = utf8_decodeFN(utf8_basename($this->_fileName)); 129900976812SAndreas Gohr $this->_info['file']['Path'] = fullpath($this->_fileName); 130055efc227SAndreas Gohr $this->_info['file']['Size'] = filesize($this->_fileName); 130155efc227SAndreas Gohr if ($this->_info['file']['Size'] < 1024) { 130255efc227SAndreas Gohr $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B'; 13030b17fdc6SAndreas Gohr } elseif ($this->_info['file']['Size'] < (1024 * 1024)) { 130455efc227SAndreas Gohr $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / 1024) . 'KB'; 13050b17fdc6SAndreas Gohr } elseif ($this->_info['file']['Size'] < (1024 * 1024 * 1024)) { 1306fe00a666SAndreas Gohr $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / (1024*1024)) . 'MB'; 13070b17fdc6SAndreas Gohr } else { 130855efc227SAndreas Gohr $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B'; 130955efc227SAndreas Gohr } 131055efc227SAndreas Gohr $this->_info['file']['UnixTime'] = filemtime($this->_fileName); 131155efc227SAndreas Gohr 131255efc227SAndreas Gohr // get image size directly from file 131355efc227SAndreas Gohr $size = getimagesize($this->_fileName); 131455efc227SAndreas Gohr $this->_info['file']['Width'] = $size[0]; 131555efc227SAndreas Gohr $this->_info['file']['Height'] = $size[1]; 131655efc227SAndreas Gohr // set mime types and formats 1317*59752844SAnders Sandblad // http://php.net/manual/en/function.getimagesize.php 1318*59752844SAnders Sandblad // http://php.net/manual/en/function.image-type-to-mime-type.php 131955efc227SAndreas Gohr switch ($size[2]){ 132055efc227SAndreas Gohr case 1: 132155efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/gif'; 132255efc227SAndreas Gohr $this->_info['file']['Format'] = 'GIF'; 132355efc227SAndreas Gohr break; 132455efc227SAndreas Gohr case 2: 132555efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/jpeg'; 132655efc227SAndreas Gohr $this->_info['file']['Format'] = 'JPEG'; 132755efc227SAndreas Gohr break; 132855efc227SAndreas Gohr case 3: 132955efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/png'; 133055efc227SAndreas Gohr $this->_info['file']['Format'] = 'PNG'; 133155efc227SAndreas Gohr break; 133255efc227SAndreas Gohr case 4: 133355efc227SAndreas Gohr $this->_info['file']['Mime'] = 'application/x-shockwave-flash'; 133455efc227SAndreas Gohr $this->_info['file']['Format'] = 'SWF'; 133555efc227SAndreas Gohr break; 133655efc227SAndreas Gohr case 5: 133755efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/psd'; 133855efc227SAndreas Gohr $this->_info['file']['Format'] = 'PSD'; 133955efc227SAndreas Gohr break; 134055efc227SAndreas Gohr case 6: 134155efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/bmp'; 134255efc227SAndreas Gohr $this->_info['file']['Format'] = 'BMP'; 134355efc227SAndreas Gohr break; 134455efc227SAndreas Gohr case 7: 134555efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/tiff'; 134655efc227SAndreas Gohr $this->_info['file']['Format'] = 'TIFF (Intel)'; 134755efc227SAndreas Gohr break; 134855efc227SAndreas Gohr case 8: 134955efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/tiff'; 135055efc227SAndreas Gohr $this->_info['file']['Format'] = 'TIFF (Motorola)'; 135155efc227SAndreas Gohr break; 135255efc227SAndreas Gohr case 9: 135355efc227SAndreas Gohr $this->_info['file']['Mime'] = 'application/octet-stream'; 135455efc227SAndreas Gohr $this->_info['file']['Format'] = 'JPC'; 135555efc227SAndreas Gohr break; 135655efc227SAndreas Gohr case 10: 135755efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/jp2'; 135855efc227SAndreas Gohr $this->_info['file']['Format'] = 'JP2'; 135955efc227SAndreas Gohr break; 136055efc227SAndreas Gohr case 11: 136155efc227SAndreas Gohr $this->_info['file']['Mime'] = 'application/octet-stream'; 136255efc227SAndreas Gohr $this->_info['file']['Format'] = 'JPX'; 136355efc227SAndreas Gohr break; 136455efc227SAndreas Gohr case 12: 136555efc227SAndreas Gohr $this->_info['file']['Mime'] = 'application/octet-stream'; 136655efc227SAndreas Gohr $this->_info['file']['Format'] = 'JB2'; 136755efc227SAndreas Gohr break; 136855efc227SAndreas Gohr case 13: 136955efc227SAndreas Gohr $this->_info['file']['Mime'] = 'application/x-shockwave-flash'; 137055efc227SAndreas Gohr $this->_info['file']['Format'] = 'SWC'; 137155efc227SAndreas Gohr break; 137255efc227SAndreas Gohr case 14: 137355efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/iff'; 137455efc227SAndreas Gohr $this->_info['file']['Format'] = 'IFF'; 137555efc227SAndreas Gohr break; 137655efc227SAndreas Gohr case 15: 137755efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/vnd.wap.wbmp'; 137855efc227SAndreas Gohr $this->_info['file']['Format'] = 'WBMP'; 137955efc227SAndreas Gohr break; 138055efc227SAndreas Gohr case 16: 138155efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/xbm'; 138255efc227SAndreas Gohr $this->_info['file']['Format'] = 'XBM'; 138355efc227SAndreas Gohr break; 138455efc227SAndreas Gohr default: 138555efc227SAndreas Gohr $this->_info['file']['Mime'] = 'image/unknown'; 138655efc227SAndreas Gohr } 13870b17fdc6SAndreas Gohr } else { 138855efc227SAndreas Gohr $this->_info['file'] = array(); 13893009a773SAndreas Gohr $this->_info['file']['Name'] = utf8_basename($this->_fileName); 139055efc227SAndreas Gohr $this->_info['file']['Url'] = $this->_fileName; 139155efc227SAndreas Gohr } 139255efc227SAndreas Gohr 139355efc227SAndreas Gohr return true; 139455efc227SAndreas Gohr } 139555efc227SAndreas Gohr 139655efc227SAndreas Gohr /*************************************************************/ 13970b17fdc6SAndreas Gohr function _parseMarkerJFIF() { 139855efc227SAndreas Gohr if (!isset($this->_markers)) { 139955efc227SAndreas Gohr $this->_readJPEG(); 140055efc227SAndreas Gohr } 140155efc227SAndreas Gohr 140255efc227SAndreas Gohr if ($this->_markers == null) { 140355efc227SAndreas Gohr return false; 140455efc227SAndreas Gohr } 140555efc227SAndreas Gohr 140655efc227SAndreas Gohr $data = null; 140755efc227SAndreas Gohr $count = count($this->_markers); 140855efc227SAndreas Gohr for ($i = 0; $i < $count; $i++) { 140955efc227SAndreas Gohr if ($this->_markers[$i]['marker'] == 0xE0) { 141055efc227SAndreas Gohr $signature = $this->_getFixedString($this->_markers[$i]['data'], 0, 4); 141155efc227SAndreas Gohr if ($signature == 'JFIF') { 141255efc227SAndreas Gohr $data =& $this->_markers[$i]['data']; 141355efc227SAndreas Gohr break; 141455efc227SAndreas Gohr } 141555efc227SAndreas Gohr } 141655efc227SAndreas Gohr } 141755efc227SAndreas Gohr 141855efc227SAndreas Gohr if ($data == null) { 141955efc227SAndreas Gohr $this->_info['jfif'] = false; 142055efc227SAndreas Gohr return false; 142155efc227SAndreas Gohr } 142255efc227SAndreas Gohr 142355efc227SAndreas Gohr $this->_info['jfif'] = array(); 142455efc227SAndreas Gohr 142555efc227SAndreas Gohr $vmaj = $this->_getByte($data, 5); 142655efc227SAndreas Gohr $vmin = $this->_getByte($data, 6); 142755efc227SAndreas Gohr 142855efc227SAndreas Gohr $this->_info['jfif']['Version'] = sprintf('%d.%02d', $vmaj, $vmin); 142955efc227SAndreas Gohr 143055efc227SAndreas Gohr $units = $this->_getByte($data, 7); 143155efc227SAndreas Gohr switch ($units) { 143255efc227SAndreas Gohr case 0: 143355efc227SAndreas Gohr $this->_info['jfif']['Units'] = 'pixels'; 143455efc227SAndreas Gohr break; 143555efc227SAndreas Gohr case 1: 143655efc227SAndreas Gohr $this->_info['jfif']['Units'] = 'dpi'; 143755efc227SAndreas Gohr break; 143855efc227SAndreas Gohr case 2: 143955efc227SAndreas Gohr $this->_info['jfif']['Units'] = 'dpcm'; 144055efc227SAndreas Gohr break; 144155efc227SAndreas Gohr default: 144255efc227SAndreas Gohr $this->_info['jfif']['Units'] = 'unknown'; 144355efc227SAndreas Gohr break; 144455efc227SAndreas Gohr } 144555efc227SAndreas Gohr 144655efc227SAndreas Gohr $xdens = $this->_getShort($data, 8); 144755efc227SAndreas Gohr $ydens = $this->_getShort($data, 10); 144855efc227SAndreas Gohr 144955efc227SAndreas Gohr $this->_info['jfif']['XDensity'] = $xdens; 145055efc227SAndreas Gohr $this->_info['jfif']['YDensity'] = $ydens; 145155efc227SAndreas Gohr 145255efc227SAndreas Gohr $thumbx = $this->_getByte($data, 12); 145355efc227SAndreas Gohr $thumby = $this->_getByte($data, 13); 145455efc227SAndreas Gohr 145555efc227SAndreas Gohr $this->_info['jfif']['ThumbnailWidth'] = $thumbx; 145655efc227SAndreas Gohr $this->_info['jfif']['ThumbnailHeight'] = $thumby; 145755efc227SAndreas Gohr 145855efc227SAndreas Gohr return true; 145955efc227SAndreas Gohr } 146055efc227SAndreas Gohr 146155efc227SAndreas Gohr /*************************************************************/ 14620b17fdc6SAndreas Gohr function _parseMarkerSOF() { 146355efc227SAndreas Gohr if (!isset($this->_markers)) { 146455efc227SAndreas Gohr $this->_readJPEG(); 146555efc227SAndreas Gohr } 146655efc227SAndreas Gohr 146755efc227SAndreas Gohr if ($this->_markers == null) { 146855efc227SAndreas Gohr return false; 146955efc227SAndreas Gohr } 147055efc227SAndreas Gohr 147155efc227SAndreas Gohr $data = null; 147255efc227SAndreas Gohr $count = count($this->_markers); 147355efc227SAndreas Gohr for ($i = 0; $i < $count; $i++) { 147455efc227SAndreas Gohr switch ($this->_markers[$i]['marker']) { 147555efc227SAndreas Gohr case 0xC0: // SOF0 147655efc227SAndreas Gohr case 0xC1: // SOF1 147755efc227SAndreas Gohr case 0xC2: // SOF2 147855efc227SAndreas Gohr case 0xC9: // SOF9 147955efc227SAndreas Gohr $data =& $this->_markers[$i]['data']; 148055efc227SAndreas Gohr $marker = $this->_markers[$i]['marker']; 148155efc227SAndreas Gohr break; 148255efc227SAndreas Gohr } 148355efc227SAndreas Gohr } 148455efc227SAndreas Gohr 148555efc227SAndreas Gohr if ($data == null) { 148655efc227SAndreas Gohr $this->_info['sof'] = false; 148755efc227SAndreas Gohr return false; 148855efc227SAndreas Gohr } 148955efc227SAndreas Gohr 149055efc227SAndreas Gohr $pos = 0; 149155efc227SAndreas Gohr $this->_info['sof'] = array(); 149255efc227SAndreas Gohr 149355efc227SAndreas Gohr switch ($marker) { 149455efc227SAndreas Gohr case 0xC0: // SOF0 149555efc227SAndreas Gohr $format = 'Baseline'; 149655efc227SAndreas Gohr break; 149755efc227SAndreas Gohr case 0xC1: // SOF1 149855efc227SAndreas Gohr $format = 'Progessive'; 149955efc227SAndreas Gohr break; 150055efc227SAndreas Gohr case 0xC2: // SOF2 150155efc227SAndreas Gohr $format = 'Non-baseline'; 150255efc227SAndreas Gohr break; 150355efc227SAndreas Gohr case 0xC9: // SOF9 150455efc227SAndreas Gohr $format = 'Arithmetic'; 150555efc227SAndreas Gohr break; 150655efc227SAndreas Gohr default: 150755efc227SAndreas Gohr return false; 150855efc227SAndreas Gohr } 150955efc227SAndreas Gohr 151055efc227SAndreas Gohr $this->_info['sof']['Format'] = $format; 151155efc227SAndreas Gohr $this->_info['sof']['SamplePrecision'] = $this->_getByte($data, $pos + 0); 151255efc227SAndreas Gohr $this->_info['sof']['ImageHeight'] = $this->_getShort($data, $pos + 1); 151355efc227SAndreas Gohr $this->_info['sof']['ImageWidth'] = $this->_getShort($data, $pos + 3); 151455efc227SAndreas Gohr $this->_info['sof']['ColorChannels'] = $this->_getByte($data, $pos + 5); 151555efc227SAndreas Gohr 151655efc227SAndreas Gohr return true; 151755efc227SAndreas Gohr } 151855efc227SAndreas Gohr 1519431c7fc8Shakan.sandell /** 1520431c7fc8Shakan.sandell * Parses the XMP data 1521431c7fc8Shakan.sandell * 1522431c7fc8Shakan.sandell * @author Hakan Sandell <hakan.sandell@mydata.se> 1523431c7fc8Shakan.sandell */ 15240b17fdc6SAndreas Gohr function _parseMarkerXmp() { 1525431c7fc8Shakan.sandell if (!isset($this->_markers)) { 1526431c7fc8Shakan.sandell $this->_readJPEG(); 1527431c7fc8Shakan.sandell } 1528431c7fc8Shakan.sandell 1529431c7fc8Shakan.sandell if ($this->_markers == null) { 1530431c7fc8Shakan.sandell return false; 1531431c7fc8Shakan.sandell } 1532431c7fc8Shakan.sandell 1533431c7fc8Shakan.sandell $data = null; 1534431c7fc8Shakan.sandell $count = count($this->_markers); 1535431c7fc8Shakan.sandell for ($i = 0; $i < $count; $i++) { 1536431c7fc8Shakan.sandell if ($this->_markers[$i]['marker'] == 0xE1) { 1537431c7fc8Shakan.sandell $signature = $this->_getFixedString($this->_markers[$i]['data'], 0, 29); 1538431c7fc8Shakan.sandell if ($signature == "http://ns.adobe.com/xap/1.0/\0") { 1539f5891fa4SGerrit Uitslag $data = substr($this->_markers[$i]['data'], 29); 1540431c7fc8Shakan.sandell break; 1541431c7fc8Shakan.sandell } 1542431c7fc8Shakan.sandell } 1543431c7fc8Shakan.sandell } 1544431c7fc8Shakan.sandell 1545431c7fc8Shakan.sandell if ($data == null) { 1546431c7fc8Shakan.sandell $this->_info['xmp'] = false; 1547431c7fc8Shakan.sandell return false; 1548431c7fc8Shakan.sandell } 1549431c7fc8Shakan.sandell 1550431c7fc8Shakan.sandell $parser = xml_parser_create(); 1551431c7fc8Shakan.sandell xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); 1552431c7fc8Shakan.sandell xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); 1553d8443bf1SHakan Sandell $result = xml_parse_into_struct($parser, $data, $values, $tags); 1554431c7fc8Shakan.sandell xml_parser_free($parser); 1555431c7fc8Shakan.sandell 1556d8443bf1SHakan Sandell if ($result == 0) { 1557d8443bf1SHakan Sandell $this->_info['xmp'] = false; 1558d8443bf1SHakan Sandell return false; 1559d8443bf1SHakan Sandell } 1560d8443bf1SHakan Sandell 1561431c7fc8Shakan.sandell $this->_info['xmp'] = array(); 1562431c7fc8Shakan.sandell $count = count($values); 1563431c7fc8Shakan.sandell for ($i = 0; $i < $count; $i++) { 15640b17fdc6SAndreas Gohr if ($values[$i]['tag'] == 'rdf:Description' && $values[$i]['type'] == 'open') { 1565431c7fc8Shakan.sandell 1566d8443bf1SHakan Sandell while ((++$i < $count) && ($values[$i]['tag'] != 'rdf:Description')) { 1567d8443bf1SHakan Sandell $this->_parseXmpNode($values, $i, $this->_info['xmp'][$values[$i]['tag']], $count); 1568431c7fc8Shakan.sandell } 1569431c7fc8Shakan.sandell } 1570431c7fc8Shakan.sandell } 1571431c7fc8Shakan.sandell return true; 1572431c7fc8Shakan.sandell } 1573431c7fc8Shakan.sandell 1574431c7fc8Shakan.sandell /** 1575431c7fc8Shakan.sandell * Parses XMP nodes by recursion 1576431c7fc8Shakan.sandell * 1577431c7fc8Shakan.sandell * @author Hakan Sandell <hakan.sandell@mydata.se> 1578276820f7SScrutinizer Auto-Fixer * @param integer $count 1579431c7fc8Shakan.sandell */ 1580d8443bf1SHakan Sandell function _parseXmpNode($values, &$i, &$meta, $count) { 1581831c10d0SHakan Sandell if ($values[$i]['type'] == 'close') return; 1582831c10d0SHakan Sandell 15830b17fdc6SAndreas Gohr if ($values[$i]['type'] == 'complete') { 1584431c7fc8Shakan.sandell // Simple Type property 15850b17fdc6SAndreas Gohr $meta = $values[$i]['value']; 1586431c7fc8Shakan.sandell return; 1587431c7fc8Shakan.sandell } 1588431c7fc8Shakan.sandell 1589431c7fc8Shakan.sandell $i++; 1590d8443bf1SHakan Sandell if ($i >= $count) return; 1591d8443bf1SHakan Sandell 15920b17fdc6SAndreas Gohr if ($values[$i]['tag'] == 'rdf:Bag' || $values[$i]['tag'] == 'rdf:Seq') { 1593431c7fc8Shakan.sandell // Array property 1594431c7fc8Shakan.sandell $meta = array(); 15950b17fdc6SAndreas Gohr while ($values[++$i]['tag'] == 'rdf:li') { 1596d8443bf1SHakan Sandell $this->_parseXmpNode($values, $i, $meta[], $count); 1597431c7fc8Shakan.sandell } 1598831c10d0SHakan Sandell $i++; // skip closing Bag/Seq tag 1599431c7fc8Shakan.sandell 16000b17fdc6SAndreas Gohr } elseif ($values[$i]['tag'] == 'rdf:Alt') { 1601431c7fc8Shakan.sandell // Language Alternative property, only the first (default) value is used 1602831c10d0SHakan Sandell if ($values[$i]['type'] == 'open') { 1603431c7fc8Shakan.sandell $i++; 1604d8443bf1SHakan Sandell $this->_parseXmpNode($values, $i, $meta, $count); 1605d8443bf1SHakan Sandell while ((++$i < $count) && ($values[$i]['tag'] != 'rdf:Alt')); 1606831c10d0SHakan Sandell $i++; // skip closing Alt tag 1607831c10d0SHakan Sandell } 1608431c7fc8Shakan.sandell 1609431c7fc8Shakan.sandell } else { 1610431c7fc8Shakan.sandell // Structure property 1611431c7fc8Shakan.sandell $meta = array(); 16120b17fdc6SAndreas Gohr $startTag = $values[$i-1]['tag']; 1613431c7fc8Shakan.sandell do { 1614d8443bf1SHakan Sandell $this->_parseXmpNode($values, $i, $meta[$values[$i]['tag']], $count); 1615d8443bf1SHakan Sandell } while ((++$i < $count) && ($values[$i]['tag'] != $startTag)); 1616431c7fc8Shakan.sandell } 1617431c7fc8Shakan.sandell } 1618431c7fc8Shakan.sandell 161955efc227SAndreas Gohr /*************************************************************/ 16200b17fdc6SAndreas Gohr function _parseMarkerExif() { 162155efc227SAndreas Gohr if (!isset($this->_markers)) { 162255efc227SAndreas Gohr $this->_readJPEG(); 162355efc227SAndreas Gohr } 162455efc227SAndreas Gohr 162555efc227SAndreas Gohr if ($this->_markers == null) { 162655efc227SAndreas Gohr return false; 162755efc227SAndreas Gohr } 162855efc227SAndreas Gohr 162955efc227SAndreas Gohr $data = null; 163055efc227SAndreas Gohr $count = count($this->_markers); 163155efc227SAndreas Gohr for ($i = 0; $i < $count; $i++) { 163255efc227SAndreas Gohr if ($this->_markers[$i]['marker'] == 0xE1) { 163355efc227SAndreas Gohr $signature = $this->_getFixedString($this->_markers[$i]['data'], 0, 6); 163455efc227SAndreas Gohr if ($signature == "Exif\0\0") { 163555efc227SAndreas Gohr $data =& $this->_markers[$i]['data']; 163655efc227SAndreas Gohr break; 163755efc227SAndreas Gohr } 163855efc227SAndreas Gohr } 163955efc227SAndreas Gohr } 164055efc227SAndreas Gohr 164155efc227SAndreas Gohr if ($data == null) { 164255efc227SAndreas Gohr $this->_info['exif'] = false; 164355efc227SAndreas Gohr return false; 164455efc227SAndreas Gohr } 164555efc227SAndreas Gohr $pos = 6; 164655efc227SAndreas Gohr $this->_info['exif'] = array(); 164755efc227SAndreas Gohr 164855efc227SAndreas Gohr // We don't increment $pos after this because Exif uses offsets relative to this point 164955efc227SAndreas Gohr 165055efc227SAndreas Gohr $byteAlign = $this->_getShort($data, $pos + 0); 165155efc227SAndreas Gohr 165255efc227SAndreas Gohr if ($byteAlign == 0x4949) { // "II" 165355efc227SAndreas Gohr $isBigEndian = false; 16540b17fdc6SAndreas Gohr } elseif ($byteAlign == 0x4D4D) { // "MM" 165555efc227SAndreas Gohr $isBigEndian = true; 16560b17fdc6SAndreas Gohr } else { 165755efc227SAndreas Gohr return false; // Unexpected data 165855efc227SAndreas Gohr } 165955efc227SAndreas Gohr 166055efc227SAndreas Gohr $alignCheck = $this->_getShort($data, $pos + 2, $isBigEndian); 166155efc227SAndreas Gohr if ($alignCheck != 0x002A) // That's the expected value 166255efc227SAndreas Gohr return false; // Unexpected data 166355efc227SAndreas Gohr 166455efc227SAndreas Gohr if ($isBigEndian) { 166555efc227SAndreas Gohr $this->_info['exif']['ByteAlign'] = "Big Endian"; 16660b17fdc6SAndreas Gohr } else { 166755efc227SAndreas Gohr $this->_info['exif']['ByteAlign'] = "Little Endian"; 166855efc227SAndreas Gohr } 166955efc227SAndreas Gohr 167055efc227SAndreas Gohr $offsetIFD0 = $this->_getLong($data, $pos + 4, $isBigEndian); 167155efc227SAndreas Gohr if ($offsetIFD0 < 8) 167255efc227SAndreas Gohr return false; // Unexpected data 167355efc227SAndreas Gohr 167455efc227SAndreas Gohr $offsetIFD1 = $this->_readIFD($data, $pos, $offsetIFD0, $isBigEndian, 'ifd0'); 167555efc227SAndreas Gohr if ($offsetIFD1 != 0) 167655efc227SAndreas Gohr $this->_readIFD($data, $pos, $offsetIFD1, $isBigEndian, 'ifd1'); 167755efc227SAndreas Gohr 167855efc227SAndreas Gohr return true; 167955efc227SAndreas Gohr } 168055efc227SAndreas Gohr 168155efc227SAndreas Gohr /*************************************************************/ 1682276820f7SScrutinizer Auto-Fixer 1683276820f7SScrutinizer Auto-Fixer /** 1684276820f7SScrutinizer Auto-Fixer * @param integer $base 1685276820f7SScrutinizer Auto-Fixer * @param boolean $isBigEndian 1686276820f7SScrutinizer Auto-Fixer * @param string $mode 1687276820f7SScrutinizer Auto-Fixer */ 16880b17fdc6SAndreas Gohr function _readIFD($data, $base, $offset, $isBigEndian, $mode) { 168955efc227SAndreas Gohr $EXIFTags = $this->_exifTagNames($mode); 169055efc227SAndreas Gohr 169155efc227SAndreas Gohr $numEntries = $this->_getShort($data, $base + $offset, $isBigEndian); 169255efc227SAndreas Gohr $offset += 2; 169355efc227SAndreas Gohr 169455efc227SAndreas Gohr $exifTIFFOffset = 0; 169555efc227SAndreas Gohr $exifTIFFLength = 0; 169655efc227SAndreas Gohr $exifThumbnailOffset = 0; 169755efc227SAndreas Gohr $exifThumbnailLength = 0; 169855efc227SAndreas Gohr 169955efc227SAndreas Gohr for ($i = 0; $i < $numEntries; $i++) { 170055efc227SAndreas Gohr $tag = $this->_getShort($data, $base + $offset, $isBigEndian); 170155efc227SAndreas Gohr $offset += 2; 170255efc227SAndreas Gohr $type = $this->_getShort($data, $base + $offset, $isBigEndian); 170355efc227SAndreas Gohr $offset += 2; 170455efc227SAndreas Gohr $count = $this->_getLong($data, $base + $offset, $isBigEndian); 170555efc227SAndreas Gohr $offset += 4; 170655efc227SAndreas Gohr 170755efc227SAndreas Gohr if (($type < 1) || ($type > 12)) 170855efc227SAndreas Gohr return false; // Unexpected Type 170955efc227SAndreas Gohr 171055efc227SAndreas Gohr $typeLengths = array( -1, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8 ); 171155efc227SAndreas Gohr 171255efc227SAndreas Gohr $dataLength = $typeLengths[$type] * $count; 171355efc227SAndreas Gohr if ($dataLength > 4) { 171455efc227SAndreas Gohr $dataOffset = $this->_getLong($data, $base + $offset, $isBigEndian); 171555efc227SAndreas Gohr $rawValue = $this->_getFixedString($data, $base + $dataOffset, $dataLength); 17160b17fdc6SAndreas Gohr } else { 171755efc227SAndreas Gohr $rawValue = $this->_getFixedString($data, $base + $offset, $dataLength); 171855efc227SAndreas Gohr } 171955efc227SAndreas Gohr $offset += 4; 172055efc227SAndreas Gohr 172155efc227SAndreas Gohr switch ($type) { 172255efc227SAndreas Gohr case 1: // UBYTE 172355efc227SAndreas Gohr if ($count == 1) { 172455efc227SAndreas Gohr $value = $this->_getByte($rawValue, 0); 17250b17fdc6SAndreas Gohr } else { 172655efc227SAndreas Gohr $value = array(); 172755efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) 172855efc227SAndreas Gohr $value[$j] = $this->_getByte($rawValue, $j); 172955efc227SAndreas Gohr } 173055efc227SAndreas Gohr break; 173155efc227SAndreas Gohr case 2: // ASCII 173255efc227SAndreas Gohr $value = $rawValue; 173355efc227SAndreas Gohr break; 173455efc227SAndreas Gohr case 3: // USHORT 173555efc227SAndreas Gohr if ($count == 1) { 173655efc227SAndreas Gohr $value = $this->_getShort($rawValue, 0, $isBigEndian); 17370b17fdc6SAndreas Gohr } else { 173855efc227SAndreas Gohr $value = array(); 173955efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) 174055efc227SAndreas Gohr $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian); 174155efc227SAndreas Gohr } 174255efc227SAndreas Gohr break; 174355efc227SAndreas Gohr case 4: // ULONG 174455efc227SAndreas Gohr if ($count == 1) { 174555efc227SAndreas Gohr $value = $this->_getLong($rawValue, 0, $isBigEndian); 17460b17fdc6SAndreas Gohr } else { 174755efc227SAndreas Gohr $value = array(); 174855efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) 174955efc227SAndreas Gohr $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian); 175055efc227SAndreas Gohr } 175155efc227SAndreas Gohr break; 175255efc227SAndreas Gohr case 5: // URATIONAL 175355efc227SAndreas Gohr if ($count == 1) { 175455efc227SAndreas Gohr $a = $this->_getLong($rawValue, 0, $isBigEndian); 175555efc227SAndreas Gohr $b = $this->_getLong($rawValue, 4, $isBigEndian); 175655efc227SAndreas Gohr $value = array(); 175755efc227SAndreas Gohr $value['val'] = 0; 175855efc227SAndreas Gohr $value['num'] = $a; 175955efc227SAndreas Gohr $value['den'] = $b; 176055efc227SAndreas Gohr if (($a != 0) && ($b != 0)) { 176155efc227SAndreas Gohr $value['val'] = $a / $b; 176255efc227SAndreas Gohr } 17630b17fdc6SAndreas Gohr } else { 176455efc227SAndreas Gohr $value = array(); 176555efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) { 176655efc227SAndreas Gohr $a = $this->_getLong($rawValue, $j * 8, $isBigEndian); 176755efc227SAndreas Gohr $b = $this->_getLong($rawValue, ($j * 8) + 4, $isBigEndian); 176855efc227SAndreas Gohr $value = array(); 176955efc227SAndreas Gohr $value[$j]['val'] = 0; 177055efc227SAndreas Gohr $value[$j]['num'] = $a; 177155efc227SAndreas Gohr $value[$j]['den'] = $b; 177255efc227SAndreas Gohr if (($a != 0) && ($b != 0)) 177355efc227SAndreas Gohr $value[$j]['val'] = $a / $b; 177455efc227SAndreas Gohr } 177555efc227SAndreas Gohr } 177655efc227SAndreas Gohr break; 177755efc227SAndreas Gohr case 6: // SBYTE 177855efc227SAndreas Gohr if ($count == 1) { 177955efc227SAndreas Gohr $value = $this->_getByte($rawValue, 0); 17800b17fdc6SAndreas Gohr } else { 178155efc227SAndreas Gohr $value = array(); 178255efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) 178355efc227SAndreas Gohr $value[$j] = $this->_getByte($rawValue, $j); 178455efc227SAndreas Gohr } 178555efc227SAndreas Gohr break; 178655efc227SAndreas Gohr case 7: // UNDEFINED 178755efc227SAndreas Gohr $value = $rawValue; 178855efc227SAndreas Gohr break; 178955efc227SAndreas Gohr case 8: // SSHORT 179055efc227SAndreas Gohr if ($count == 1) { 179155efc227SAndreas Gohr $value = $this->_getShort($rawValue, 0, $isBigEndian); 17920b17fdc6SAndreas Gohr } else { 179355efc227SAndreas Gohr $value = array(); 179455efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) 179555efc227SAndreas Gohr $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian); 179655efc227SAndreas Gohr } 179755efc227SAndreas Gohr break; 179855efc227SAndreas Gohr case 9: // SLONG 179955efc227SAndreas Gohr if ($count == 1) { 180055efc227SAndreas Gohr $value = $this->_getLong($rawValue, 0, $isBigEndian); 18010b17fdc6SAndreas Gohr } else { 180255efc227SAndreas Gohr $value = array(); 180355efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) 180455efc227SAndreas Gohr $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian); 180555efc227SAndreas Gohr } 180655efc227SAndreas Gohr break; 180755efc227SAndreas Gohr case 10: // SRATIONAL 180855efc227SAndreas Gohr if ($count == 1) { 180955efc227SAndreas Gohr $a = $this->_getLong($rawValue, 0, $isBigEndian); 181055efc227SAndreas Gohr $b = $this->_getLong($rawValue, 4, $isBigEndian); 181155efc227SAndreas Gohr $value = array(); 181255efc227SAndreas Gohr $value['val'] = 0; 181355efc227SAndreas Gohr $value['num'] = $a; 181455efc227SAndreas Gohr $value['den'] = $b; 181555efc227SAndreas Gohr if (($a != 0) && ($b != 0)) 181655efc227SAndreas Gohr $value['val'] = $a / $b; 18170b17fdc6SAndreas Gohr } else { 181855efc227SAndreas Gohr $value = array(); 181955efc227SAndreas Gohr for ($j = 0; $j < $count; $j++) { 182055efc227SAndreas Gohr $a = $this->_getLong($rawValue, $j * 8, $isBigEndian); 182155efc227SAndreas Gohr $b = $this->_getLong($rawValue, ($j * 8) + 4, $isBigEndian); 182255efc227SAndreas Gohr $value = array(); 182355efc227SAndreas Gohr $value[$j]['val'] = 0; 182455efc227SAndreas Gohr $value[$j]['num'] = $a; 182555efc227SAndreas Gohr $value[$j]['den'] = $b; 182655efc227SAndreas Gohr if (($a != 0) && ($b != 0)) 182755efc227SAndreas Gohr $value[$j]['val'] = $a / $b; 182855efc227SAndreas Gohr } 182955efc227SAndreas Gohr } 183055efc227SAndreas Gohr break; 183155efc227SAndreas Gohr case 11: // FLOAT 183255efc227SAndreas Gohr $value = $rawValue; 183355efc227SAndreas Gohr break; 183455efc227SAndreas Gohr 183555efc227SAndreas Gohr case 12: // DFLOAT 183655efc227SAndreas Gohr $value = $rawValue; 183755efc227SAndreas Gohr break; 183855efc227SAndreas Gohr default: 183955efc227SAndreas Gohr return false; // Unexpected Type 184055efc227SAndreas Gohr } 184155efc227SAndreas Gohr 184255efc227SAndreas Gohr $tagName = ''; 184355efc227SAndreas Gohr if (($mode == 'ifd0') && ($tag == 0x8769)) { // ExifIFDOffset 184455efc227SAndreas Gohr $this->_readIFD($data, $base, $value, $isBigEndian, 'exif'); 18450b17fdc6SAndreas Gohr } elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset 184655efc227SAndreas Gohr $this->_readIFD($data, $base, $value, $isBigEndian, 'gps'); 18470b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets 184855efc227SAndreas Gohr $exifTIFFOffset = $value; 18490b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts 185055efc227SAndreas Gohr $exifTIFFLength = $value; 18510b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset 185255efc227SAndreas Gohr $exifThumbnailOffset = $value; 18530b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength 185455efc227SAndreas Gohr $exifThumbnailLength = $value; 18550b17fdc6SAndreas Gohr } elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset 185655efc227SAndreas Gohr $this->_readIFD($data, $base, $value, $isBigEndian, 'interop'); 185755efc227SAndreas Gohr } 185855efc227SAndreas Gohr // elseif (($mode == 'exif') && ($tag == 0x927C)) { // MakerNote 185955efc227SAndreas Gohr // } 186055efc227SAndreas Gohr else { 186155efc227SAndreas Gohr if (isset($EXIFTags[$tag])) { 186255efc227SAndreas Gohr $tagName = $EXIFTags[$tag]; 186355efc227SAndreas Gohr if (isset($this->_info['exif'][$tagName])) { 186455efc227SAndreas Gohr if (!is_array($this->_info['exif'][$tagName])) { 186555efc227SAndreas Gohr $aux = array(); 186655efc227SAndreas Gohr $aux[0] = $this->_info['exif'][$tagName]; 186755efc227SAndreas Gohr $this->_info['exif'][$tagName] = $aux; 186855efc227SAndreas Gohr } 186955efc227SAndreas Gohr 187055efc227SAndreas Gohr $this->_info['exif'][$tagName][count($this->_info['exif'][$tagName])] = $value; 18710b17fdc6SAndreas Gohr } else { 187255efc227SAndreas Gohr $this->_info['exif'][$tagName] = $value; 187355efc227SAndreas Gohr } 187455efc227SAndreas Gohr } 18750b17fdc6SAndreas Gohr /* 187655efc227SAndreas Gohr else { 18770b17fdc6SAndreas Gohr echo sprintf("<h1>Unknown tag %02x (t: %d l: %d) %s in %s</h1>", $tag, $type, $count, $mode, $this->_fileName); 187855efc227SAndreas Gohr // Unknown Tags will be ignored!!! 187955efc227SAndreas Gohr // That's because the tag might be a pointer (like the Exif tag) 188055efc227SAndreas Gohr // and saving it without saving the data it points to might 188155efc227SAndreas Gohr // create an invalid file. 188255efc227SAndreas Gohr } 18830b17fdc6SAndreas Gohr */ 188455efc227SAndreas Gohr } 188555efc227SAndreas Gohr } 188655efc227SAndreas Gohr 188755efc227SAndreas Gohr if (($exifThumbnailOffset > 0) && ($exifThumbnailLength > 0)) { 188855efc227SAndreas Gohr $this->_info['exif']['JFIFThumbnail'] = $this->_getFixedString($data, $base + $exifThumbnailOffset, $exifThumbnailLength); 188955efc227SAndreas Gohr } 189055efc227SAndreas Gohr 189155efc227SAndreas Gohr if (($exifTIFFOffset > 0) && ($exifTIFFLength > 0)) { 189255efc227SAndreas Gohr $this->_info['exif']['TIFFStrips'] = $this->_getFixedString($data, $base + $exifTIFFOffset, $exifTIFFLength); 189355efc227SAndreas Gohr } 189455efc227SAndreas Gohr 189555efc227SAndreas Gohr $nextOffset = $this->_getLong($data, $base + $offset, $isBigEndian); 189655efc227SAndreas Gohr return $nextOffset; 189755efc227SAndreas Gohr } 189855efc227SAndreas Gohr 189955efc227SAndreas Gohr /*************************************************************/ 19000b17fdc6SAndreas Gohr function & _createMarkerExif() { 190155efc227SAndreas Gohr $data = null; 190255efc227SAndreas Gohr $count = count($this->_markers); 190355efc227SAndreas Gohr for ($i = 0; $i < $count; $i++) { 190455efc227SAndreas Gohr if ($this->_markers[$i]['marker'] == 0xE1) { 190555efc227SAndreas Gohr $signature = $this->_getFixedString($this->_markers[$i]['data'], 0, 6); 190655efc227SAndreas Gohr if ($signature == "Exif\0\0") { 190755efc227SAndreas Gohr $data =& $this->_markers[$i]['data']; 190855efc227SAndreas Gohr break; 190955efc227SAndreas Gohr } 191055efc227SAndreas Gohr } 191155efc227SAndreas Gohr } 191255efc227SAndreas Gohr 191355efc227SAndreas Gohr if (!isset($this->_info['exif'])) { 191455efc227SAndreas Gohr return false; 191555efc227SAndreas Gohr } 191655efc227SAndreas Gohr 191755efc227SAndreas Gohr $data = "Exif\0\0"; 191855efc227SAndreas Gohr $pos = 6; 191955efc227SAndreas Gohr $offsetBase = 6; 192055efc227SAndreas Gohr 192155efc227SAndreas Gohr if (isset($this->_info['exif']['ByteAlign']) && ($this->_info['exif']['ByteAlign'] == "Big Endian")) { 192255efc227SAndreas Gohr $isBigEndian = true; 192355efc227SAndreas Gohr $aux = "MM"; 192455efc227SAndreas Gohr $pos = $this->_putString($data, $pos, $aux); 19250b17fdc6SAndreas Gohr } else { 192655efc227SAndreas Gohr $isBigEndian = false; 192755efc227SAndreas Gohr $aux = "II"; 192855efc227SAndreas Gohr $pos = $this->_putString($data, $pos, $aux); 192955efc227SAndreas Gohr } 193055efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, 0x002A, $isBigEndian); 193155efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, 0x00000008, $isBigEndian); // IFD0 Offset is always 8 193255efc227SAndreas Gohr 193355efc227SAndreas Gohr $ifd0 =& $this->_getIFDEntries($isBigEndian, 'ifd0'); 193455efc227SAndreas Gohr $ifd1 =& $this->_getIFDEntries($isBigEndian, 'ifd1'); 193555efc227SAndreas Gohr 193655efc227SAndreas Gohr $pos = $this->_writeIFD($data, $pos, $offsetBase, $ifd0, $isBigEndian, true); 193755efc227SAndreas Gohr $pos = $this->_writeIFD($data, $pos, $offsetBase, $ifd1, $isBigEndian, false); 193855efc227SAndreas Gohr 193955efc227SAndreas Gohr return $data; 194055efc227SAndreas Gohr } 194155efc227SAndreas Gohr 194255efc227SAndreas Gohr /*************************************************************/ 1943276820f7SScrutinizer Auto-Fixer 1944276820f7SScrutinizer Auto-Fixer /** 1945276820f7SScrutinizer Auto-Fixer * @param integer $offsetBase 1946276820f7SScrutinizer Auto-Fixer * @param boolean $isBigEndian 1947276820f7SScrutinizer Auto-Fixer * @param boolean $hasNext 1948276820f7SScrutinizer Auto-Fixer */ 19490b17fdc6SAndreas Gohr function _writeIFD(&$data, $pos, $offsetBase, &$entries, $isBigEndian, $hasNext) { 195055efc227SAndreas Gohr $tiffData = null; 195155efc227SAndreas Gohr $tiffDataOffsetPos = -1; 195255efc227SAndreas Gohr 195355efc227SAndreas Gohr $entryCount = count($entries); 195455efc227SAndreas Gohr 195555efc227SAndreas Gohr $dataPos = $pos + 2 + ($entryCount * 12) + 4; 195655efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, $entryCount, $isBigEndian); 195755efc227SAndreas Gohr 195855efc227SAndreas Gohr for ($i = 0; $i < $entryCount; $i++) { 195955efc227SAndreas Gohr $tag = $entries[$i]['tag']; 196055efc227SAndreas Gohr $type = $entries[$i]['type']; 196155efc227SAndreas Gohr 196255efc227SAndreas Gohr if ($type == -99) { // SubIFD 196355efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, $tag, $isBigEndian); 196455efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, 0x04, $isBigEndian); // LONG 196555efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, 0x01, $isBigEndian); // Count = 1 196655efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian); 196755efc227SAndreas Gohr 196855efc227SAndreas Gohr $dataPos = $this->_writeIFD($data, $dataPos, $offsetBase, $entries[$i]['value'], $isBigEndian, false); 19690b17fdc6SAndreas Gohr } elseif ($type == -98) { // TIFF Data 197055efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, $tag, $isBigEndian); 197155efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, 0x04, $isBigEndian); // LONG 197255efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, 0x01, $isBigEndian); // Count = 1 197355efc227SAndreas Gohr $tiffDataOffsetPos = $pos; 197455efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, 0x00, $isBigEndian); // For Now 197555efc227SAndreas Gohr $tiffData =& $entries[$i]['value'] ; 19760b17fdc6SAndreas Gohr } else { // Regular Entry 197755efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, $tag, $isBigEndian); 197855efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, $type, $isBigEndian); 197955efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, $entries[$i]['count'], $isBigEndian); 198055efc227SAndreas Gohr if (strlen($entries[$i]['value']) > 4) { 198155efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian); 198255efc227SAndreas Gohr $dataPos = $this->_putString($data, $dataPos, $entries[$i]['value']); 19830b17fdc6SAndreas Gohr } else { 198455efc227SAndreas Gohr $val = str_pad($entries[$i]['value'], 4, "\0"); 198555efc227SAndreas Gohr $pos = $this->_putString($data, $pos, $val); 198655efc227SAndreas Gohr } 198755efc227SAndreas Gohr } 198855efc227SAndreas Gohr } 198955efc227SAndreas Gohr 199055efc227SAndreas Gohr if ($tiffData != null) { 199155efc227SAndreas Gohr $this->_putLong($data, $tiffDataOffsetPos, $dataPos - $offsetBase, $isBigEndian); 199255efc227SAndreas Gohr $dataPos = $this->_putString($data, $dataPos, $tiffData); 199355efc227SAndreas Gohr } 199455efc227SAndreas Gohr 199555efc227SAndreas Gohr if ($hasNext) { 199655efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian); 19970b17fdc6SAndreas Gohr } else { 199855efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, 0, $isBigEndian); 199955efc227SAndreas Gohr } 200055efc227SAndreas Gohr 200155efc227SAndreas Gohr return $dataPos; 200255efc227SAndreas Gohr } 200355efc227SAndreas Gohr 200455efc227SAndreas Gohr /*************************************************************/ 2005276820f7SScrutinizer Auto-Fixer 2006276820f7SScrutinizer Auto-Fixer /** 2007276820f7SScrutinizer Auto-Fixer * @param boolean $isBigEndian 2008276820f7SScrutinizer Auto-Fixer * @param string $mode 2009276820f7SScrutinizer Auto-Fixer */ 20100b17fdc6SAndreas Gohr function & _getIFDEntries($isBigEndian, $mode) { 201155efc227SAndreas Gohr $EXIFNames = $this->_exifTagNames($mode); 201255efc227SAndreas Gohr $EXIFTags = $this->_exifNameTags($mode); 201355efc227SAndreas Gohr $EXIFTypeInfo = $this->_exifTagTypes($mode); 201455efc227SAndreas Gohr 201555efc227SAndreas Gohr $ifdEntries = array(); 201655efc227SAndreas Gohr $entryCount = 0; 201755efc227SAndreas Gohr 201855efc227SAndreas Gohr reset($EXIFNames); 201955efc227SAndreas Gohr while (list($tag, $name) = each($EXIFNames)) { 202055efc227SAndreas Gohr $type = $EXIFTypeInfo[$tag][0]; 202155efc227SAndreas Gohr $count = $EXIFTypeInfo[$tag][1]; 202255efc227SAndreas Gohr $value = null; 202355efc227SAndreas Gohr 202455efc227SAndreas Gohr if (($mode == 'ifd0') && ($tag == 0x8769)) { // ExifIFDOffset 202555efc227SAndreas Gohr if (isset($this->_info['exif']['EXIFVersion'])) { 202655efc227SAndreas Gohr $value =& $this->_getIFDEntries($isBigEndian, "exif"); 202755efc227SAndreas Gohr $type = -99; 202855efc227SAndreas Gohr } 202955efc227SAndreas Gohr else { 203055efc227SAndreas Gohr $value = null; 203155efc227SAndreas Gohr } 20320b17fdc6SAndreas Gohr } elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset 203355efc227SAndreas Gohr if (isset($this->_info['exif']['GPSVersionID'])) { 203455efc227SAndreas Gohr $value =& $this->_getIFDEntries($isBigEndian, "gps"); 203555efc227SAndreas Gohr $type = -99; 20360b17fdc6SAndreas Gohr } else { 203755efc227SAndreas Gohr $value = null; 203855efc227SAndreas Gohr } 20390b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets 204055efc227SAndreas Gohr if (isset($this->_info['exif']['TIFFStrips'])) { 204155efc227SAndreas Gohr $value =& $this->_info['exif']['TIFFStrips']; 204255efc227SAndreas Gohr $type = -98; 20430b17fdc6SAndreas Gohr } else { 204455efc227SAndreas Gohr $value = null; 204555efc227SAndreas Gohr } 20460b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts 204755efc227SAndreas Gohr if (isset($this->_info['exif']['TIFFStrips'])) { 204855efc227SAndreas Gohr $value = strlen($this->_info['exif']['TIFFStrips']); 20490b17fdc6SAndreas Gohr } else { 205055efc227SAndreas Gohr $value = null; 205155efc227SAndreas Gohr } 20520b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset 205355efc227SAndreas Gohr if (isset($this->_info['exif']['JFIFThumbnail'])) { 205455efc227SAndreas Gohr $value =& $this->_info['exif']['JFIFThumbnail']; 205555efc227SAndreas Gohr $type = -98; 20560b17fdc6SAndreas Gohr } else { 205755efc227SAndreas Gohr $value = null; 205855efc227SAndreas Gohr } 20590b17fdc6SAndreas Gohr } elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength 206055efc227SAndreas Gohr if (isset($this->_info['exif']['JFIFThumbnail'])) { 206155efc227SAndreas Gohr $value = strlen($this->_info['exif']['JFIFThumbnail']); 20620b17fdc6SAndreas Gohr } else { 206355efc227SAndreas Gohr $value = null; 206455efc227SAndreas Gohr } 20650b17fdc6SAndreas Gohr } elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset 206655efc227SAndreas Gohr if (isset($this->_info['exif']['InteroperabilityIndex'])) { 206755efc227SAndreas Gohr $value =& $this->_getIFDEntries($isBigEndian, "interop"); 206855efc227SAndreas Gohr $type = -99; 20690b17fdc6SAndreas Gohr } else { 207055efc227SAndreas Gohr $value = null; 207155efc227SAndreas Gohr } 20720b17fdc6SAndreas Gohr } elseif (isset($this->_info['exif'][$name])) { 207355efc227SAndreas Gohr $origValue =& $this->_info['exif'][$name]; 207455efc227SAndreas Gohr 207555efc227SAndreas Gohr // This makes it easier to process variable size elements 207655efc227SAndreas Gohr if (!is_array($origValue) || isset($origValue['val'])) { 207755efc227SAndreas Gohr unset($origValue); // Break the reference 207855efc227SAndreas Gohr $origValue = array($this->_info['exif'][$name]); 207955efc227SAndreas Gohr } 208055efc227SAndreas Gohr $origCount = count($origValue); 208155efc227SAndreas Gohr 208255efc227SAndreas Gohr if ($origCount == 0 ) { 208355efc227SAndreas Gohr $type = -1; // To ignore this field 208455efc227SAndreas Gohr } 208555efc227SAndreas Gohr 208655efc227SAndreas Gohr $value = " "; 208755efc227SAndreas Gohr 208855efc227SAndreas Gohr switch ($type) { 208955efc227SAndreas Gohr case 1: // UBYTE 209055efc227SAndreas Gohr if ($count == 0) { 209155efc227SAndreas Gohr $count = $origCount; 209255efc227SAndreas Gohr } 209355efc227SAndreas Gohr 209455efc227SAndreas Gohr $j = 0; 209555efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 209655efc227SAndreas Gohr 209755efc227SAndreas Gohr $this->_putByte($value, $j, $origValue[$j]); 209855efc227SAndreas Gohr $j++; 209955efc227SAndreas Gohr } 210055efc227SAndreas Gohr 210155efc227SAndreas Gohr while ($j < $count) { 210255efc227SAndreas Gohr $this->_putByte($value, $j, 0); 210355efc227SAndreas Gohr $j++; 210455efc227SAndreas Gohr } 210555efc227SAndreas Gohr break; 210655efc227SAndreas Gohr case 2: // ASCII 210755efc227SAndreas Gohr $v = strval($origValue[0]); 210855efc227SAndreas Gohr if (($count != 0) && (strlen($v) > $count)) { 210955efc227SAndreas Gohr $v = substr($v, 0, $count); 211055efc227SAndreas Gohr } 211155efc227SAndreas Gohr elseif (($count > 0) && (strlen($v) < $count)) { 211255efc227SAndreas Gohr $v = str_pad($v, $count, "\0"); 211355efc227SAndreas Gohr } 211455efc227SAndreas Gohr 211555efc227SAndreas Gohr $count = strlen($v); 211655efc227SAndreas Gohr 211755efc227SAndreas Gohr $this->_putString($value, 0, $v); 211855efc227SAndreas Gohr break; 211955efc227SAndreas Gohr case 3: // USHORT 212055efc227SAndreas Gohr if ($count == 0) { 212155efc227SAndreas Gohr $count = $origCount; 212255efc227SAndreas Gohr } 212355efc227SAndreas Gohr 212455efc227SAndreas Gohr $j = 0; 212555efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 212655efc227SAndreas Gohr $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian); 212755efc227SAndreas Gohr $j++; 212855efc227SAndreas Gohr } 212955efc227SAndreas Gohr 213055efc227SAndreas Gohr while ($j < $count) { 213155efc227SAndreas Gohr $this->_putShort($value, $j * 2, 0, $isBigEndian); 213255efc227SAndreas Gohr $j++; 213355efc227SAndreas Gohr } 213455efc227SAndreas Gohr break; 213555efc227SAndreas Gohr case 4: // ULONG 213655efc227SAndreas Gohr if ($count == 0) { 213755efc227SAndreas Gohr $count = $origCount; 213855efc227SAndreas Gohr } 213955efc227SAndreas Gohr 214055efc227SAndreas Gohr $j = 0; 214155efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 214255efc227SAndreas Gohr $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian); 214355efc227SAndreas Gohr $j++; 214455efc227SAndreas Gohr } 214555efc227SAndreas Gohr 214655efc227SAndreas Gohr while ($j < $count) { 214755efc227SAndreas Gohr $this->_putLong($value, $j * 4, 0, $isBigEndian); 214855efc227SAndreas Gohr $j++; 214955efc227SAndreas Gohr } 215055efc227SAndreas Gohr break; 215155efc227SAndreas Gohr case 5: // URATIONAL 215255efc227SAndreas Gohr if ($count == 0) { 215355efc227SAndreas Gohr $count = $origCount; 215455efc227SAndreas Gohr } 215555efc227SAndreas Gohr 215655efc227SAndreas Gohr $j = 0; 215755efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 215855efc227SAndreas Gohr $v = $origValue[$j]; 215955efc227SAndreas Gohr if (is_array($v)) { 216055efc227SAndreas Gohr $a = $v['num']; 216155efc227SAndreas Gohr $b = $v['den']; 216255efc227SAndreas Gohr } 216355efc227SAndreas Gohr else { 216455efc227SAndreas Gohr $a = 0; 216555efc227SAndreas Gohr $b = 0; 216655efc227SAndreas Gohr // TODO: Allow other types and convert them 216755efc227SAndreas Gohr } 216855efc227SAndreas Gohr $this->_putLong($value, $j * 8, $a, $isBigEndian); 216955efc227SAndreas Gohr $this->_putLong($value, ($j * 8) + 4, $b, $isBigEndian); 217055efc227SAndreas Gohr $j++; 217155efc227SAndreas Gohr } 217255efc227SAndreas Gohr 217355efc227SAndreas Gohr while ($j < $count) { 217455efc227SAndreas Gohr $this->_putLong($value, $j * 8, 0, $isBigEndian); 217555efc227SAndreas Gohr $this->_putLong($value, ($j * 8) + 4, 0, $isBigEndian); 217655efc227SAndreas Gohr $j++; 217755efc227SAndreas Gohr } 217855efc227SAndreas Gohr break; 217955efc227SAndreas Gohr case 6: // SBYTE 218055efc227SAndreas Gohr if ($count == 0) { 218155efc227SAndreas Gohr $count = $origCount; 218255efc227SAndreas Gohr } 218355efc227SAndreas Gohr 218455efc227SAndreas Gohr $j = 0; 218555efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 218655efc227SAndreas Gohr $this->_putByte($value, $j, $origValue[$j]); 218755efc227SAndreas Gohr $j++; 218855efc227SAndreas Gohr } 218955efc227SAndreas Gohr 219055efc227SAndreas Gohr while ($j < $count) { 219155efc227SAndreas Gohr $this->_putByte($value, $j, 0); 219255efc227SAndreas Gohr $j++; 219355efc227SAndreas Gohr } 219455efc227SAndreas Gohr break; 219555efc227SAndreas Gohr case 7: // UNDEFINED 219655efc227SAndreas Gohr $v = strval($origValue[0]); 219755efc227SAndreas Gohr if (($count != 0) && (strlen($v) > $count)) { 219855efc227SAndreas Gohr $v = substr($v, 0, $count); 219955efc227SAndreas Gohr } 220055efc227SAndreas Gohr elseif (($count > 0) && (strlen($v) < $count)) { 220155efc227SAndreas Gohr $v = str_pad($v, $count, "\0"); 220255efc227SAndreas Gohr } 220355efc227SAndreas Gohr 220455efc227SAndreas Gohr $count = strlen($v); 220555efc227SAndreas Gohr 220655efc227SAndreas Gohr $this->_putString($value, 0, $v); 220755efc227SAndreas Gohr break; 220855efc227SAndreas Gohr case 8: // SSHORT 220955efc227SAndreas Gohr if ($count == 0) { 221055efc227SAndreas Gohr $count = $origCount; 221155efc227SAndreas Gohr } 221255efc227SAndreas Gohr 221355efc227SAndreas Gohr $j = 0; 221455efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 221555efc227SAndreas Gohr $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian); 221655efc227SAndreas Gohr $j++; 221755efc227SAndreas Gohr } 221855efc227SAndreas Gohr 221955efc227SAndreas Gohr while ($j < $count) { 222055efc227SAndreas Gohr $this->_putShort($value, $j * 2, 0, $isBigEndian); 222155efc227SAndreas Gohr $j++; 222255efc227SAndreas Gohr } 222355efc227SAndreas Gohr break; 222455efc227SAndreas Gohr case 9: // SLONG 222555efc227SAndreas Gohr if ($count == 0) { 222655efc227SAndreas Gohr $count = $origCount; 222755efc227SAndreas Gohr } 222855efc227SAndreas Gohr 222955efc227SAndreas Gohr $j = 0; 223055efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 223155efc227SAndreas Gohr $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian); 223255efc227SAndreas Gohr $j++; 223355efc227SAndreas Gohr } 223455efc227SAndreas Gohr 223555efc227SAndreas Gohr while ($j < $count) { 223655efc227SAndreas Gohr $this->_putLong($value, $j * 4, 0, $isBigEndian); 223755efc227SAndreas Gohr $j++; 223855efc227SAndreas Gohr } 223955efc227SAndreas Gohr break; 224055efc227SAndreas Gohr case 10: // SRATIONAL 224155efc227SAndreas Gohr if ($count == 0) { 224255efc227SAndreas Gohr $count = $origCount; 224355efc227SAndreas Gohr } 224455efc227SAndreas Gohr 224555efc227SAndreas Gohr $j = 0; 224655efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 224755efc227SAndreas Gohr $v = $origValue[$j]; 224855efc227SAndreas Gohr if (is_array($v)) { 224955efc227SAndreas Gohr $a = $v['num']; 225055efc227SAndreas Gohr $b = $v['den']; 225155efc227SAndreas Gohr } 225255efc227SAndreas Gohr else { 225355efc227SAndreas Gohr $a = 0; 225455efc227SAndreas Gohr $b = 0; 225555efc227SAndreas Gohr // TODO: Allow other types and convert them 225655efc227SAndreas Gohr } 225755efc227SAndreas Gohr 225855efc227SAndreas Gohr $this->_putLong($value, $j * 8, $a, $isBigEndian); 225955efc227SAndreas Gohr $this->_putLong($value, ($j * 8) + 4, $b, $isBigEndian); 226055efc227SAndreas Gohr $j++; 226155efc227SAndreas Gohr } 226255efc227SAndreas Gohr 226355efc227SAndreas Gohr while ($j < $count) { 226455efc227SAndreas Gohr $this->_putLong($value, $j * 8, 0, $isBigEndian); 226555efc227SAndreas Gohr $this->_putLong($value, ($j * 8) + 4, 0, $isBigEndian); 226655efc227SAndreas Gohr $j++; 226755efc227SAndreas Gohr } 226855efc227SAndreas Gohr break; 226955efc227SAndreas Gohr case 11: // FLOAT 227055efc227SAndreas Gohr if ($count == 0) { 227155efc227SAndreas Gohr $count = $origCount; 227255efc227SAndreas Gohr } 227355efc227SAndreas Gohr 227455efc227SAndreas Gohr $j = 0; 227555efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 227655efc227SAndreas Gohr $v = strval($origValue[$j]); 227755efc227SAndreas Gohr if (strlen($v) > 4) { 227855efc227SAndreas Gohr $v = substr($v, 0, 4); 227955efc227SAndreas Gohr } 228055efc227SAndreas Gohr elseif (strlen($v) < 4) { 228155efc227SAndreas Gohr $v = str_pad($v, 4, "\0"); 228255efc227SAndreas Gohr } 228355efc227SAndreas Gohr $this->_putString($value, $j * 4, $v); 228455efc227SAndreas Gohr $j++; 228555efc227SAndreas Gohr } 228655efc227SAndreas Gohr 228755efc227SAndreas Gohr while ($j < $count) { 22885aaca723SGerrit Uitslag $v = "\0\0\0\0"; 22895aaca723SGerrit Uitslag $this->_putString($value, $j * 4, $v); 229055efc227SAndreas Gohr $j++; 229155efc227SAndreas Gohr } 229255efc227SAndreas Gohr break; 229355efc227SAndreas Gohr case 12: // DFLOAT 229455efc227SAndreas Gohr if ($count == 0) { 229555efc227SAndreas Gohr $count = $origCount; 229655efc227SAndreas Gohr } 229755efc227SAndreas Gohr 229855efc227SAndreas Gohr $j = 0; 229955efc227SAndreas Gohr while (($j < $count) && ($j < $origCount)) { 230055efc227SAndreas Gohr $v = strval($origValue[$j]); 230155efc227SAndreas Gohr if (strlen($v) > 8) { 230255efc227SAndreas Gohr $v = substr($v, 0, 8); 230355efc227SAndreas Gohr } 230455efc227SAndreas Gohr elseif (strlen($v) < 8) { 230555efc227SAndreas Gohr $v = str_pad($v, 8, "\0"); 230655efc227SAndreas Gohr } 230755efc227SAndreas Gohr $this->_putString($value, $j * 8, $v); 230855efc227SAndreas Gohr $j++; 230955efc227SAndreas Gohr } 231055efc227SAndreas Gohr 231155efc227SAndreas Gohr while ($j < $count) { 23125aaca723SGerrit Uitslag $v = "\0\0\0\0\0\0\0\0"; 23135aaca723SGerrit Uitslag $this->_putString($value, $j * 8, $v); 231455efc227SAndreas Gohr $j++; 231555efc227SAndreas Gohr } 231655efc227SAndreas Gohr break; 231755efc227SAndreas Gohr default: 231855efc227SAndreas Gohr $value = null; 231955efc227SAndreas Gohr break; 232055efc227SAndreas Gohr } 232155efc227SAndreas Gohr } 232255efc227SAndreas Gohr 232355efc227SAndreas Gohr if ($value != null) { 232455efc227SAndreas Gohr $ifdEntries[$entryCount] = array(); 232555efc227SAndreas Gohr $ifdEntries[$entryCount]['tag'] = $tag; 232655efc227SAndreas Gohr $ifdEntries[$entryCount]['type'] = $type; 232755efc227SAndreas Gohr $ifdEntries[$entryCount]['count'] = $count; 232855efc227SAndreas Gohr $ifdEntries[$entryCount]['value'] = $value; 232955efc227SAndreas Gohr 233055efc227SAndreas Gohr $entryCount++; 233155efc227SAndreas Gohr } 233255efc227SAndreas Gohr } 233355efc227SAndreas Gohr 233455efc227SAndreas Gohr return $ifdEntries; 233555efc227SAndreas Gohr } 233655efc227SAndreas Gohr 233755efc227SAndreas Gohr /*************************************************************/ 23380b17fdc6SAndreas Gohr function _parseMarkerAdobe() { 233955efc227SAndreas Gohr if (!isset($this->_markers)) { 234055efc227SAndreas Gohr $this->_readJPEG(); 234155efc227SAndreas Gohr } 234255efc227SAndreas Gohr 234355efc227SAndreas Gohr if ($this->_markers == null) { 234455efc227SAndreas Gohr return false; 234555efc227SAndreas Gohr } 234655efc227SAndreas Gohr 234755efc227SAndreas Gohr $data = null; 234855efc227SAndreas Gohr $count = count($this->_markers); 234955efc227SAndreas Gohr for ($i = 0; $i < $count; $i++) { 235055efc227SAndreas Gohr if ($this->_markers[$i]['marker'] == 0xED) { 235155efc227SAndreas Gohr $signature = $this->_getFixedString($this->_markers[$i]['data'], 0, 14); 235255efc227SAndreas Gohr if ($signature == "Photoshop 3.0\0") { 235355efc227SAndreas Gohr $data =& $this->_markers[$i]['data']; 235455efc227SAndreas Gohr break; 235555efc227SAndreas Gohr } 235655efc227SAndreas Gohr } 235755efc227SAndreas Gohr } 235855efc227SAndreas Gohr 235955efc227SAndreas Gohr if ($data == null) { 236055efc227SAndreas Gohr $this->_info['adobe'] = false; 236155efc227SAndreas Gohr $this->_info['iptc'] = false; 236255efc227SAndreas Gohr return false; 236355efc227SAndreas Gohr } 236455efc227SAndreas Gohr $pos = 14; 236555efc227SAndreas Gohr $this->_info['adobe'] = array(); 236655efc227SAndreas Gohr $this->_info['adobe']['raw'] = array(); 236755efc227SAndreas Gohr $this->_info['iptc'] = array(); 236855efc227SAndreas Gohr 236955efc227SAndreas Gohr $datasize = strlen($data); 237055efc227SAndreas Gohr 237155efc227SAndreas Gohr while ($pos < $datasize) { 237255efc227SAndreas Gohr $signature = $this->_getFixedString($data, $pos, 4); 237355efc227SAndreas Gohr if ($signature != '8BIM') 237455efc227SAndreas Gohr return false; 237555efc227SAndreas Gohr $pos += 4; 237655efc227SAndreas Gohr 237755efc227SAndreas Gohr $type = $this->_getShort($data, $pos); 237855efc227SAndreas Gohr $pos += 2; 237955efc227SAndreas Gohr 238055efc227SAndreas Gohr $strlen = $this->_getByte($data, $pos); 238155efc227SAndreas Gohr $pos += 1; 238255efc227SAndreas Gohr $header = ''; 238355efc227SAndreas Gohr for ($i = 0; $i < $strlen; $i++) { 238455efc227SAndreas Gohr $header .= $data{$pos + $i}; 238555efc227SAndreas Gohr } 238655efc227SAndreas Gohr $pos += $strlen + 1 - ($strlen % 2); // The string is padded to even length, counting the length byte itself 238755efc227SAndreas Gohr 238855efc227SAndreas Gohr $length = $this->_getLong($data, $pos); 238955efc227SAndreas Gohr $pos += 4; 239055efc227SAndreas Gohr 239155efc227SAndreas Gohr $basePos = $pos; 239255efc227SAndreas Gohr 239355efc227SAndreas Gohr switch ($type) { 239455efc227SAndreas Gohr case 0x0404: // Caption (IPTC Data) 239555efc227SAndreas Gohr $pos = $this->_readIPTC($data, $pos); 239655efc227SAndreas Gohr if ($pos == false) 239755efc227SAndreas Gohr return false; 239855efc227SAndreas Gohr break; 239955efc227SAndreas Gohr case 0x040A: // CopyrightFlag 240055efc227SAndreas Gohr $this->_info['adobe']['CopyrightFlag'] = $this->_getByte($data, $pos); 240155efc227SAndreas Gohr $pos += $length; 240255efc227SAndreas Gohr break; 240355efc227SAndreas Gohr case 0x040B: // ImageURL 240455efc227SAndreas Gohr $this->_info['adobe']['ImageURL'] = $this->_getFixedString($data, $pos, $length); 240555efc227SAndreas Gohr $pos += $length; 240655efc227SAndreas Gohr break; 240755efc227SAndreas Gohr case 0x040C: // Thumbnail 240855efc227SAndreas Gohr $aux = $this->_getLong($data, $pos); 240955efc227SAndreas Gohr $pos += 4; 241055efc227SAndreas Gohr if ($aux == 1) { 241155efc227SAndreas Gohr $this->_info['adobe']['ThumbnailWidth'] = $this->_getLong($data, $pos); 241255efc227SAndreas Gohr $pos += 4; 241355efc227SAndreas Gohr $this->_info['adobe']['ThumbnailHeight'] = $this->_getLong($data, $pos); 241455efc227SAndreas Gohr $pos += 4; 241555efc227SAndreas Gohr 241655efc227SAndreas Gohr $pos += 16; // Skip some data 241755efc227SAndreas Gohr 241855efc227SAndreas Gohr $this->_info['adobe']['ThumbnailData'] = $this->_getFixedString($data, $pos, $length - 28); 241955efc227SAndreas Gohr $pos += $length - 28; 242055efc227SAndreas Gohr } 242155efc227SAndreas Gohr break; 242255efc227SAndreas Gohr default: 242355efc227SAndreas Gohr break; 242455efc227SAndreas Gohr } 242555efc227SAndreas Gohr 242655efc227SAndreas Gohr // We save all blocks, even those we recognized 242755efc227SAndreas Gohr $label = sprintf('8BIM_0x%04x', $type); 242855efc227SAndreas Gohr $this->_info['adobe']['raw'][$label] = array(); 242955efc227SAndreas Gohr $this->_info['adobe']['raw'][$label]['type'] = $type; 243055efc227SAndreas Gohr $this->_info['adobe']['raw'][$label]['header'] = $header; 243155efc227SAndreas Gohr $this->_info['adobe']['raw'][$label]['data'] =& $this->_getFixedString($data, $basePos, $length); 243255efc227SAndreas Gohr 243355efc227SAndreas Gohr $pos = $basePos + $length + ($length % 2); // Even padding 243455efc227SAndreas Gohr } 243555efc227SAndreas Gohr 243655efc227SAndreas Gohr } 243755efc227SAndreas Gohr 243855efc227SAndreas Gohr /*************************************************************/ 24390b17fdc6SAndreas Gohr function _readIPTC(&$data, $pos = 0) { 244055efc227SAndreas Gohr $totalLength = strlen($data); 244155efc227SAndreas Gohr 2442f5891fa4SGerrit Uitslag $IPTCTags = $this->_iptcTagNames(); 244355efc227SAndreas Gohr 244455efc227SAndreas Gohr while ($pos < ($totalLength - 5)) { 244555efc227SAndreas Gohr $signature = $this->_getShort($data, $pos); 244655efc227SAndreas Gohr if ($signature != 0x1C02) 244755efc227SAndreas Gohr return $pos; 244855efc227SAndreas Gohr $pos += 2; 244955efc227SAndreas Gohr 245055efc227SAndreas Gohr $type = $this->_getByte($data, $pos); 245155efc227SAndreas Gohr $pos += 1; 245255efc227SAndreas Gohr $length = $this->_getShort($data, $pos); 245355efc227SAndreas Gohr $pos += 2; 245455efc227SAndreas Gohr 245555efc227SAndreas Gohr $basePos = $pos; 245655efc227SAndreas Gohr $label = ''; 245755efc227SAndreas Gohr 245855efc227SAndreas Gohr if (isset($IPTCTags[$type])) { 245955efc227SAndreas Gohr $label = $IPTCTags[$type]; 24600b17fdc6SAndreas Gohr } else { 246155efc227SAndreas Gohr $label = sprintf('IPTC_0x%02x', $type); 246255efc227SAndreas Gohr } 246355efc227SAndreas Gohr 246455efc227SAndreas Gohr if ($label != '') { 246555efc227SAndreas Gohr if (isset($this->_info['iptc'][$label])) { 246655efc227SAndreas Gohr if (!is_array($this->_info['iptc'][$label])) { 246755efc227SAndreas Gohr $aux = array(); 246855efc227SAndreas Gohr $aux[0] = $this->_info['iptc'][$label]; 246955efc227SAndreas Gohr $this->_info['iptc'][$label] = $aux; 247055efc227SAndreas Gohr } 247155efc227SAndreas Gohr $this->_info['iptc'][$label][ count($this->_info['iptc'][$label]) ] = $this->_getFixedString($data, $pos, $length); 24720b17fdc6SAndreas Gohr } else { 247355efc227SAndreas Gohr $this->_info['iptc'][$label] = $this->_getFixedString($data, $pos, $length); 247455efc227SAndreas Gohr } 247555efc227SAndreas Gohr } 247655efc227SAndreas Gohr 247755efc227SAndreas Gohr $pos = $basePos + $length; // No padding 247855efc227SAndreas Gohr } 247955efc227SAndreas Gohr return $pos; 248055efc227SAndreas Gohr } 248155efc227SAndreas Gohr 248255efc227SAndreas Gohr /*************************************************************/ 24830b17fdc6SAndreas Gohr function & _createMarkerAdobe() { 248455efc227SAndreas Gohr if (isset($this->_info['iptc'])) { 248555efc227SAndreas Gohr if (!isset($this->_info['adobe'])) { 248655efc227SAndreas Gohr $this->_info['adobe'] = array(); 248755efc227SAndreas Gohr } 248855efc227SAndreas Gohr if (!isset($this->_info['adobe']['raw'])) { 248955efc227SAndreas Gohr $this->_info['adobe']['raw'] = array(); 249055efc227SAndreas Gohr } 249155efc227SAndreas Gohr if (!isset($this->_info['adobe']['raw']['8BIM_0x0404'])) { 249255efc227SAndreas Gohr $this->_info['adobe']['raw']['8BIM_0x0404'] = array(); 249355efc227SAndreas Gohr } 249455efc227SAndreas Gohr $this->_info['adobe']['raw']['8BIM_0x0404']['type'] = 0x0404; 249555efc227SAndreas Gohr $this->_info['adobe']['raw']['8BIM_0x0404']['header'] = "Caption"; 249655efc227SAndreas Gohr $this->_info['adobe']['raw']['8BIM_0x0404']['data'] =& $this->_writeIPTC(); 249755efc227SAndreas Gohr } 249855efc227SAndreas Gohr 249955efc227SAndreas Gohr if (isset($this->_info['adobe']['raw']) && (count($this->_info['adobe']['raw']) > 0)) { 250055efc227SAndreas Gohr $data = "Photoshop 3.0\0"; 250155efc227SAndreas Gohr $pos = 14; 250255efc227SAndreas Gohr 250355efc227SAndreas Gohr reset($this->_info['adobe']['raw']); 250455efc227SAndreas Gohr while (list($key) = each($this->_info['adobe']['raw'])) { 250555efc227SAndreas Gohr $pos = $this->_write8BIM( 250655efc227SAndreas Gohr $data, 250755efc227SAndreas Gohr $pos, 250855efc227SAndreas Gohr $this->_info['adobe']['raw'][$key]['type'], 250955efc227SAndreas Gohr $this->_info['adobe']['raw'][$key]['header'], 251055efc227SAndreas Gohr $this->_info['adobe']['raw'][$key]['data'] ); 251155efc227SAndreas Gohr } 251255efc227SAndreas Gohr } 251355efc227SAndreas Gohr 251455efc227SAndreas Gohr return $data; 251555efc227SAndreas Gohr } 251655efc227SAndreas Gohr 251755efc227SAndreas Gohr /*************************************************************/ 2518276820f7SScrutinizer Auto-Fixer 2519276820f7SScrutinizer Auto-Fixer /** 2520276820f7SScrutinizer Auto-Fixer * @param integer $pos 2521276820f7SScrutinizer Auto-Fixer */ 25220b17fdc6SAndreas Gohr function _write8BIM(&$data, $pos, $type, $header, &$value) { 252355efc227SAndreas Gohr $signature = "8BIM"; 252455efc227SAndreas Gohr 252555efc227SAndreas Gohr $pos = $this->_putString($data, $pos, $signature); 252655efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, $type); 252755efc227SAndreas Gohr 252855efc227SAndreas Gohr $len = strlen($header); 252955efc227SAndreas Gohr 253055efc227SAndreas Gohr $pos = $this->_putByte($data, $pos, $len); 253155efc227SAndreas Gohr $pos = $this->_putString($data, $pos, $header); 253255efc227SAndreas Gohr if (($len % 2) == 0) { // Even padding, including the length byte 253355efc227SAndreas Gohr $pos = $this->_putByte($data, $pos, 0); 253455efc227SAndreas Gohr } 253555efc227SAndreas Gohr 253655efc227SAndreas Gohr $len = strlen($value); 253755efc227SAndreas Gohr $pos = $this->_putLong($data, $pos, $len); 253855efc227SAndreas Gohr $pos = $this->_putString($data, $pos, $value); 253955efc227SAndreas Gohr if (($len % 2) != 0) { // Even padding 254055efc227SAndreas Gohr $pos = $this->_putByte($data, $pos, 0); 254155efc227SAndreas Gohr } 254255efc227SAndreas Gohr return $pos; 254355efc227SAndreas Gohr } 254455efc227SAndreas Gohr 254555efc227SAndreas Gohr /*************************************************************/ 25460b17fdc6SAndreas Gohr function & _writeIPTC() { 254755efc227SAndreas Gohr $data = " "; 254855efc227SAndreas Gohr $pos = 0; 254955efc227SAndreas Gohr 255055efc227SAndreas Gohr $IPTCNames =& $this->_iptcNameTags(); 255155efc227SAndreas Gohr 255255efc227SAndreas Gohr reset($this->_info['iptc']); 255355efc227SAndreas Gohr 255455efc227SAndreas Gohr while (list($label) = each($this->_info['iptc'])) { 255555efc227SAndreas Gohr $value =& $this->_info['iptc'][$label]; 255655efc227SAndreas Gohr $type = -1; 255755efc227SAndreas Gohr 255855efc227SAndreas Gohr if (isset($IPTCNames[$label])) { 255955efc227SAndreas Gohr $type = $IPTCNames[$label]; 256055efc227SAndreas Gohr } 256155efc227SAndreas Gohr elseif (substr($label, 0, 7) == "IPTC_0x") { 256255efc227SAndreas Gohr $type = hexdec(substr($label, 7, 2)); 256355efc227SAndreas Gohr } 256455efc227SAndreas Gohr 256555efc227SAndreas Gohr if ($type != -1) { 256655efc227SAndreas Gohr if (is_array($value)) { 25670b17fdc6SAndreas Gohr $vcnt = count($value); 25680b17fdc6SAndreas Gohr for ($i = 0; $i < $vcnt; $i++) { 256955efc227SAndreas Gohr $pos = $this->_writeIPTCEntry($data, $pos, $type, $value[$i]); 257055efc227SAndreas Gohr } 257155efc227SAndreas Gohr } 257255efc227SAndreas Gohr else { 257355efc227SAndreas Gohr $pos = $this->_writeIPTCEntry($data, $pos, $type, $value); 257455efc227SAndreas Gohr } 257555efc227SAndreas Gohr } 257655efc227SAndreas Gohr } 257755efc227SAndreas Gohr 257855efc227SAndreas Gohr return $data; 257955efc227SAndreas Gohr } 258055efc227SAndreas Gohr 258155efc227SAndreas Gohr /*************************************************************/ 2582276820f7SScrutinizer Auto-Fixer 2583276820f7SScrutinizer Auto-Fixer /** 2584276820f7SScrutinizer Auto-Fixer * @param integer $pos 2585276820f7SScrutinizer Auto-Fixer */ 25860b17fdc6SAndreas Gohr function _writeIPTCEntry(&$data, $pos, $type, &$value) { 258755efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, 0x1C02); 258855efc227SAndreas Gohr $pos = $this->_putByte($data, $pos, $type); 258955efc227SAndreas Gohr $pos = $this->_putShort($data, $pos, strlen($value)); 259055efc227SAndreas Gohr $pos = $this->_putString($data, $pos, $value); 259155efc227SAndreas Gohr 259255efc227SAndreas Gohr return $pos; 259355efc227SAndreas Gohr } 259455efc227SAndreas Gohr 259555efc227SAndreas Gohr /*************************************************************/ 25960b17fdc6SAndreas Gohr function _exifTagNames($mode) { 259755efc227SAndreas Gohr $tags = array(); 259855efc227SAndreas Gohr 259955efc227SAndreas Gohr if ($mode == 'ifd0') { 260055efc227SAndreas Gohr $tags[0x010E] = 'ImageDescription'; 260155efc227SAndreas Gohr $tags[0x010F] = 'Make'; 260255efc227SAndreas Gohr $tags[0x0110] = 'Model'; 260355efc227SAndreas Gohr $tags[0x0112] = 'Orientation'; 260455efc227SAndreas Gohr $tags[0x011A] = 'XResolution'; 260555efc227SAndreas Gohr $tags[0x011B] = 'YResolution'; 260655efc227SAndreas Gohr $tags[0x0128] = 'ResolutionUnit'; 260755efc227SAndreas Gohr $tags[0x0131] = 'Software'; 260855efc227SAndreas Gohr $tags[0x0132] = 'DateTime'; 260955efc227SAndreas Gohr $tags[0x013B] = 'Artist'; 261055efc227SAndreas Gohr $tags[0x013E] = 'WhitePoint'; 261155efc227SAndreas Gohr $tags[0x013F] = 'PrimaryChromaticities'; 261255efc227SAndreas Gohr $tags[0x0211] = 'YCbCrCoefficients'; 261355efc227SAndreas Gohr $tags[0x0212] = 'YCbCrSubSampling'; 261455efc227SAndreas Gohr $tags[0x0213] = 'YCbCrPositioning'; 261555efc227SAndreas Gohr $tags[0x0214] = 'ReferenceBlackWhite'; 261655efc227SAndreas Gohr $tags[0x8298] = 'Copyright'; 261755efc227SAndreas Gohr $tags[0x8769] = 'ExifIFDOffset'; 261855efc227SAndreas Gohr $tags[0x8825] = 'GPSIFDOffset'; 261955efc227SAndreas Gohr } 262055efc227SAndreas Gohr if ($mode == 'ifd1') { 262155efc227SAndreas Gohr $tags[0x00FE] = 'TIFFNewSubfileType'; 262255efc227SAndreas Gohr $tags[0x00FF] = 'TIFFSubfileType'; 262355efc227SAndreas Gohr $tags[0x0100] = 'TIFFImageWidth'; 262455efc227SAndreas Gohr $tags[0x0101] = 'TIFFImageHeight'; 262555efc227SAndreas Gohr $tags[0x0102] = 'TIFFBitsPerSample'; 262655efc227SAndreas Gohr $tags[0x0103] = 'TIFFCompression'; 262755efc227SAndreas Gohr $tags[0x0106] = 'TIFFPhotometricInterpretation'; 262855efc227SAndreas Gohr $tags[0x0107] = 'TIFFThreshholding'; 262955efc227SAndreas Gohr $tags[0x0108] = 'TIFFCellWidth'; 263055efc227SAndreas Gohr $tags[0x0109] = 'TIFFCellLength'; 263155efc227SAndreas Gohr $tags[0x010A] = 'TIFFFillOrder'; 263255efc227SAndreas Gohr $tags[0x010E] = 'TIFFImageDescription'; 263355efc227SAndreas Gohr $tags[0x010F] = 'TIFFMake'; 263455efc227SAndreas Gohr $tags[0x0110] = 'TIFFModel'; 263555efc227SAndreas Gohr $tags[0x0111] = 'TIFFStripOffsets'; 263655efc227SAndreas Gohr $tags[0x0112] = 'TIFFOrientation'; 263755efc227SAndreas Gohr $tags[0x0115] = 'TIFFSamplesPerPixel'; 263855efc227SAndreas Gohr $tags[0x0116] = 'TIFFRowsPerStrip'; 263955efc227SAndreas Gohr $tags[0x0117] = 'TIFFStripByteCounts'; 264055efc227SAndreas Gohr $tags[0x0118] = 'TIFFMinSampleValue'; 264155efc227SAndreas Gohr $tags[0x0119] = 'TIFFMaxSampleValue'; 264255efc227SAndreas Gohr $tags[0x011A] = 'TIFFXResolution'; 264355efc227SAndreas Gohr $tags[0x011B] = 'TIFFYResolution'; 264455efc227SAndreas Gohr $tags[0x011C] = 'TIFFPlanarConfiguration'; 264555efc227SAndreas Gohr $tags[0x0122] = 'TIFFGrayResponseUnit'; 264655efc227SAndreas Gohr $tags[0x0123] = 'TIFFGrayResponseCurve'; 264755efc227SAndreas Gohr $tags[0x0128] = 'TIFFResolutionUnit'; 264855efc227SAndreas Gohr $tags[0x0131] = 'TIFFSoftware'; 264955efc227SAndreas Gohr $tags[0x0132] = 'TIFFDateTime'; 265055efc227SAndreas Gohr $tags[0x013B] = 'TIFFArtist'; 265155efc227SAndreas Gohr $tags[0x013C] = 'TIFFHostComputer'; 265255efc227SAndreas Gohr $tags[0x0140] = 'TIFFColorMap'; 265355efc227SAndreas Gohr $tags[0x0152] = 'TIFFExtraSamples'; 265455efc227SAndreas Gohr $tags[0x0201] = 'TIFFJFIFOffset'; 265555efc227SAndreas Gohr $tags[0x0202] = 'TIFFJFIFLength'; 265655efc227SAndreas Gohr $tags[0x0211] = 'TIFFYCbCrCoefficients'; 265755efc227SAndreas Gohr $tags[0x0212] = 'TIFFYCbCrSubSampling'; 265855efc227SAndreas Gohr $tags[0x0213] = 'TIFFYCbCrPositioning'; 265955efc227SAndreas Gohr $tags[0x0214] = 'TIFFReferenceBlackWhite'; 266055efc227SAndreas Gohr $tags[0x8298] = 'TIFFCopyright'; 266155efc227SAndreas Gohr $tags[0x9286] = 'TIFFUserComment'; 26620b17fdc6SAndreas Gohr } elseif ($mode == 'exif') { 266355efc227SAndreas Gohr $tags[0x829A] = 'ExposureTime'; 266455efc227SAndreas Gohr $tags[0x829D] = 'FNumber'; 266555efc227SAndreas Gohr $tags[0x8822] = 'ExposureProgram'; 266655efc227SAndreas Gohr $tags[0x8824] = 'SpectralSensitivity'; 266755efc227SAndreas Gohr $tags[0x8827] = 'ISOSpeedRatings'; 266855efc227SAndreas Gohr $tags[0x8828] = 'OECF'; 266955efc227SAndreas Gohr $tags[0x9000] = 'EXIFVersion'; 267055efc227SAndreas Gohr $tags[0x9003] = 'DatetimeOriginal'; 267155efc227SAndreas Gohr $tags[0x9004] = 'DatetimeDigitized'; 267255efc227SAndreas Gohr $tags[0x9101] = 'ComponentsConfiguration'; 267355efc227SAndreas Gohr $tags[0x9102] = 'CompressedBitsPerPixel'; 267455efc227SAndreas Gohr $tags[0x9201] = 'ShutterSpeedValue'; 267555efc227SAndreas Gohr $tags[0x9202] = 'ApertureValue'; 267655efc227SAndreas Gohr $tags[0x9203] = 'BrightnessValue'; 267755efc227SAndreas Gohr $tags[0x9204] = 'ExposureBiasValue'; 267855efc227SAndreas Gohr $tags[0x9205] = 'MaxApertureValue'; 267955efc227SAndreas Gohr $tags[0x9206] = 'SubjectDistance'; 268055efc227SAndreas Gohr $tags[0x9207] = 'MeteringMode'; 268155efc227SAndreas Gohr $tags[0x9208] = 'LightSource'; 268255efc227SAndreas Gohr $tags[0x9209] = 'Flash'; 268355efc227SAndreas Gohr $tags[0x920A] = 'FocalLength'; 268455efc227SAndreas Gohr $tags[0x927C] = 'MakerNote'; 268555efc227SAndreas Gohr $tags[0x9286] = 'UserComment'; 268655efc227SAndreas Gohr $tags[0x9290] = 'SubSecTime'; 268755efc227SAndreas Gohr $tags[0x9291] = 'SubSecTimeOriginal'; 268855efc227SAndreas Gohr $tags[0x9292] = 'SubSecTimeDigitized'; 268955efc227SAndreas Gohr $tags[0xA000] = 'FlashPixVersion'; 269055efc227SAndreas Gohr $tags[0xA001] = 'ColorSpace'; 269155efc227SAndreas Gohr $tags[0xA002] = 'PixelXDimension'; 269255efc227SAndreas Gohr $tags[0xA003] = 'PixelYDimension'; 269355efc227SAndreas Gohr $tags[0xA004] = 'RelatedSoundFile'; 269455efc227SAndreas Gohr $tags[0xA005] = 'InteropIFDOffset'; 269555efc227SAndreas Gohr $tags[0xA20B] = 'FlashEnergy'; 269655efc227SAndreas Gohr $tags[0xA20C] = 'SpatialFrequencyResponse'; 269755efc227SAndreas Gohr $tags[0xA20E] = 'FocalPlaneXResolution'; 269855efc227SAndreas Gohr $tags[0xA20F] = 'FocalPlaneYResolution'; 269955efc227SAndreas Gohr $tags[0xA210] = 'FocalPlaneResolutionUnit'; 270055efc227SAndreas Gohr $tags[0xA214] = 'SubjectLocation'; 270155efc227SAndreas Gohr $tags[0xA215] = 'ExposureIndex'; 270255efc227SAndreas Gohr $tags[0xA217] = 'SensingMethod'; 270355efc227SAndreas Gohr $tags[0xA300] = 'FileSource'; 270455efc227SAndreas Gohr $tags[0xA301] = 'SceneType'; 270555efc227SAndreas Gohr $tags[0xA302] = 'CFAPattern'; 27060b17fdc6SAndreas Gohr } elseif ($mode == 'interop') { 270755efc227SAndreas Gohr $tags[0x0001] = 'InteroperabilityIndex'; 270855efc227SAndreas Gohr $tags[0x0002] = 'InteroperabilityVersion'; 270955efc227SAndreas Gohr $tags[0x1000] = 'RelatedImageFileFormat'; 271055efc227SAndreas Gohr $tags[0x1001] = 'RelatedImageWidth'; 271155efc227SAndreas Gohr $tags[0x1002] = 'RelatedImageLength'; 27120b17fdc6SAndreas Gohr } elseif ($mode == 'gps') { 271355efc227SAndreas Gohr $tags[0x0000] = 'GPSVersionID'; 271455efc227SAndreas Gohr $tags[0x0001] = 'GPSLatitudeRef'; 271555efc227SAndreas Gohr $tags[0x0002] = 'GPSLatitude'; 271655efc227SAndreas Gohr $tags[0x0003] = 'GPSLongitudeRef'; 271755efc227SAndreas Gohr $tags[0x0004] = 'GPSLongitude'; 271855efc227SAndreas Gohr $tags[0x0005] = 'GPSAltitudeRef'; 271955efc227SAndreas Gohr $tags[0x0006] = 'GPSAltitude'; 272055efc227SAndreas Gohr $tags[0x0007] = 'GPSTimeStamp'; 272155efc227SAndreas Gohr $tags[0x0008] = 'GPSSatellites'; 272255efc227SAndreas Gohr $tags[0x0009] = 'GPSStatus'; 272355efc227SAndreas Gohr $tags[0x000A] = 'GPSMeasureMode'; 272455efc227SAndreas Gohr $tags[0x000B] = 'GPSDOP'; 272555efc227SAndreas Gohr $tags[0x000C] = 'GPSSpeedRef'; 272655efc227SAndreas Gohr $tags[0x000D] = 'GPSSpeed'; 272755efc227SAndreas Gohr $tags[0x000E] = 'GPSTrackRef'; 272855efc227SAndreas Gohr $tags[0x000F] = 'GPSTrack'; 272955efc227SAndreas Gohr $tags[0x0010] = 'GPSImgDirectionRef'; 273055efc227SAndreas Gohr $tags[0x0011] = 'GPSImgDirection'; 273155efc227SAndreas Gohr $tags[0x0012] = 'GPSMapDatum'; 273255efc227SAndreas Gohr $tags[0x0013] = 'GPSDestLatitudeRef'; 273355efc227SAndreas Gohr $tags[0x0014] = 'GPSDestLatitude'; 273455efc227SAndreas Gohr $tags[0x0015] = 'GPSDestLongitudeRef'; 273555efc227SAndreas Gohr $tags[0x0016] = 'GPSDestLongitude'; 273655efc227SAndreas Gohr $tags[0x0017] = 'GPSDestBearingRef'; 273755efc227SAndreas Gohr $tags[0x0018] = 'GPSDestBearing'; 273855efc227SAndreas Gohr $tags[0x0019] = 'GPSDestDistanceRef'; 273955efc227SAndreas Gohr $tags[0x001A] = 'GPSDestDistance'; 274055efc227SAndreas Gohr } 274155efc227SAndreas Gohr 274255efc227SAndreas Gohr return $tags; 274355efc227SAndreas Gohr } 274455efc227SAndreas Gohr 274555efc227SAndreas Gohr /*************************************************************/ 27460b17fdc6SAndreas Gohr function _exifTagTypes($mode) { 274755efc227SAndreas Gohr $tags = array(); 274855efc227SAndreas Gohr 274955efc227SAndreas Gohr if ($mode == 'ifd0') { 275055efc227SAndreas Gohr $tags[0x010E] = array(2, 0); // ImageDescription -> ASCII, Any 275155efc227SAndreas Gohr $tags[0x010F] = array(2, 0); // Make -> ASCII, Any 275255efc227SAndreas Gohr $tags[0x0110] = array(2, 0); // Model -> ASCII, Any 275355efc227SAndreas Gohr $tags[0x0112] = array(3, 1); // Orientation -> SHORT, 1 275455efc227SAndreas Gohr $tags[0x011A] = array(5, 1); // XResolution -> RATIONAL, 1 275555efc227SAndreas Gohr $tags[0x011B] = array(5, 1); // YResolution -> RATIONAL, 1 275655efc227SAndreas Gohr $tags[0x0128] = array(3, 1); // ResolutionUnit -> SHORT 275755efc227SAndreas Gohr $tags[0x0131] = array(2, 0); // Software -> ASCII, Any 275855efc227SAndreas Gohr $tags[0x0132] = array(2, 20); // DateTime -> ASCII, 20 275955efc227SAndreas Gohr $tags[0x013B] = array(2, 0); // Artist -> ASCII, Any 276055efc227SAndreas Gohr $tags[0x013E] = array(5, 2); // WhitePoint -> RATIONAL, 2 276155efc227SAndreas Gohr $tags[0x013F] = array(5, 6); // PrimaryChromaticities -> RATIONAL, 6 276255efc227SAndreas Gohr $tags[0x0211] = array(5, 3); // YCbCrCoefficients -> RATIONAL, 3 276355efc227SAndreas Gohr $tags[0x0212] = array(3, 2); // YCbCrSubSampling -> SHORT, 2 276455efc227SAndreas Gohr $tags[0x0213] = array(3, 1); // YCbCrPositioning -> SHORT, 1 276555efc227SAndreas Gohr $tags[0x0214] = array(5, 6); // ReferenceBlackWhite -> RATIONAL, 6 276655efc227SAndreas Gohr $tags[0x8298] = array(2, 0); // Copyright -> ASCII, Any 276755efc227SAndreas Gohr $tags[0x8769] = array(4, 1); // ExifIFDOffset -> LONG, 1 276855efc227SAndreas Gohr $tags[0x8825] = array(4, 1); // GPSIFDOffset -> LONG, 1 276955efc227SAndreas Gohr } 277055efc227SAndreas Gohr if ($mode == 'ifd1') { 277155efc227SAndreas Gohr $tags[0x00FE] = array(4, 1); // TIFFNewSubfileType -> LONG, 1 277255efc227SAndreas Gohr $tags[0x00FF] = array(3, 1); // TIFFSubfileType -> SHORT, 1 277355efc227SAndreas Gohr $tags[0x0100] = array(4, 1); // TIFFImageWidth -> LONG (or SHORT), 1 277455efc227SAndreas Gohr $tags[0x0101] = array(4, 1); // TIFFImageHeight -> LONG (or SHORT), 1 277555efc227SAndreas Gohr $tags[0x0102] = array(3, 3); // TIFFBitsPerSample -> SHORT, 3 277655efc227SAndreas Gohr $tags[0x0103] = array(3, 1); // TIFFCompression -> SHORT, 1 277755efc227SAndreas Gohr $tags[0x0106] = array(3, 1); // TIFFPhotometricInterpretation -> SHORT, 1 277855efc227SAndreas Gohr $tags[0x0107] = array(3, 1); // TIFFThreshholding -> SHORT, 1 277955efc227SAndreas Gohr $tags[0x0108] = array(3, 1); // TIFFCellWidth -> SHORT, 1 278055efc227SAndreas Gohr $tags[0x0109] = array(3, 1); // TIFFCellLength -> SHORT, 1 278155efc227SAndreas Gohr $tags[0x010A] = array(3, 1); // TIFFFillOrder -> SHORT, 1 278255efc227SAndreas Gohr $tags[0x010E] = array(2, 0); // TIFFImageDescription -> ASCII, Any 278355efc227SAndreas Gohr $tags[0x010F] = array(2, 0); // TIFFMake -> ASCII, Any 278455efc227SAndreas Gohr $tags[0x0110] = array(2, 0); // TIFFModel -> ASCII, Any 278555efc227SAndreas Gohr $tags[0x0111] = array(4, 0); // TIFFStripOffsets -> LONG (or SHORT), Any (one per strip) 278655efc227SAndreas Gohr $tags[0x0112] = array(3, 1); // TIFFOrientation -> SHORT, 1 278755efc227SAndreas Gohr $tags[0x0115] = array(3, 1); // TIFFSamplesPerPixel -> SHORT, 1 278855efc227SAndreas Gohr $tags[0x0116] = array(4, 1); // TIFFRowsPerStrip -> LONG (or SHORT), 1 278955efc227SAndreas Gohr $tags[0x0117] = array(4, 0); // TIFFStripByteCounts -> LONG (or SHORT), Any (one per strip) 279055efc227SAndreas Gohr $tags[0x0118] = array(3, 0); // TIFFMinSampleValue -> SHORT, Any (SamplesPerPixel) 279155efc227SAndreas Gohr $tags[0x0119] = array(3, 0); // TIFFMaxSampleValue -> SHORT, Any (SamplesPerPixel) 279255efc227SAndreas Gohr $tags[0x011A] = array(5, 1); // TIFFXResolution -> RATIONAL, 1 279355efc227SAndreas Gohr $tags[0x011B] = array(5, 1); // TIFFYResolution -> RATIONAL, 1 279455efc227SAndreas Gohr $tags[0x011C] = array(3, 1); // TIFFPlanarConfiguration -> SHORT, 1 279555efc227SAndreas Gohr $tags[0x0122] = array(3, 1); // TIFFGrayResponseUnit -> SHORT, 1 279655efc227SAndreas Gohr $tags[0x0123] = array(3, 0); // TIFFGrayResponseCurve -> SHORT, Any (2^BitsPerSample) 279755efc227SAndreas Gohr $tags[0x0128] = array(3, 1); // TIFFResolutionUnit -> SHORT, 1 279855efc227SAndreas Gohr $tags[0x0131] = array(2, 0); // TIFFSoftware -> ASCII, Any 279955efc227SAndreas Gohr $tags[0x0132] = array(2, 20); // TIFFDateTime -> ASCII, 20 280055efc227SAndreas Gohr $tags[0x013B] = array(2, 0); // TIFFArtist -> ASCII, Any 280155efc227SAndreas Gohr $tags[0x013C] = array(2, 0); // TIFFHostComputer -> ASCII, Any 280255efc227SAndreas Gohr $tags[0x0140] = array(3, 0); // TIFFColorMap -> SHORT, Any (3 * 2^BitsPerSample) 280355efc227SAndreas Gohr $tags[0x0152] = array(3, 0); // TIFFExtraSamples -> SHORT, Any (SamplesPerPixel - 3) 280455efc227SAndreas Gohr $tags[0x0201] = array(4, 1); // TIFFJFIFOffset -> LONG, 1 280555efc227SAndreas Gohr $tags[0x0202] = array(4, 1); // TIFFJFIFLength -> LONG, 1 280655efc227SAndreas Gohr $tags[0x0211] = array(5, 3); // TIFFYCbCrCoefficients -> RATIONAL, 3 280755efc227SAndreas Gohr $tags[0x0212] = array(3, 2); // TIFFYCbCrSubSampling -> SHORT, 2 280855efc227SAndreas Gohr $tags[0x0213] = array(3, 1); // TIFFYCbCrPositioning -> SHORT, 1 280955efc227SAndreas Gohr $tags[0x0214] = array(5, 6); // TIFFReferenceBlackWhite -> RATIONAL, 6 281055efc227SAndreas Gohr $tags[0x8298] = array(2, 0); // TIFFCopyright -> ASCII, Any 281155efc227SAndreas Gohr $tags[0x9286] = array(2, 0); // TIFFUserComment -> ASCII, Any 28120b17fdc6SAndreas Gohr } elseif ($mode == 'exif') { 281355efc227SAndreas Gohr $tags[0x829A] = array(5, 1); // ExposureTime -> RATIONAL, 1 281455efc227SAndreas Gohr $tags[0x829D] = array(5, 1); // FNumber -> RATIONAL, 1 281555efc227SAndreas Gohr $tags[0x8822] = array(3, 1); // ExposureProgram -> SHORT, 1 281655efc227SAndreas Gohr $tags[0x8824] = array(2, 0); // SpectralSensitivity -> ASCII, Any 281755efc227SAndreas Gohr $tags[0x8827] = array(3, 0); // ISOSpeedRatings -> SHORT, Any 281855efc227SAndreas Gohr $tags[0x8828] = array(7, 0); // OECF -> UNDEFINED, Any 281955efc227SAndreas Gohr $tags[0x9000] = array(7, 4); // EXIFVersion -> UNDEFINED, 4 282055efc227SAndreas Gohr $tags[0x9003] = array(2, 20); // DatetimeOriginal -> ASCII, 20 282155efc227SAndreas Gohr $tags[0x9004] = array(2, 20); // DatetimeDigitized -> ASCII, 20 282255efc227SAndreas Gohr $tags[0x9101] = array(7, 4); // ComponentsConfiguration -> UNDEFINED, 4 282355efc227SAndreas Gohr $tags[0x9102] = array(5, 1); // CompressedBitsPerPixel -> RATIONAL, 1 282455efc227SAndreas Gohr $tags[0x9201] = array(10, 1); // ShutterSpeedValue -> SRATIONAL, 1 282555efc227SAndreas Gohr $tags[0x9202] = array(5, 1); // ApertureValue -> RATIONAL, 1 282655efc227SAndreas Gohr $tags[0x9203] = array(10, 1); // BrightnessValue -> SRATIONAL, 1 282755efc227SAndreas Gohr $tags[0x9204] = array(10, 1); // ExposureBiasValue -> SRATIONAL, 1 282855efc227SAndreas Gohr $tags[0x9205] = array(5, 1); // MaxApertureValue -> RATIONAL, 1 282955efc227SAndreas Gohr $tags[0x9206] = array(5, 1); // SubjectDistance -> RATIONAL, 1 283055efc227SAndreas Gohr $tags[0x9207] = array(3, 1); // MeteringMode -> SHORT, 1 283155efc227SAndreas Gohr $tags[0x9208] = array(3, 1); // LightSource -> SHORT, 1 283255efc227SAndreas Gohr $tags[0x9209] = array(3, 1); // Flash -> SHORT, 1 283355efc227SAndreas Gohr $tags[0x920A] = array(5, 1); // FocalLength -> RATIONAL, 1 283455efc227SAndreas Gohr $tags[0x927C] = array(7, 0); // MakerNote -> UNDEFINED, Any 283555efc227SAndreas Gohr $tags[0x9286] = array(7, 0); // UserComment -> UNDEFINED, Any 283655efc227SAndreas Gohr $tags[0x9290] = array(2, 0); // SubSecTime -> ASCII, Any 283755efc227SAndreas Gohr $tags[0x9291] = array(2, 0); // SubSecTimeOriginal -> ASCII, Any 283855efc227SAndreas Gohr $tags[0x9292] = array(2, 0); // SubSecTimeDigitized -> ASCII, Any 283955efc227SAndreas Gohr $tags[0xA000] = array(7, 4); // FlashPixVersion -> UNDEFINED, 4 284055efc227SAndreas Gohr $tags[0xA001] = array(3, 1); // ColorSpace -> SHORT, 1 284155efc227SAndreas Gohr $tags[0xA002] = array(4, 1); // PixelXDimension -> LONG (or SHORT), 1 284255efc227SAndreas Gohr $tags[0xA003] = array(4, 1); // PixelYDimension -> LONG (or SHORT), 1 284355efc227SAndreas Gohr $tags[0xA004] = array(2, 13); // RelatedSoundFile -> ASCII, 13 284455efc227SAndreas Gohr $tags[0xA005] = array(4, 1); // InteropIFDOffset -> LONG, 1 284555efc227SAndreas Gohr $tags[0xA20B] = array(5, 1); // FlashEnergy -> RATIONAL, 1 284655efc227SAndreas Gohr $tags[0xA20C] = array(7, 0); // SpatialFrequencyResponse -> UNDEFINED, Any 284755efc227SAndreas Gohr $tags[0xA20E] = array(5, 1); // FocalPlaneXResolution -> RATIONAL, 1 284855efc227SAndreas Gohr $tags[0xA20F] = array(5, 1); // FocalPlaneYResolution -> RATIONAL, 1 284955efc227SAndreas Gohr $tags[0xA210] = array(3, 1); // FocalPlaneResolutionUnit -> SHORT, 1 285055efc227SAndreas Gohr $tags[0xA214] = array(3, 2); // SubjectLocation -> SHORT, 2 285155efc227SAndreas Gohr $tags[0xA215] = array(5, 1); // ExposureIndex -> RATIONAL, 1 285255efc227SAndreas Gohr $tags[0xA217] = array(3, 1); // SensingMethod -> SHORT, 1 285355efc227SAndreas Gohr $tags[0xA300] = array(7, 1); // FileSource -> UNDEFINED, 1 285455efc227SAndreas Gohr $tags[0xA301] = array(7, 1); // SceneType -> UNDEFINED, 1 285555efc227SAndreas Gohr $tags[0xA302] = array(7, 0); // CFAPattern -> UNDEFINED, Any 28560b17fdc6SAndreas Gohr } elseif ($mode == 'interop') { 285755efc227SAndreas Gohr $tags[0x0001] = array(2, 0); // InteroperabilityIndex -> ASCII, Any 285855efc227SAndreas Gohr $tags[0x0002] = array(7, 4); // InteroperabilityVersion -> UNKNOWN, 4 285955efc227SAndreas Gohr $tags[0x1000] = array(2, 0); // RelatedImageFileFormat -> ASCII, Any 286055efc227SAndreas Gohr $tags[0x1001] = array(4, 1); // RelatedImageWidth -> LONG (or SHORT), 1 286155efc227SAndreas Gohr $tags[0x1002] = array(4, 1); // RelatedImageLength -> LONG (or SHORT), 1 28620b17fdc6SAndreas Gohr } elseif ($mode == 'gps') { 286355efc227SAndreas Gohr $tags[0x0000] = array(1, 4); // GPSVersionID -> BYTE, 4 286455efc227SAndreas Gohr $tags[0x0001] = array(2, 2); // GPSLatitudeRef -> ASCII, 2 286555efc227SAndreas Gohr $tags[0x0002] = array(5, 3); // GPSLatitude -> RATIONAL, 3 286655efc227SAndreas Gohr $tags[0x0003] = array(2, 2); // GPSLongitudeRef -> ASCII, 2 286755efc227SAndreas Gohr $tags[0x0004] = array(5, 3); // GPSLongitude -> RATIONAL, 3 286855efc227SAndreas Gohr $tags[0x0005] = array(2, 2); // GPSAltitudeRef -> ASCII, 2 286955efc227SAndreas Gohr $tags[0x0006] = array(5, 1); // GPSAltitude -> RATIONAL, 1 287055efc227SAndreas Gohr $tags[0x0007] = array(5, 3); // GPSTimeStamp -> RATIONAL, 3 287155efc227SAndreas Gohr $tags[0x0008] = array(2, 0); // GPSSatellites -> ASCII, Any 287255efc227SAndreas Gohr $tags[0x0009] = array(2, 2); // GPSStatus -> ASCII, 2 287355efc227SAndreas Gohr $tags[0x000A] = array(2, 2); // GPSMeasureMode -> ASCII, 2 287455efc227SAndreas Gohr $tags[0x000B] = array(5, 1); // GPSDOP -> RATIONAL, 1 287555efc227SAndreas Gohr $tags[0x000C] = array(2, 2); // GPSSpeedRef -> ASCII, 2 287655efc227SAndreas Gohr $tags[0x000D] = array(5, 1); // GPSSpeed -> RATIONAL, 1 287755efc227SAndreas Gohr $tags[0x000E] = array(2, 2); // GPSTrackRef -> ASCII, 2 287855efc227SAndreas Gohr $tags[0x000F] = array(5, 1); // GPSTrack -> RATIONAL, 1 287955efc227SAndreas Gohr $tags[0x0010] = array(2, 2); // GPSImgDirectionRef -> ASCII, 2 288055efc227SAndreas Gohr $tags[0x0011] = array(5, 1); // GPSImgDirection -> RATIONAL, 1 288155efc227SAndreas Gohr $tags[0x0012] = array(2, 0); // GPSMapDatum -> ASCII, Any 288255efc227SAndreas Gohr $tags[0x0013] = array(2, 2); // GPSDestLatitudeRef -> ASCII, 2 288355efc227SAndreas Gohr $tags[0x0014] = array(5, 3); // GPSDestLatitude -> RATIONAL, 3 288455efc227SAndreas Gohr $tags[0x0015] = array(2, 2); // GPSDestLongitudeRef -> ASCII, 2 288555efc227SAndreas Gohr $tags[0x0016] = array(5, 3); // GPSDestLongitude -> RATIONAL, 3 288655efc227SAndreas Gohr $tags[0x0017] = array(2, 2); // GPSDestBearingRef -> ASCII, 2 288755efc227SAndreas Gohr $tags[0x0018] = array(5, 1); // GPSDestBearing -> RATIONAL, 1 288855efc227SAndreas Gohr $tags[0x0019] = array(2, 2); // GPSDestDistanceRef -> ASCII, 2 288955efc227SAndreas Gohr $tags[0x001A] = array(5, 1); // GPSDestDistance -> RATIONAL, 1 289055efc227SAndreas Gohr } 289155efc227SAndreas Gohr 289255efc227SAndreas Gohr return $tags; 289355efc227SAndreas Gohr } 289455efc227SAndreas Gohr 289555efc227SAndreas Gohr /*************************************************************/ 28960b17fdc6SAndreas Gohr function _exifNameTags($mode) { 289755efc227SAndreas Gohr $tags = $this->_exifTagNames($mode); 289855efc227SAndreas Gohr return $this->_names2Tags($tags); 289955efc227SAndreas Gohr } 290055efc227SAndreas Gohr 290155efc227SAndreas Gohr /*************************************************************/ 29020b17fdc6SAndreas Gohr function _iptcTagNames() { 290355efc227SAndreas Gohr $tags = array(); 290455efc227SAndreas Gohr $tags[0x14] = 'SuplementalCategories'; 290555efc227SAndreas Gohr $tags[0x19] = 'Keywords'; 290655efc227SAndreas Gohr $tags[0x78] = 'Caption'; 290755efc227SAndreas Gohr $tags[0x7A] = 'CaptionWriter'; 290855efc227SAndreas Gohr $tags[0x69] = 'Headline'; 290955efc227SAndreas Gohr $tags[0x28] = 'SpecialInstructions'; 291055efc227SAndreas Gohr $tags[0x0F] = 'Category'; 291155efc227SAndreas Gohr $tags[0x50] = 'Byline'; 291255efc227SAndreas Gohr $tags[0x55] = 'BylineTitle'; 291355efc227SAndreas Gohr $tags[0x6E] = 'Credit'; 291455efc227SAndreas Gohr $tags[0x73] = 'Source'; 291555efc227SAndreas Gohr $tags[0x74] = 'CopyrightNotice'; 291655efc227SAndreas Gohr $tags[0x05] = 'ObjectName'; 291755efc227SAndreas Gohr $tags[0x5A] = 'City'; 2918493531a8SJoe Lapp $tags[0x5C] = 'Sublocation'; 291955efc227SAndreas Gohr $tags[0x5F] = 'ProvinceState'; 292055efc227SAndreas Gohr $tags[0x65] = 'CountryName'; 292155efc227SAndreas Gohr $tags[0x67] = 'OriginalTransmissionReference'; 292255efc227SAndreas Gohr $tags[0x37] = 'DateCreated'; 292355efc227SAndreas Gohr $tags[0x0A] = 'CopyrightFlag'; 292455efc227SAndreas Gohr 292555efc227SAndreas Gohr return $tags; 292655efc227SAndreas Gohr } 292755efc227SAndreas Gohr 292855efc227SAndreas Gohr /*************************************************************/ 29290b17fdc6SAndreas Gohr function & _iptcNameTags() { 293055efc227SAndreas Gohr $tags = $this->_iptcTagNames(); 293155efc227SAndreas Gohr return $this->_names2Tags($tags); 293255efc227SAndreas Gohr } 293355efc227SAndreas Gohr 293455efc227SAndreas Gohr /*************************************************************/ 29350b17fdc6SAndreas Gohr function _names2Tags($tags2Names) { 293655efc227SAndreas Gohr $names2Tags = array(); 293755efc227SAndreas Gohr reset($tags2Names); 293855efc227SAndreas Gohr while (list($tag, $name) = each($tags2Names)) { 293955efc227SAndreas Gohr $names2Tags[$name] = $tag; 294055efc227SAndreas Gohr } 294155efc227SAndreas Gohr 294255efc227SAndreas Gohr return $names2Tags; 294355efc227SAndreas Gohr } 294455efc227SAndreas Gohr 294555efc227SAndreas Gohr /*************************************************************/ 2946276820f7SScrutinizer Auto-Fixer 2947276820f7SScrutinizer Auto-Fixer /** 2948276820f7SScrutinizer Auto-Fixer * @param integer $pos 2949276820f7SScrutinizer Auto-Fixer */ 29500b17fdc6SAndreas Gohr function _getByte(&$data, $pos) { 295155efc227SAndreas Gohr return ord($data{$pos}); 295255efc227SAndreas Gohr } 295355efc227SAndreas Gohr 295455efc227SAndreas Gohr /*************************************************************/ 2955276820f7SScrutinizer Auto-Fixer 2956276820f7SScrutinizer Auto-Fixer /** 2957276820f7SScrutinizer Auto-Fixer * @param integer $pos 2958276820f7SScrutinizer Auto-Fixer */ 29590b17fdc6SAndreas Gohr function _putByte(&$data, $pos, $val) { 296055efc227SAndreas Gohr $val = intval($val); 296155efc227SAndreas Gohr 296255efc227SAndreas Gohr $data{$pos} = chr($val); 296355efc227SAndreas Gohr 296455efc227SAndreas Gohr return $pos + 1; 296555efc227SAndreas Gohr } 296655efc227SAndreas Gohr 296755efc227SAndreas Gohr /*************************************************************/ 29680b17fdc6SAndreas Gohr function _getShort(&$data, $pos, $bigEndian = true) { 296955efc227SAndreas Gohr if ($bigEndian) { 297055efc227SAndreas Gohr return (ord($data{$pos}) << 8) 297155efc227SAndreas Gohr + ord($data{$pos + 1}); 29720b17fdc6SAndreas Gohr } else { 297355efc227SAndreas Gohr return ord($data{$pos}) 297455efc227SAndreas Gohr + (ord($data{$pos + 1}) << 8); 297555efc227SAndreas Gohr } 297655efc227SAndreas Gohr } 297755efc227SAndreas Gohr 297855efc227SAndreas Gohr /*************************************************************/ 29790b17fdc6SAndreas Gohr function _putShort(&$data, $pos = 0, $val = 0, $bigEndian = true) { 298055efc227SAndreas Gohr $val = intval($val); 298155efc227SAndreas Gohr 298255efc227SAndreas Gohr if ($bigEndian) { 298355efc227SAndreas Gohr $data{$pos + 0} = chr(($val & 0x0000FF00) >> 8); 298455efc227SAndreas Gohr $data{$pos + 1} = chr(($val & 0x000000FF) >> 0); 29850b17fdc6SAndreas Gohr } else { 298655efc227SAndreas Gohr $data{$pos + 0} = chr(($val & 0x00FF) >> 0); 298755efc227SAndreas Gohr $data{$pos + 1} = chr(($val & 0xFF00) >> 8); 298855efc227SAndreas Gohr } 298955efc227SAndreas Gohr 299055efc227SAndreas Gohr return $pos + 2; 299155efc227SAndreas Gohr } 299255efc227SAndreas Gohr 299355efc227SAndreas Gohr /*************************************************************/ 2994276820f7SScrutinizer Auto-Fixer 2995276820f7SScrutinizer Auto-Fixer /** 2996276820f7SScrutinizer Auto-Fixer * @param integer $pos 2997276820f7SScrutinizer Auto-Fixer */ 29980b17fdc6SAndreas Gohr function _getLong(&$data, $pos, $bigEndian = true) { 299955efc227SAndreas Gohr if ($bigEndian) { 300055efc227SAndreas Gohr return (ord($data{$pos}) << 24) 300155efc227SAndreas Gohr + (ord($data{$pos + 1}) << 16) 300255efc227SAndreas Gohr + (ord($data{$pos + 2}) << 8) 300355efc227SAndreas Gohr + ord($data{$pos + 3}); 30040b17fdc6SAndreas Gohr } else { 300555efc227SAndreas Gohr return ord($data{$pos}) 300655efc227SAndreas Gohr + (ord($data{$pos + 1}) << 8) 300755efc227SAndreas Gohr + (ord($data{$pos + 2}) << 16) 300855efc227SAndreas Gohr + (ord($data{$pos + 3}) << 24); 300955efc227SAndreas Gohr } 301055efc227SAndreas Gohr } 301155efc227SAndreas Gohr 301255efc227SAndreas Gohr /*************************************************************/ 3013276820f7SScrutinizer Auto-Fixer 3014276820f7SScrutinizer Auto-Fixer /** 3015276820f7SScrutinizer Auto-Fixer * @param integer $pos 3016276820f7SScrutinizer Auto-Fixer */ 30170b17fdc6SAndreas Gohr function _putLong(&$data, $pos, $val, $bigEndian = true) { 301855efc227SAndreas Gohr $val = intval($val); 301955efc227SAndreas Gohr 302055efc227SAndreas Gohr if ($bigEndian) { 302155efc227SAndreas Gohr $data{$pos + 0} = chr(($val & 0xFF000000) >> 24); 302255efc227SAndreas Gohr $data{$pos + 1} = chr(($val & 0x00FF0000) >> 16); 302355efc227SAndreas Gohr $data{$pos + 2} = chr(($val & 0x0000FF00) >> 8); 302455efc227SAndreas Gohr $data{$pos + 3} = chr(($val & 0x000000FF) >> 0); 30250b17fdc6SAndreas Gohr } else { 302655efc227SAndreas Gohr $data{$pos + 0} = chr(($val & 0x000000FF) >> 0); 302755efc227SAndreas Gohr $data{$pos + 1} = chr(($val & 0x0000FF00) >> 8); 302855efc227SAndreas Gohr $data{$pos + 2} = chr(($val & 0x00FF0000) >> 16); 302955efc227SAndreas Gohr $data{$pos + 3} = chr(($val & 0xFF000000) >> 24); 303055efc227SAndreas Gohr } 303155efc227SAndreas Gohr 303255efc227SAndreas Gohr return $pos + 4; 303355efc227SAndreas Gohr } 303455efc227SAndreas Gohr 303555efc227SAndreas Gohr /*************************************************************/ 30360b17fdc6SAndreas Gohr function & _getNullString(&$data, $pos) { 303755efc227SAndreas Gohr $str = ''; 303855efc227SAndreas Gohr $max = strlen($data); 303955efc227SAndreas Gohr 304055efc227SAndreas Gohr while ($pos < $max) { 304155efc227SAndreas Gohr if (ord($data{$pos}) == 0) { 304255efc227SAndreas Gohr return $str; 30430b17fdc6SAndreas Gohr } else { 304455efc227SAndreas Gohr $str .= $data{$pos}; 304555efc227SAndreas Gohr } 304655efc227SAndreas Gohr $pos++; 304755efc227SAndreas Gohr } 304855efc227SAndreas Gohr 304955efc227SAndreas Gohr return $str; 305055efc227SAndreas Gohr } 305155efc227SAndreas Gohr 305255efc227SAndreas Gohr /*************************************************************/ 30530b17fdc6SAndreas Gohr function & _getFixedString(&$data, $pos, $length = -1) { 305455efc227SAndreas Gohr if ($length == -1) { 305555efc227SAndreas Gohr $length = strlen($data) - $pos; 305655efc227SAndreas Gohr } 305755efc227SAndreas Gohr 305817dd401eSChristopher Smith $rv = substr($data, $pos, $length); 305917dd401eSChristopher Smith return $rv; 306055efc227SAndreas Gohr } 306155efc227SAndreas Gohr 306255efc227SAndreas Gohr /*************************************************************/ 30630b17fdc6SAndreas Gohr function _putString(&$data, $pos, &$str) { 306455efc227SAndreas Gohr $len = strlen($str); 306555efc227SAndreas Gohr for ($i = 0; $i < $len; $i++) { 306655efc227SAndreas Gohr $data{$pos + $i} = $str{$i}; 306755efc227SAndreas Gohr } 306855efc227SAndreas Gohr 306955efc227SAndreas Gohr return $pos + $len; 307055efc227SAndreas Gohr } 307155efc227SAndreas Gohr 307255efc227SAndreas Gohr /*************************************************************/ 30730b17fdc6SAndreas Gohr function _hexDump(&$data, $start = 0, $length = -1) { 307455efc227SAndreas Gohr if (($length == -1) || (($length + $start) > strlen($data))) { 307555efc227SAndreas Gohr $end = strlen($data); 30760b17fdc6SAndreas Gohr } else { 307755efc227SAndreas Gohr $end = $start + $length; 307855efc227SAndreas Gohr } 307955efc227SAndreas Gohr 308055efc227SAndreas Gohr $ascii = ''; 308155efc227SAndreas Gohr $count = 0; 308255efc227SAndreas Gohr 308355efc227SAndreas Gohr echo "<tt>\n"; 308455efc227SAndreas Gohr 308555efc227SAndreas Gohr while ($start < $end) { 308655efc227SAndreas Gohr if (($count % 16) == 0) { 308755efc227SAndreas Gohr echo sprintf('%04d', $count) . ': '; 308855efc227SAndreas Gohr } 308955efc227SAndreas Gohr 309055efc227SAndreas Gohr $c = ord($data{$start}); 309155efc227SAndreas Gohr $count++; 309255efc227SAndreas Gohr $start++; 309355efc227SAndreas Gohr 309455efc227SAndreas Gohr $aux = dechex($c); 309555efc227SAndreas Gohr if (strlen($aux) == 1) 309655efc227SAndreas Gohr echo '0'; 309755efc227SAndreas Gohr echo $aux . ' '; 309855efc227SAndreas Gohr 309955efc227SAndreas Gohr if ($c == 60) 310055efc227SAndreas Gohr $ascii .= '<'; 310155efc227SAndreas Gohr elseif ($c == 62) 310255efc227SAndreas Gohr $ascii .= '>'; 310355efc227SAndreas Gohr elseif ($c == 32) 3104e260f93bSAnika Henke $ascii .= ' '; 310555efc227SAndreas Gohr elseif ($c > 32) 310655efc227SAndreas Gohr $ascii .= chr($c); 310755efc227SAndreas Gohr else 310855efc227SAndreas Gohr $ascii .= '.'; 310955efc227SAndreas Gohr 311055efc227SAndreas Gohr if (($count % 4) == 0) { 311155efc227SAndreas Gohr echo ' - '; 311255efc227SAndreas Gohr } 311355efc227SAndreas Gohr 311455efc227SAndreas Gohr if (($count % 16) == 0) { 311555efc227SAndreas Gohr echo ': ' . $ascii . "<br>\n"; 311655efc227SAndreas Gohr $ascii = ''; 311755efc227SAndreas Gohr } 311855efc227SAndreas Gohr } 311955efc227SAndreas Gohr 312055efc227SAndreas Gohr if ($ascii != '') { 312155efc227SAndreas Gohr while (($count % 16) != 0) { 312255efc227SAndreas Gohr echo '-- '; 312355efc227SAndreas Gohr $count++; 312455efc227SAndreas Gohr if (($count % 4) == 0) { 312555efc227SAndreas Gohr echo ' - '; 312655efc227SAndreas Gohr } 312755efc227SAndreas Gohr } 312855efc227SAndreas Gohr echo ': ' . $ascii . "<br>\n"; 312955efc227SAndreas Gohr } 313055efc227SAndreas Gohr 313155efc227SAndreas Gohr echo "</tt>\n"; 313255efc227SAndreas Gohr } 313355efc227SAndreas Gohr 313455efc227SAndreas Gohr /*****************************************************************/ 313555efc227SAndreas Gohr} 313655efc227SAndreas Gohr 313755efc227SAndreas Gohr/* vim: set expandtab tabstop=4 shiftwidth=4: */ 3138