Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Pdf_Resource_Image_Jpeg Class Reference
Inheritance diagram for Zend_Pdf_Resource_Image_Jpeg:
Zend_Pdf_Resource_Image Zend_Pdf_Resource

Public Member Functions

 __construct ($imageFileName)
 
 getPixelWidth ()
 
 getPixelHeight ()
 
 getProperties ()
 
- Public Member Functions inherited from Zend_Pdf_Resource_Image
 __construct ()
 
 getPixelHeight ()
 
 getPixelWidth ()
 
 getProperties ()
 
- Public Member Functions inherited from Zend_Pdf_Resource
 __construct ($resource)
 
 __clone ()
 
 cloneResource ($factory, &$processed)
 
 getResource ()
 
 getFactory ()
 

Protected Attributes

 $_width
 
 $_height
 
 $_imageProperties
 
- Protected Attributes inherited from Zend_Pdf_Resource
 $_objectFactory
 
 $_resource
 

Detailed Description

Definition at line 38 of file Jpeg.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $imageFileName)

Object constructor

Parameters
string$imageFileName
Exceptions
Zend_Pdf_Exception

Definition at line 51 of file Jpeg.php.

52  {
53  if (!function_exists('gd_info')) {
54  #require_once 'Zend/Pdf/Exception.php';
55  throw new Zend_Pdf_Exception('Image extension is not installed.');
56  }
57 
58  $gd_options = gd_info();
59  if ( (!isset($gd_options['JPG Support']) || $gd_options['JPG Support'] != true) &&
60  (!isset($gd_options['JPEG Support']) || $gd_options['JPEG Support'] != true) ) {
61  #require_once 'Zend/Pdf/Exception.php';
62  throw new Zend_Pdf_Exception('JPG support is not configured properly.');
63  }
64 
65  if (($imageInfo = getimagesize($imageFileName)) === false) {
66  #require_once 'Zend/Pdf/Exception.php';
67  throw new Zend_Pdf_Exception('Corrupted image or image doesn\'t exist.');
68  }
69  if ($imageInfo[2] != IMAGETYPE_JPEG && $imageInfo[2] != IMAGETYPE_JPEG2000) {
70  #require_once 'Zend/Pdf/Exception.php';
71  throw new Zend_Pdf_Exception('ImageType is not JPG');
72  }
73 
74  parent::__construct();
75 
76  switch ($imageInfo['channels']) {
77  case 3:
78  $colorSpace = 'DeviceRGB';
79  break;
80  case 4:
81  $colorSpace = 'DeviceCMYK';
82  break;
83  default:
84  $colorSpace = 'DeviceGray';
85  break;
86  }
87 
88  $imageDictionary = $this->_resource->dictionary;
89  $imageDictionary->Width = new Zend_Pdf_Element_Numeric($imageInfo[0]);
90  $imageDictionary->Height = new Zend_Pdf_Element_Numeric($imageInfo[1]);
91  $imageDictionary->ColorSpace = new Zend_Pdf_Element_Name($colorSpace);
92  $imageDictionary->BitsPerComponent = new Zend_Pdf_Element_Numeric($imageInfo['bits']);
93  if ($imageInfo[2] == IMAGETYPE_JPEG) {
94  $imageDictionary->Filter = new Zend_Pdf_Element_Name('DCTDecode');
95  } else if ($imageInfo[2] == IMAGETYPE_JPEG2000){
96  $imageDictionary->Filter = new Zend_Pdf_Element_Name('JPXDecode');
97  }
98 
99  if (($imageFile = @fopen($imageFileName, 'rb')) === false ) {
100  #require_once 'Zend/Pdf/Exception.php';
101  throw new Zend_Pdf_Exception( "Can not open '$imageFileName' file for reading." );
102  }
103  $byteCount = filesize($imageFileName);
104  $this->_resource->value = '';
105 
106  while ($byteCount > 0 && !feof($imageFile)) {
107  $nextBlock = fread($imageFile, $byteCount);
108  if ($nextBlock === false) {
109  #require_once 'Zend/Pdf/Exception.php';
110  throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." );
111  }
112 
113  $this->_resource->value .= $nextBlock;
114  $byteCount -= strlen($nextBlock);
115  }
116  if ($byteCount != 0) {
117  #require_once 'Zend/Pdf/Exception.php';
118  throw new Zend_Pdf_Exception( "Error occured while '$imageFileName' file reading." );
119  }
120  fclose($imageFile);
121  $this->_resource->skipFilters();
122 
123  $this->_width = $imageInfo[0];
124  $this->_height = $imageInfo[1];
125  $this->_imageProperties = array();
126  $this->_imageProperties['bitDepth'] = $imageInfo['bits'];
127  $this->_imageProperties['jpegImageType'] = $imageInfo[2];
128  $this->_imageProperties['jpegColorType'] = $imageInfo['channels'];
129  }

Member Function Documentation

◆ getPixelHeight()

getPixelHeight ( )

Image height

Definition at line 141 of file Jpeg.php.

141  {
142  return $this->_height;
143  }

◆ getPixelWidth()

getPixelWidth ( )

Image width

Definition at line 134 of file Jpeg.php.

134  {
135  return $this->_width;
136  }

◆ getProperties()

getProperties ( )

Image properties

Definition at line 148 of file Jpeg.php.

148  {
150  }

Field Documentation

◆ $_height

$_height
protected

Definition at line 42 of file Jpeg.php.

◆ $_imageProperties

$_imageProperties
protected

Definition at line 43 of file Jpeg.php.

◆ $_width

$_width
protected

Definition at line 41 of file Jpeg.php.


The documentation for this class was generated from the following file: