81 if (($imageFile = @
fopen($imageFileName,
'rb')) ===
false ) {
82 #require_once 'Zend/Pdf/Exception.php'; 86 parent::__construct();
89 fseek($imageFile, 1, SEEK_CUR);
90 if (
'PNG' != fread($imageFile, 3)) {
91 #require_once 'Zend/Pdf/Exception.php'; 94 fseek($imageFile, 12, SEEK_CUR);
95 $wtmp = unpack(
'Ni',fread($imageFile, 4));
97 $htmp = unpack(
'Ni',fread($imageFile, 4));
99 $bits = ord(fread($imageFile, 1));
100 $color = ord(fread($imageFile, 1));
102 $compression = ord(fread($imageFile, 1));
103 $prefilter = ord(fread($imageFile,1));
106 #require_once 'Zend/Pdf/Exception.php'; 107 throw new Zend_Pdf_Exception(
"Only non-interlaced images are currently supported." );
110 $this->_width = $width;
111 $this->_height = $height;
112 $this->_imageProperties = array();
113 $this->_imageProperties[
'bitDepth'] = $bits;
114 $this->_imageProperties[
'pngColorType'] = $color;
115 $this->_imageProperties[
'pngFilterType'] = $prefilter;
116 $this->_imageProperties[
'pngCompressionType'] = $compression;
117 $this->_imageProperties[
'pngInterlacingType'] = $interlacing;
119 fseek($imageFile, 4, SEEK_CUR);
126 while (!
feof($imageFile)) {
127 $chunkLengthBytes = fread($imageFile, 4);
128 if ($chunkLengthBytes ===
false) {
129 #require_once 'Zend/Pdf/Exception.php'; 133 $chunkLengthtmp = unpack(
'Ni', $chunkLengthBytes);
134 $chunkLength = $chunkLengthtmp[
'i'];
135 $chunkType = fread($imageFile, 4);
144 $imageData .= fread($imageFile, $chunkLength);
145 fseek($imageFile, 4, SEEK_CUR);
149 $paletteData = fread($imageFile, $chunkLength);
150 fseek($imageFile, 4, SEEK_CUR);
154 $trnsData = fread($imageFile, $chunkLength);
157 $baseColor = ord(substr($trnsData, 1, 1));
163 $red = ord(substr($trnsData,1,1));
164 $green = ord(substr($trnsData,3,1));
165 $blue = ord(substr($trnsData,5,1));
176 if(($trnsIdx = strpos($trnsData,
"\0")) !==
false) {
186 #require_once 'Zend/Pdf/Exception.php'; 190 fseek($imageFile, 4, SEEK_CUR);
197 fseek($imageFile, $chunkLength + 4, SEEK_CUR);
216 if(empty($paletteData)) {
217 #require_once 'Zend/Pdf/Exception.php'; 218 throw new Zend_Pdf_Exception(
"PNG Corruption: No palette data read for indexed type PNG." );
225 $colorSpace->items[] = $paletteObject;
235 #require_once 'Zend/Pdf/Exception.php'; 241 #require_once 'Zend/Pdf/ElementFactory.php'; 243 $decodingStream = $decodingObjFactory->newStreamObject($imageData);
250 $decodingStream->skipFilters();
252 $pngDataRawDecoded = $decodingStream->value;
255 for($pixel = 0, $pixelcount = ($width * $height); $pixel < $pixelcount; $pixel++) {
256 $imageDataTmp .= $pngDataRawDecoded[($pixel*2)];
257 $smaskData .= $pngDataRawDecoded[($pixel*2)+1];
260 $imageData = $imageDataTmp;
270 #require_once 'Zend/Pdf/Exception.php'; 276 #require_once 'Zend/Pdf/ElementFactory.php'; 278 $decodingStream = $decodingObjFactory->newStreamObject($imageData);
285 $decodingStream->skipFilters();
287 $pngDataRawDecoded = $decodingStream->value;
290 for($pixel = 0, $pixelcount = ($width * $height); $pixel < $pixelcount; $pixel++) {
291 $imageDataTmp .= $pngDataRawDecoded[($pixel*4)+0] . $pngDataRawDecoded[($pixel*4)+1] . $pngDataRawDecoded[($pixel*4)+2];
292 $smaskData .= $pngDataRawDecoded[($pixel*4)+3];
296 $imageData = $imageDataTmp;
300 #require_once 'Zend/Pdf/Exception.php'; 304 if(empty($imageData)) {
305 #require_once 'Zend/Pdf/Exception.php'; 309 $imageDictionary = $this->_resource->dictionary;
310 if(!empty($smaskData)) {
314 $smaskStream = $this->_objectFactory->newStreamObject($smaskData);
321 $imageDictionary->SMask = $smaskStream;
324 $smaskStreamDecodeParms = array();
333 if(!empty($transparencyData)) {
340 $imageDictionary->ColorSpace = $colorSpace;
344 $decodeParms = array();
352 $this->_resource->value = $imageData;
356 $this->_resource->skipFilters();
const PNG_CHANNEL_RGB_ALPHA
const PNG_CHANNEL_GRAY_ALPHA
const PNG_INTERLACING_DISABLED
const PNG_CHANNEL_INDEXED
static createFactory($objCount)