File indexing completed on 2024-12-29 05:27:55
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Pdf 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 0023 /** Internally used classes */ 0024 // require_once 'Zend/Pdf/Element/Name.php'; 0025 // require_once 'Zend/Pdf/Element/Numeric.php'; 0026 0027 0028 /** Zend_Pdf_Resource_Image */ 0029 // require_once 'Zend/Pdf/Resource/Image.php'; 0030 0031 /** 0032 * JPEG image 0033 * 0034 * @package Zend_Pdf 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_Pdf_Resource_Image_Jpeg extends Zend_Pdf_Resource_Image 0039 { 0040 0041 protected $_width; 0042 protected $_height; 0043 protected $_imageProperties; 0044 0045 /** 0046 * Object constructor 0047 * 0048 * @param string $imageFileName 0049 * @throws Zend_Pdf_Exception 0050 */ 0051 public function __construct($imageFileName) 0052 { 0053 if (!function_exists('gd_info')) { 0054 // require_once 'Zend/Pdf/Exception.php'; 0055 throw new Zend_Pdf_Exception('Image extension is not installed.'); 0056 } 0057 0058 $gd_options = gd_info(); 0059 if ( (!isset($gd_options['JPG Support']) || $gd_options['JPG Support'] != true) && 0060 (!isset($gd_options['JPEG Support']) || $gd_options['JPEG Support'] != true) ) { 0061 // require_once 'Zend/Pdf/Exception.php'; 0062 throw new Zend_Pdf_Exception('JPG support is not configured properly.'); 0063 } 0064 0065 if (($imageInfo = getimagesize($imageFileName)) === false) { 0066 // require_once 'Zend/Pdf/Exception.php'; 0067 throw new Zend_Pdf_Exception('Corrupted image or image doesn\'t exist.'); 0068 } 0069 if ($imageInfo[2] != IMAGETYPE_JPEG && $imageInfo[2] != IMAGETYPE_JPEG2000) { 0070 // require_once 'Zend/Pdf/Exception.php'; 0071 throw new Zend_Pdf_Exception('ImageType is not JPG'); 0072 } 0073 0074 parent::__construct(); 0075 0076 switch ($imageInfo['channels']) { 0077 case 3: 0078 $colorSpace = 'DeviceRGB'; 0079 break; 0080 case 4: 0081 $colorSpace = 'DeviceCMYK'; 0082 break; 0083 default: 0084 $colorSpace = 'DeviceGray'; 0085 break; 0086 } 0087 0088 $imageDictionary = $this->_resource->dictionary; 0089 $imageDictionary->Width = new Zend_Pdf_Element_Numeric($imageInfo[0]); 0090 $imageDictionary->Height = new Zend_Pdf_Element_Numeric($imageInfo[1]); 0091 $imageDictionary->ColorSpace = new Zend_Pdf_Element_Name($colorSpace); 0092 $imageDictionary->BitsPerComponent = new Zend_Pdf_Element_Numeric($imageInfo['bits']); 0093 if ($imageInfo[2] == IMAGETYPE_JPEG) { 0094 $imageDictionary->Filter = new Zend_Pdf_Element_Name('DCTDecode'); 0095 } else if ($imageInfo[2] == IMAGETYPE_JPEG2000){ 0096 $imageDictionary->Filter = new Zend_Pdf_Element_Name('JPXDecode'); 0097 } 0098 0099 if (($imageFile = @fopen($imageFileName, 'rb')) === false ) { 0100 // require_once 'Zend/Pdf/Exception.php'; 0101 throw new Zend_Pdf_Exception( "Can not open '$imageFileName' file for reading." ); 0102 } 0103 $byteCount = filesize($imageFileName); 0104 $this->_resource->value = ''; 0105 0106 while ($byteCount > 0 && !feof($imageFile)) { 0107 $nextBlock = fread($imageFile, $byteCount); 0108 if ($nextBlock === false) { 0109 // require_once 'Zend/Pdf/Exception.php'; 0110 throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." ); 0111 } 0112 0113 $this->_resource->value .= $nextBlock; 0114 $byteCount -= strlen($nextBlock); 0115 } 0116 if ($byteCount != 0) { 0117 // require_once 'Zend/Pdf/Exception.php'; 0118 throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." ); 0119 } 0120 fclose($imageFile); 0121 $this->_resource->skipFilters(); 0122 0123 $this->_width = $imageInfo[0]; 0124 $this->_height = $imageInfo[1]; 0125 $this->_imageProperties = array(); 0126 $this->_imageProperties['bitDepth'] = $imageInfo['bits']; 0127 $this->_imageProperties['jpegImageType'] = $imageInfo[2]; 0128 $this->_imageProperties['jpegColorType'] = $imageInfo['channels']; 0129 } 0130 0131 /** 0132 * Image width 0133 */ 0134 public function getPixelWidth() { 0135 return $this->_width; 0136 } 0137 0138 /** 0139 * Image height 0140 */ 0141 public function getPixelHeight() { 0142 return $this->_height; 0143 } 0144 0145 /** 0146 * Image properties 0147 */ 0148 public function getProperties() { 0149 return $this->_imageProperties; 0150 } 0151 } 0152