📄 tiff.php
字号:
switch($fieldType) { case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_BYTE: $value = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_BYTE, $offsetBytes); break; case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_ASCII: //Fall through to next case case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_LONG: $value = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_LONG, $offsetBytes); break; case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_SHORT: //Fall through to next case default: $value = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, $offsetBytes); } } else { $refOffset = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_LONG, $offsetBytes); } /* * Linear tag processing is probably not the best way to do this. I've processed the tags according to the * Tiff 6 specification and make some assumptions about when tags will be < 4 bytes and fit into $value and when * they will be > 4 bytes and require seek/extraction of the offset. Same goes for extracting arrays of data, like * the data offsets and length. This should be fixed in the future. */ switch($tag) { case Zend_Pdf_Resource_Image_Tiff::TIFF_TAG_IMAGE_WIDTH: $this->_width = $value; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_TAG_IMAGE_LENGTH: $this->_height = $value; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_TAG_BITS_PER_SAMPLE: if($valueCount>1) { $fp = ftell($imageFile); fseek($imageFile, $refOffset, SEEK_SET); $this->_bitsPerSample = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2)); fseek($imageFile, $fp, SEEK_SET); } else { $this->_bitsPerSample = $value; } break; case Zend_Pdf_Resource_Image_Tiff::TIFF_TAG_COMPRESSION: $this->_compression = $value; switch($value) { case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_UNCOMPRESSED: $this->_filter = 'None'; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_CCITT1D: //Fall through to next case case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_GROUP_3_FAX: //Fall through to next case case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_GROUP_4_FAX: $this->_filter = 'CCITTFaxDecode'; throw new Zend_Pdf_Exception("CCITTFaxDecode Compression Mode Not Currently Supported"); break; case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_LZW: $this->_filter = 'LZWDecode'; throw new Zend_Pdf_Exception("LZWDecode Compression Mode Not Currently Supported"); break; case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_JPEG: $this->_filter = 'DCTDecode'; //Should work, doesnt... throw new Zend_Pdf_Exception("JPEG Compression Mode Not Currently Supported"); break; case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_FLATE: //fall through to next case case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_FLATE_OBSOLETE_CODE: $this->_filter = 'FlateDecode'; throw new Zend_Pdf_Exception("ZIP/Flate Compression Mode Not Currently Supported"); break; case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_PACKBITS: $this->_filter = 'RunLengthDecode'; break; } break; case Zend_Pdf_Resource_Image_Tiff::TIFF_TAG_PHOTOMETRIC_INTERPRETATION: $this->_colorCode = $value; $this->_whiteIsZero = false; $this->_blackIsZero = false; switch($value) { case Zend_Pdf_Resource_Image_Tiff::TIFF_PHOTOMETRIC_INTERPRETATION_WHITE_IS_ZERO: $this->_whiteIsZero = true; $this->_colorSpace = 'DeviceGray'; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_PHOTOMETRIC_INTERPRETATION_BLACK_IS_ZERO: $this->_blackIsZero = true; $this->_colorSpace = 'DeviceGray'; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_PHOTOMETRIC_INTERPRETATION_YCBCR: //fall through to next case case Zend_Pdf_Resource_Image_Tiff::TIFF_PHOTOMETRIC_INTERPRETATION_RGB: $this->_colorSpace = 'DeviceRGB'; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_PHOTOMETRIC_INTERPRETATION_RGB_INDEXED: $this->_colorSpace = 'Indexed'; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_PHOTOMETRIC_INTERPRETATION_CMYK: $this->_colorSpace = 'DeviceCMYK'; break; case Zend_Pdf_Resource_Image_Tiff::TIFF_PHOTOMETRIC_INTERPRETATION_CIELAB: $this->_colorSpace = 'Lab'; break; default: throw new Zend_Pdf_Exception('TIFF: Unknown or Unsupported Color Type: '. $value); } break; case Zend_Pdf_Resource_Image_Tiff::TIFF_TAG_STRIP_OFFSETS: if($valueCount>1) { $format = ($this->_endianType == Zend_Pdf_Resource_Image_Tiff::TIFF_ENDIAN_LITTLE)?'V*':'N*'; $fp = ftell($imageFile); fseek($imageFile, $refOffset, SEEK_SET); $stripOffsetsBytes = fread($imageFile, $fieldLength); $this->_imageDataOffset = unpack($format, $stripOffsetsBytes); fseek($imageFile, $fp, SEEK_SET); } else { $this->_imageDataOffset = $value; } break; case Zend_Pdf_Resource_Image_Tiff::TIFF_TAG_STRIP_BYTE_COUNTS: if($valueCount>1) { $format = ($this->_endianType == Zend_Pdf_Resource_Image_Tiff::TIFF_ENDIAN_LITTLE)?'V*':'N*'; $fp = ftell($imageFile); fseek($imageFile, $refOffset, SEEK_SET); $stripByteCountsBytes = fread($imageFile, $fieldLength); $this->_imageDataLength = unpack($format, $stripByteCountsBytes); fseek($imageFile, $fp, SEEK_SET); } else { $this->_imageDataLength = $value; } break; default: //For debugging. It should be harmless to ignore unknown tags, though there is some good info in them. //echo "Unknown tag detected: ". $tag . " value: ". $value; } } $ifdOffset = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_LONG, fread($imageFile, 4)); } if(!isset($this->_imageDataOffset) || !isset($this->_imageDataLength)) { throw new Zend_Pdf_Exception("TIFF: The image processed did not contain image data as expected."); } $imageDataBytes = ''; if(is_array($this->_imageDataOffset)) { if(!is_array($this->_imageDataLength)) { throw new Zend_Pdf_Exception("TIFF: The image contained multiple data offsets but not multiple data lengths. Tiff may be corrupt."); } foreach($this->_imageDataOffset as $idx => $offset) { fseek($imageFile, $this->_imageDataOffset[$idx], SEEK_SET); $imageDataBytes .= fread($imageFile, $this->_imageDataLength[$idx]); } } else { fseek($imageFile, $this->_imageDataOffset, SEEK_SET); $imageDataBytes = fread($imageFile, $this->_imageDataLength); } if($imageDataBytes === '') { throw new Zend_Pdf_Exception("TIFF: No data. Image Corruption"); } fclose($imageFile); parent::__construct(); $imageDictionary = $this->_resource->dictionary; if(!isset($this->_width) || !isset($this->_width)) { throw new Zend_Pdf_Exception("Problem reading tiff file. Tiff is probably corrupt."); } $this->_imageProperties = array(); $this->_imageProperties['bitDepth'] = $this->_bitsPerSample; $this->_imageProperties['fileSize'] = $this->_fileSize; $this->_imageProperties['TIFFendianType'] = $this->_endianType; $this->_imageProperties['TIFFcompressionType'] = $this->_compression; $this->_imageProperties['TIFFwhiteIsZero'] = $this->_whiteIsZero; $this->_imageProperties['TIFFblackIsZero'] = $this->_blackIsZero; $this->_imageProperties['TIFFcolorCode'] = $this->_colorCode; $this->_imageProperties['TIFFimageDataOffset'] = $this->_imageDataOffset; $this->_imageProperties['TIFFimageDataLength'] = $this->_imageDataLength; $this->_imageProperties['PDFfilter'] = $this->_filter; $this->_imageProperties['PDFcolorSpace'] = $this->_colorSpace; $imageDictionary->Width = new Zend_Pdf_Element_Numeric($this->_width); if($this->_whiteIsZero === true) { $imageDictionary->Decode = new Zend_Pdf_Element_Array(array(new Zend_Pdf_Element_Numeric(1), new Zend_Pdf_Element_Numeric(0))); } $imageDictionary->Height = new Zend_Pdf_Element_Numeric($this->_height); $imageDictionary->ColorSpace = new Zend_Pdf_Element_Name($this->_colorSpace); $imageDictionary->BitsPerComponent = new Zend_Pdf_Element_Numeric($this->_bitsPerSample); if(isset($this->_filter) && $this->_filter != 'None') { $imageDictionary->Filter = new Zend_Pdf_Element_Name($this->_filter); } $this->_resource->value = $imageDataBytes; $this->_resource->skipFilters(); } /** * Image width (defined in Zend_Pdf_Resource_Image_Interface) */ public function getPixelWidth() { return $this->_width; } /** * Image height (defined in Zend_Pdf_Resource_Image_Interface) */ public function getPixelHeight() { return $this->_height; } /** * Image properties (defined in Zend_Pdf_Resource_Image_Interface) */ public function getProperties() { return $this->_imageProperties; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -