当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Pdf_Resource_Image::__construct方法代码示例

本文整理汇总了PHP中Zend_Pdf_Resource_Image::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Pdf_Resource_Image::__construct方法的具体用法?PHP Zend_Pdf_Resource_Image::__construct怎么用?PHP Zend_Pdf_Resource_Image::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Pdf_Resource_Image的用法示例。


在下文中一共展示了Zend_Pdf_Resource_Image::__construct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Object constructor
  *
  * @param string $imageFileName
  * @throws Zend_Pdf_Exception
  */
 public function __construct($imageFileName)
 {
     if (!function_exists('gd_info')) {
         throw new Zend_Pdf_Exception('Image extension is not installed.');
     }
     $gd_options = gd_info();
     if (!$gd_options['JPG Support']) {
         throw new Zend_Pdf_Exception('JPG support is not configured properly.');
     }
     if (($imageInfo = getimagesize($imageFileName)) === false) {
         throw new Zend_Pdf_Exception('Corrupted image or image doesn\'t exist.');
     }
     if ($imageInfo[2] != IMAGETYPE_JPEG && $imageInfo[2] != IMAGETYPE_JPEG2000) {
         throw new Zend_Pdf_Exception('ImageType is not JPG');
     }
     parent::__construct();
     switch ($imageInfo['channels']) {
         case 3:
             $colorSpace = 'DeviceRGB';
             break;
         case 4:
             $colorSpace = 'DeviceCMYK';
             break;
         default:
             $colorSpace = 'DeviceGray';
             break;
     }
     $imageDictionary = $this->_resource->dictionary;
     $imageDictionary->Width = new Zend_Pdf_Element_Numeric($imageInfo[0]);
     $imageDictionary->Height = new Zend_Pdf_Element_Numeric($imageInfo[1]);
     $imageDictionary->ColorSpace = new Zend_Pdf_Element_Name($colorSpace);
     $imageDictionary->BitsPerComponent = new Zend_Pdf_Element_Numeric($imageInfo['bits']);
     if ($imageInfo[2] == IMAGETYPE_JPEG) {
         $imageDictionary->Filter = new Zend_Pdf_Element_Name('DCTDecode');
     } else {
         if ($imageInfo[2] == IMAGETYPE_JPEG2000) {
             $imageDictionary->Filter = new Zend_Pdf_Element_Name('JPXDecode');
         }
     }
     if (($imageFile = @fopen($imageFileName, 'rb')) === false) {
         throw new Zend_Pdf_Exception("Can not open '{$imageFileName}' file for reading.");
     }
     $byteCount = filesize($imageFileName);
     $this->_resource->value = '';
     while ($byteCount > 0 && ($nextBlock = fread($imageFile, $byteCount)) != false) {
         $this->_resource->value .= $nextBlock;
         $byteCount -= strlen($nextBlock);
     }
     fclose($imageFile);
     $this->_resource->skipFilters();
     $this->_width = $imageInfo[0];
     $this->_height = $imageInfo[1];
     $this->_imageProperties = array();
     $this->_imageProperties['bitDepth'] = $imageInfo['bits'];
     $this->_imageProperties['jpegImageType'] = $imageInfo[2];
     $this->_imageProperties['jpegColorType'] = $imageInfo['channels'];
 }
开发者ID:dalinhuang,项目名称:popo,代码行数:63,代码来源:Jpeg.php

示例2: __construct

 /**
  * Object constructor
  *
  * @param string $imageFileName
  * @throws Zend_Pdf_Exception
  */
 public function __construct($imageFileName)
 {
     if (($imageFile = @fopen($imageFileName, 'rb')) === false) {
         // require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception("Can not open '{$imageFileName}' file for reading.");
     }
     $byteOrderIndicator = fread($imageFile, 2);
     if ($byteOrderIndicator == 'II') {
         $this->_endianType = Zend_Pdf_Resource_Image_Tiff::TIFF_ENDIAN_LITTLE;
     } else {
         if ($byteOrderIndicator == 'MM') {
             $this->_endianType = Zend_Pdf_Resource_Image_Tiff::TIFF_ENDIAN_BIG;
         } else {
             // require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception("Not a tiff file or Tiff corrupt. No byte order indication found");
         }
     }
     $version = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
     if ($version != 42) {
         // require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception("Not a tiff file or Tiff corrupt. Incorrect version number.");
     }
     $ifdOffset = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_LONG, fread($imageFile, 4));
     $fileStats = fstat($imageFile);
     $this->_fileSize = $fileStats['size'];
     /*
      * Tiff files are stored as a series of Image File Directories (IFD) each direcctory
      * has a specific number of entries each 12 bytes in length. At the end of the directories
      * is four bytes pointing to the offset of the next IFD.
      */
     while ($ifdOffset > 0) {
         if (fseek($imageFile, $ifdOffset, SEEK_SET) == -1 || $ifdOffset + 2 >= $this->_fileSize) {
             // require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception("Could not seek to the image file directory as indexed by the file. Likely cause is TIFF corruption. Offset: " . $ifdOffset);
         }
         $numDirEntries = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
         /*
          * Since we now know how many entries are in this (IFD) we can extract the data.
          * The format of a TIFF directory entry is:
          *
          * 2 bytes (short) tag code; See TIFF_TAG constants at the top for supported values. (There are many more in the spec)
          * 2 bytes (short) field type
          * 4 bytes (long) number of values, or value count.
          * 4 bytes (mixed) data if the data will fit into 4 bytes or an offset if the data is too large.
          */
         for ($dirEntryIdx = 1; $dirEntryIdx <= $numDirEntries; $dirEntryIdx++) {
             $tag = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
             $fieldType = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
             $valueCount = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_LONG, fread($imageFile, 4));
             switch ($fieldType) {
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_BYTE:
                     $fieldLength = $valueCount;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_ASCII:
                     $fieldLength = $valueCount;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_SHORT:
                     $fieldLength = $valueCount * 2;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_LONG:
                     $fieldLength = $valueCount * 4;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_RATIONAL:
                     $fieldLength = $valueCount * 8;
                     break;
                 default:
                     $fieldLength = $valueCount;
             }
             $offsetBytes = fread($imageFile, 4);
             if ($fieldLength <= 4) {
                 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
                     //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
                     //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.
//.........这里部分代码省略.........
开发者ID:yonetici,项目名称:pimcore-coreshop-demo,代码行数:101,代码来源:Tiff.php

示例3: __construct

 /**
  * Object constructor
  *
  * @param string $imageFileName
  * @throws Zend_Pdf_Exception
  * @todo Add compression conversions to support compression strategys other than PNG_COMPRESSION_DEFAULT_STRATEGY.
  * @todo Add pre-compression filtering.
  * @todo Add interlaced image handling.
  * @todo Add support for 16-bit images. Requires PDF version bump to 1.5 at least.
  * @todo Add processing for all PNG chunks defined in the spec. gAMA etc.
  * @todo Fix tRNS chunk support for Indexed Images to a SMask.
  */
 public function __construct($imageFileName)
 {
     if (($imageFile = @fopen($imageFileName, 'rb')) === false) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception("Can not open '{$imageFileName}' file for reading.");
     }
     parent::__construct();
     //Check if the file is a PNG
     fseek($imageFile, 1, SEEK_CUR);
     //First signature byte (%)
     if ('PNG' != fread($imageFile, 3)) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Image is not a PNG');
     }
     fseek($imageFile, 12, SEEK_CUR);
     //Signature bytes (Includes the IHDR chunk) IHDR processed linerarly because it doesnt contain a variable chunk length
     $wtmp = unpack('Ni', fread($imageFile, 4));
     //Unpack a 4-Byte Long
     $width = $wtmp['i'];
     $htmp = unpack('Ni', fread($imageFile, 4));
     $height = $htmp['i'];
     $bits = ord(fread($imageFile, 1));
     //Higher than 8 bit depths are only supported in later versions of PDF.
     $color = ord(fread($imageFile, 1));
     $compression = ord(fread($imageFile, 1));
     $prefilter = ord(fread($imageFile, 1));
     if (($interlacing = ord(fread($imageFile, 1))) != Zend_Pdf_Resource_Image_Png::PNG_INTERLACING_DISABLED) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception("Only non-interlaced images are currently supported.");
     }
     $this->_width = $width;
     $this->_height = $height;
     $this->_imageProperties = array();
     $this->_imageProperties['bitDepth'] = $bits;
     $this->_imageProperties['pngColorType'] = $color;
     $this->_imageProperties['pngFilterType'] = $prefilter;
     $this->_imageProperties['pngCompressionType'] = $compression;
     $this->_imageProperties['pngInterlacingType'] = $interlacing;
     fseek($imageFile, 4, SEEK_CUR);
     //4 Byte Ending Sequence
     $imageData = '';
     /*
      * The following loop processes PNG chunks. 4 Byte Longs are packed first give the chunk length
      * followed by the chunk signature, a four byte code. IDAT and IEND are manditory in any PNG.
      */
     while (!feof($imageFile)) {
         $chunkLengthBytes = fread($imageFile, 4);
         if ($chunkLengthBytes === false) {
             require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception('Error ocuured while image file reading.');
         }
         $chunkLengthtmp = unpack('Ni', $chunkLengthBytes);
         $chunkLength = $chunkLengthtmp['i'];
         $chunkType = fread($imageFile, 4);
         switch ($chunkType) {
             case 'IDAT':
                 //Image Data
                 /*
                  * Reads the actual image data from the PNG file. Since we know at this point that the compression
                  * strategy is the default strategy, we also know that this data is Zip compressed. We will either copy
                  * the data directly to the PDF and provide the correct FlateDecode predictor, or decompress the data
                  * decode the filters and output the data as a raw pixel map.
                  */
                 $imageData .= fread($imageFile, $chunkLength);
                 fseek($imageFile, 4, SEEK_CUR);
                 break;
             case 'PLTE':
                 //Palette
                 $paletteData = fread($imageFile, $chunkLength);
                 fseek($imageFile, 4, SEEK_CUR);
                 break;
             case 'tRNS':
                 //Basic (non-alpha channel) transparency.
                 $trnsData = fread($imageFile, $chunkLength);
                 switch ($color) {
                     case Zend_Pdf_Resource_Image_Png::PNG_CHANNEL_GRAY:
                         $baseColor = ord(substr($trnsData, 1, 1));
                         $transparencyData = array(new Zend_Pdf_Element_Numeric($baseColor), new Zend_Pdf_Element_Numeric($baseColor));
                         break;
                     case Zend_Pdf_Resource_Image_Png::PNG_CHANNEL_RGB:
                         $red = ord(substr($trnsData, 1, 1));
                         $green = ord(substr($trnsData, 3, 1));
                         $blue = ord(substr($trnsData, 5, 1));
                         $transparencyData = array(new Zend_Pdf_Element_Numeric($red), new Zend_Pdf_Element_Numeric($red), new Zend_Pdf_Element_Numeric($green), new Zend_Pdf_Element_Numeric($green), new Zend_Pdf_Element_Numeric($blue), new Zend_Pdf_Element_Numeric($blue));
                         break;
                     case Zend_Pdf_Resource_Image_Png::PNG_CHANNEL_INDEXED:
                         //Find the first transparent color in the index, we will mask that. (This is a bit of a hack. This should be a SMask and mask all entries values).
                         if (($trnsIdx = strpos($trnsData, "")) !== false) {
//.........这里部分代码省略.........
开发者ID:namgiangle90,项目名称:tokyobaito,代码行数:101,代码来源:Png.php

示例4: __construct

 public function __construct($imageFileName)
 {
     if (($imageFile = @fopen($imageFileName, 'rb')) === false) {
         throw new Zend_Pdf_Exception("Can not open '{$imageFileName}' file for reading.");
     }
     $byteOrderIndicator = fread($imageFile, 2);
     if ($byteOrderIndicator == 'II') {
         $this->_endianType = Zend_Pdf_Resource_Image_Tiff::TIFF_ENDIAN_LITTLE;
     } else {
         if ($byteOrderIndicator == 'MM') {
             $this->_endianType = Zend_Pdf_Resource_Image_Tiff::TIFF_ENDIAN_BIG;
         } else {
             throw new Zend_Pdf_Exception("Not a tiff file or Tiff corrupt. No byte order indication found");
         }
     }
     $version = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
     if ($version != 42) {
         throw new Zend_Pdf_Exception("Not a tiff file or Tiff corrupt. Incorrect version number.");
     }
     $ifdOffset = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_LONG, fread($imageFile, 4));
     $fileStats = fstat($imageFile);
     $this->_fileSize = $fileStats['size'];
     while ($ifdOffset > 0) {
         if (fseek($imageFile, $ifdOffset, SEEK_SET) == -1 || $ifdOffset + 2 >= $this->_fileSize) {
             throw new Zend_Pdf_Exception("Could not seek to the image file directory as indexed by the file. Likely cause is TIFF corruption. Offset: " . $ifdOffset);
         }
         $numDirEntries = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
         for ($dirEntryIdx = 1; $dirEntryIdx <= $numDirEntries; $dirEntryIdx++) {
             $tag = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
             $fieldType = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_SHORT, fread($imageFile, 2));
             $valueCount = $this->unpackBytes(Zend_Pdf_Resource_Image_Tiff::UNPACK_TYPE_LONG, fread($imageFile, 4));
             switch ($fieldType) {
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_BYTE:
                     $fieldLength = $valueCount;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_ASCII:
                     $fieldLength = $valueCount;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_SHORT:
                     $fieldLength = $valueCount * 2;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_LONG:
                     $fieldLength = $valueCount * 4;
                     break;
                 case Zend_Pdf_Resource_Image_Tiff::TIFF_FIELD_TYPE_RATIONAL:
                     $fieldLength = $valueCount * 8;
                     break;
                 default:
                     $fieldLength = $valueCount;
             }
             $offsetBytes = fread($imageFile, 4);
             if ($fieldLength <= 4) {
                 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:
                     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:
                     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);
             }
             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:
                         case Zend_Pdf_Resource_Image_Tiff::TIFF_COMPRESSION_GROUP_3_FAX:
                         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;
//.........这里部分代码省略.........
开发者ID:subashemphasize,项目名称:test_site,代码行数:101,代码来源:Pdf_Pack.php


注:本文中的Zend_Pdf_Resource_Image::__construct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。