Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Image.php
Go to the documentation of this file.
1 <?php
36 abstract class Zend_Pdf_Image
37 {
38  /**** Class Constants ****/
39 
40 
41  /* Image Types */
42 
43  const TYPE_UNKNOWN = 0;
44  const TYPE_JPEG = 1;
45  const TYPE_PNG = 2;
46  const TYPE_TIFF = 3;
47 
48  /* TIFF Constants */
49 
55 
57  const TIFF_TAG_IMAGE_LENGTH=257; //Height
64 
74 
82 
83  /* PNG Constants */
84 
89 
90  const PNG_FILTER_NONE = 0;
91  const PNG_FILTER_SUB = 1;
92  const PNG_FILTER_UP = 2;
93  const PNG_FILTER_AVERAGE = 3;
94  const PNG_FILTER_PAETH = 4;
95 
98 
99  const PNG_CHANNEL_GRAY = 0;
100  const PNG_CHANNEL_RGB = 2;
104 
105  /**** Public Interface ****/
106 
107 
108  /* Factory Methods */
109 
117  public static function imageWithPath($filePath)
118  {
123  #require_once 'Zend/Pdf/Resource/ImageFactory.php';
124  return Zend_Pdf_Resource_ImageFactory::factory($filePath);
125 
126 
127  /* Create a file parser data source object for this file. File path and
128  * access permission checks are handled here.
129  */
130  #require_once 'Zend/Pdf/FileParserDataSource/File.php';
131  $dataSource = new Zend_Pdf_FileParserDataSource_File($filePath);
132 
133  /* Attempt to determine the type of image. We can't always trust file
134  * extensions, but try that first since it's fastest.
135  */
136  $fileExtension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
137 
138  /* If it turns out that the file is named improperly and we guess the
139  * wrong type, we'll get null instead of an image object.
140  */
141  switch ($fileExtension) {
142  case 'tif':
143  //Fall through to next case;
144  case 'tiff':
146  break;
147  case 'png':
149  break;
150  case 'jpg':
151  //Fall through to next case;
152  case 'jpe':
153  //Fall through to next case;
154  case 'jpeg':
156  break;
157  default:
158  #require_once 'Zend/Pdf/Exception.php';
159  throw new Zend_Pdf_Exception("Cannot create image resource. File extension not known or unsupported type.");
160  break;
161  }
162 
163  /* Done with the data source object.
164  */
165  $dataSource = null;
166 
167  if ($image !== null) {
168  return $image;
169 
170  } else {
171  /* The type of image could not be determined. Give up.
172  */
173  #require_once 'Zend/Pdf/Exception.php';
174  throw new Zend_Pdf_Exception("Cannot determine image type: $filePath",
176  }
177  }
178 
179 
180 
181  /**** Internal Methods ****/
182 
183 
184  /* Image Extraction Methods */
185 
194  protected static function _extractJpegImage($dataSource)
195  {
196  #require_once 'Zend/Pdf/Exception.php';
197  throw new Zend_Pdf_Exception('Jpeg image fileparser is not implemented. Old styly implementation has to be used.');
198 
199  #require_once 'Zend/Pdf/FileParser/Image/Jpeg.php';
200  $imageParser = new Zend_Pdf_FileParser_Image_Jpeg($dataSource);
201  #require_once 'Zend/Pdf/Resource/Image/Jpeg.php';
202  $image = new Zend_Pdf_Resource_Image_Jpeg($imageParser);
203  unset($imageParser);
204 
205  return $image;
206  }
207 
215  protected static function _extractPngImage($dataSource)
216  {
217  #require_once 'Zend/Pdf/FileParser/Image/Png.php';
218  $imageParser = new Zend_Pdf_FileParser_Image_Png($dataSource);
219  #require_once 'Zend/Pdf/Resource/Image/Png.php';
220  $image = new Zend_Pdf_Resource_Image_Png($imageParser);
221  unset($imageParser);
222 
223  return $image;
224  }
225 
234  protected static function _extractTiffImage($dataSource)
235  {
236  #require_once 'Zend/Pdf/Exception.php';
237  throw new Zend_Pdf_Exception('Tiff image fileparser is not implemented. Old styly implementation has to be used.');
238 
239  #require_once 'Zend/Pdf/FileParser/Image/Tiff.php';
240  $imageParser = new Zend_Pdf_FileParser_Image_Tiff($dataSource);
241  #require_once 'Zend/Pdf/Resource/Image/Tiff.php';
242  $image = new Zend_Pdf_Resource_Image_Tiff($imageParser);
243  unset($imageParser);
244 
245  return $image;
246  }
247 }
const PNG_FILTER_NONE
Definition: Image.php:90
const TIFF_FIELD_TYPE_LONG
Definition: Image.php:53
static _extractJpegImage($dataSource)
Definition: Image.php:194
const PNG_INTERLACING_DISABLED
Definition: Image.php:96
const TIFF_FIELD_TYPE_SHORT
Definition: Image.php:52
const TIFF_PHOTOMETRIC_INTERPRETATION_YCBCR
Definition: Image.php:80
const TIFF_PHOTOMETRIC_INTERPRETATION_BLACK_IS_ZERO
Definition: Image.php:76
const TIFF_TAG_STRIP_BYTE_COUNTS
Definition: Image.php:63
const TIFF_TAG_BITS_PER_SAMPLE
Definition: Image.php:58
const PNG_FILTER_PAETH
Definition: Image.php:94
const TIFF_PHOTOMETRIC_INTERPRETATION_RGB
Definition: Image.php:77
const TIFF_TAG_STRIP_OFFSETS
Definition: Image.php:61
static _extractTiffImage($dataSource)
Definition: Image.php:234
const TIFF_FIELD_TYPE_BYTE
Definition: Image.php:50
const PNG_CHANNEL_RGB
Definition: Image.php:100
const TIFF_PHOTOMETRIC_INTERPRETATION_RGB_INDEXED
Definition: Image.php:78
const PNG_COMPRESSION_DEFAULT_STRATEGY
Definition: Image.php:85
const PNG_CHANNEL_GRAY_ALPHA
Definition: Image.php:102
const TYPE_JPEG
Definition: Image.php:44
const TIFF_TAG_SAMPLES_PER_PIXEL
Definition: Image.php:62
const TIFF_PHOTOMETRIC_INTERPRETATION_WHITE_IS_ZERO
Definition: Image.php:75
const TIFF_COMPRESSION_FLATE
Definition: Image.php:71
const TIFF_TAG_IMAGE_LENGTH
Definition: Image.php:57
const TIFF_COMPRESSION_GROUP_4_FAX
Definition: Image.php:68
const PNG_FILTER_AVERAGE
Definition: Image.php:93
const PNG_FILTER_UP
Definition: Image.php:92
static _extractPngImage($dataSource)
Definition: Image.php:215
const TIFF_TAG_COMPRESSION
Definition: Image.php:59
const TIFF_COMPRESSION_LZW
Definition: Image.php:69
const TIFF_PHOTOMETRIC_INTERPRETATION_CMYK
Definition: Image.php:79
static imageWithPath($filePath)
Definition: Image.php:117
const TIFF_COMPRESSION_JPEG
Definition: Image.php:70
const TIFF_COMPRESSION_PACKBITS
Definition: Image.php:73
const PNG_COMPRESSION_FILTERED
Definition: Image.php:86
const PNG_COMPRESSION_RLE
Definition: Image.php:88
const TYPE_TIFF
Definition: Image.php:46
const PNG_COMPRESSION_HUFFMAN_ONLY
Definition: Image.php:87
const TIFF_TAG_PHOTOMETRIC_INTERPRETATION
Definition: Image.php:60
const TIFF_COMPRESSION_UNCOMPRESSED
Definition: Image.php:65
const TIFF_COMPRESSION_FLATE_OBSOLETE_CODE
Definition: Image.php:72
const CANT_DETERMINE_IMAGE_TYPE
Definition: Exception.php:336
const PNG_CHANNEL_RGB_ALPHA
Definition: Image.php:103
const TIFF_FIELD_TYPE_RATIONAL
Definition: Image.php:54
const PNG_CHANNEL_INDEXED
Definition: Image.php:101
const TIFF_COMPRESSION_CCITT1D
Definition: Image.php:66
const TYPE_UNKNOWN
Definition: Image.php:43
const TIFF_FIELD_TYPE_ASCII
Definition: Image.php:51
const TIFF_PHOTOMETRIC_INTERPRETATION_CIELAB
Definition: Image.php:81
const TIFF_COMPRESSION_GROUP_3_FAX
Definition: Image.php:67
const TYPE_PNG
Definition: Image.php:45
const TIFF_TAG_IMAGE_WIDTH
Definition: Image.php:56
const PNG_CHANNEL_GRAY
Definition: Image.php:99
const PNG_FILTER_SUB
Definition: Image.php:91
const PNG_INTERLACING_ENABLED
Definition: Image.php:97