/* This file is released under the GPL, any version you like
*
*PHP PSD reader class, v1.3
*
*By Tim de Koning
*
*Kingsquare Information Services, 22 jan 2007
*
*example use:
*------------
*<?php
*include_once('classPhpPsdReader.php')
*header("Content-type: image/jpeg");
*print imagejpeg(imagecreatefrompsd('test.psd'));
*?>
*
*More info, bugs or requests, contact info@kingsquare.nl
*
*Latest version and demo: http://www.kingsquare.nl/phppsdreader
*
*TODO
*----
*- read color values for "multichannel data" PSD files
*- find and implement (hunter)lab to RGB algorithm
*- fix 32 bit colors... has something to do with gamma and exposure available since CS2, but dunno how to read them...
*/
class PhpPsdReader {
var $infoArray;
var $fp;
var $fileName;
var $tempFileName;
var $colorBytesLength;
function PhpPsdReader($fileName) {
set_time_limit(0);
$this->infoArray = array();
$this->fileName = $fileName;
$this->fp = fopen($this->fileName,'r');
if (fread($this->fp,4)=='8BPS') {
$this->infoArray['version id'] = $this->_getInteger(2);
fseek($this->fp,6,SEEK_CUR); // 6 bytes of 0's
$this->infoArray['channels'] = $this->_getInteger(2);
$this->infoArray['rows'] = $this->_getInteger(4);
$this->infoArray['columns'] = $this->_getInteger(4);
$this->infoArray['colorDepth'] = $this->_getInteger(2);
$this->infoArray['colorMode'] = $this->_getInteger(2);
/* COLOR MODE DATA SECTION */ //4bytes Length The length of the following color data.
$this->infoArray['colorModeDataSectionLength'] = $this->_getInteger(4);
fseek($this->fp,$this->infoArray['colorModeDataSectionLength'],SEEK_CUR); // ignore this snizzle
/* IMAGE RESOURCES */
$this->infoArray['imageResourcesSectionLength'] = $this->_getInteger(4);
fseek($this->fp,$this->infoArray['imageResourcesSectionLength'],SEEK_CUR);