psd解析java_php读取psd文件格式解析

更新时间:2023-07-20 11:29:48 阅读: 评论:0

psd解析java_php读取psd⽂件格式解析
/* This file is relead under the GPL, any version you like
*
*PHP PSD reader class, v1.3
*
*By Tim de Koning
*
*Kingsquare Information Services, 22 jan 2007内存条怎么装
*
*example u:
*------------
*<?php
*include_once('classPhpPsdReader.php')
*header("Content-type: image/jpeg");
*print imagejpeg(imagecreatefrompsd('test.psd'));
*?>
*
*More info, bugs or requests, contact info@kingsquare.nl
*
*
*TODO
*----
*- read color values for "multichannel data" PSD files
*- find and implement (hunter)lab to RGB algorithm
*- fix 32 has something to do with gamma and exposure available since CS2, but dunno how to */
class PhpPsdReader {
var $infoArray;
var $fp;
var $fileName;
var $tempFileName;
var $colorBytesLength;
function PhpPsdReader($fileName) {
t_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);
fek($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);
fek($this->fp,$this->infoArray['colorModeDataSectionLength'],SEEK_CUR); // ignore this snizzle /* IMAGE RESOURCES */
$this->infoArray['imageResourcesSectionLength'] = $this->_getInteger(4);
fek($this->fp,$this->infoArray['imageResourcesSectionLength'],SEEK_CUR); // ignore this snizzle /* LAYER AND MASK */
$this->infoArray['layerMaskDataSectionLength'] = $this->_getInteger(4);
fek($this->fp,$this->infoArray['layerMaskDataSectionLength'],SEEK_CUR); // ignore this snizzle /* IMAGE DATA */
$this->infoArray['compressionType'] = $this->_getInteger(2);
$this->infoArray['oneColorChannelPixelBytes'] = $this->infoArray['colorDepth']/8;
$this->colorBytesLength = $this->infoArray['rows']*$this->infoArray['columns']*$this-
>infoArray['oneColorChannelPixelBytes'];
if ($this->infoArray['colorMode']==2) {
$this->infoArray['error'] = 'images with indexed colours are not supported yet';
return fal;
}
} el {
$this->infoArray['error'] = 'invalid or unsupported psd';
无拘无束的反义词
return fal;
}
}
function getImage() {
// decompress image data if required
switch($this->infoArray['compressionType']) {
// ca 2:, ca 3: zip not supported yet..
ca 1:
// packed bits
$this->infoArray['scanLinesByteCounts'] = array();
for ($i=0; $iinfoArray['rows']*$this->infoArray['channels']); $i++) $this->infoArray['scanLinesByteCounts'][] = $this-
>_getInteger(2);
$this->tempFileName = tempnam(realpath('/tmp'),'decompresdImageData');
$tfp = fopen($this->tempFileName,'wb');
foreach ($this->infoArray['scanLinesByteCounts'] as $scanLinesByteCount) {
fwrite($tfp,$this->_getPackedBitsDecoded(fread($this->fp,$scanLinesByteCount)));
}
fclo($tfp);
fclo($this->fp);
$this->fp = fopen($this->tempFileName,'r');
default:
// continue with current file handle;
break;
}
// let's write pixel
$image = imagecreatetruecolor($this->infoArray['columns'],$this->infoArray['rows']);
for ($rowPointer = 0; ($rowPointer < $this->infoArray['rows']); $rowPointer++) {
for ($columnPointer = 0; ($columnPointer < $this->infoArray['columns']); $columnPointer++) {
/* The color mode of the file. Supported values are: Bitmap=0;
Grayscale=1; Indexed=2; RGB=3; CMYK=4; Multichannel=7;
Duotone=8; Lab=9.
*/
switch ($this->infoArray['colorMode']) {
ca 2: // info should be able to extract from color mode data ction. not implemented yet, so is grayscale exit;
break;
ca 0:
// bit by bit
if ($columnPointer == 0) $bitPointer = 0;
if ($bitPointer==0) $currentByteBits = str_pad(ba_convert(bin2hex(fread($this->fp,1)), 16, 2),8,'0',STR_PAD_LEFT); $r = $g = $b = (($currentByteBits[$bitPointer]=='1')?0:255);
三角形三条边的关系$bitPointer++;
if ($bitPointer==8) $bitPointer = 0;防火教案
break;
ca 1:
美丽韩国电影ca 8: // 8 is indexed with , so grayscale
$r = $g = $b = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
break;
ca 4: // CMYK
$c = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
$currentPointerPos = ftell($this->fp);
fek($this->fp,$this->colorBytesLength-1,SEEK_CUR);
$m = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
fek($this->fp,$this->colorBytesLength-1,SEEK_CUR);
$y = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
fek($this->fp,$this->colorBytesLength-1,SEEK_CUR);
$k = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
fek($this->fp,$currentPointerPos);
$r = round(($c * $k) / (pow(2,$this->infoArray['colorDepth'])-1));
$g = round(($m * $k) / (pow(2,$this->infoArray['colorDepth'])-1));
$b = round(($y * $k) / (pow(2,$this->infoArray['colorDepth'])-1));
break;
ca 9: // hunter Lab
// i still need an understandable lab2rgb if you have one, plea let me know!
$l = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
$currentPointerPos = ftell($this->fp);
fek($this->fp,$this->colorBytesLength-1,SEEK_CUR);
$a = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
fek($this->fp,$this->colorBytesLength-1,SEEK_CUR);
$b = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']);
fek($this->fp,$currentPointerPos);
$r = $l;
$g = $a;
$b = $b;涂维发
break;
default:
$r = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']); $currentPointerPos = ftell($this->fp);
fek($this->fp,$this->colorBytesLength-1,SEEK_CUR);
$g = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']); fek($this->fp,$this->colorBytesLength-1,SEEK_CUR);
$b = $this->_getInteger($this->infoArray['oneColorChannelPixelBytes']); fek($this->fp,$currentPointerPos);
break;
}
if (($this->infoArray['oneColorChannelPixelBytes']==2)) {
$r = $r >> 8;
$g = $g >> 8;
$b = $b >> 8;
} elif (($this->infoArray['oneColorChannelPixelBytes']==4)) {
$r = $r >> 24;
平安夜礼物
$g = $g >> 24;
$b = $b >> 24;
}
$pixelColor = imagecolorallocate($image,$r,$g,$b);
imagetpixel($image,$columnPointer,$rowPointer,$pixelColor);
}
}
fclo($this->fp);
if (ist($this->tempFileName)) unlink($this->tempFileName);
return $image;
}
/**
*
* PRIVATE FUNCTIONS

本文发布于:2023-07-20 11:29:48,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1088993.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:读取   韩国   关系   防火
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图