ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
TCPDF_IMAGES Class Reference

Static image methods used by the TCPDF class. More...

+ Collaboration diagram for TCPDF_IMAGES:

Static Public Member Functions

static getImageFileType ($imgfile, $iminfo=array())
 Return the image type given the file name or array returned by getimagesize() function. More...
 
static setGDImageTransparency ($new_image, $image)
 Set the transparency for the given GD image. More...
 
static _toPNG ($image)
 Convert the loaded image to a PNG and then return a structure for the PDF creator. More...
 
static _toJPEG ($image, $quality)
 Convert the loaded image to a JPEG and then return a structure for the PDF creator. More...
 
static _parsejpeg ($file)
 Extract info from a JPEG file without using the GD library. More...
 
static _parsepng ($file)
 Extract info from a PNG file without using the GD library. More...
 

Static Public Attributes

static $svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode')
 Array of hinheritable SVG properties. More...
 

Detailed Description

Static image methods used by the TCPDF class.

Definition at line 52 of file tcpdf_images.php.

Member Function Documentation

◆ _parsejpeg()

static TCPDF_IMAGES::_parsejpeg (   $file)
static

Extract info from a JPEG file without using the GD library.

Parameters
$file(string) image file to parse
Returns
array structure containing the image data static

Definition at line 162 of file tcpdf_images.php.

162 {
163 $a = getimagesize($file);
164 if (empty($a)) {
165 //Missing or incorrect image file
166 return false;
167 }
168 if ($a[2] != 2) {
169 // Not a JPEG file
170 return false;
171 }
172 // bits per pixel
173 $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
174 // number of image channels
175 if (!isset($a['channels'])) {
176 $channels = 3;
177 } else {
178 $channels = intval($a['channels']);
179 }
180 // default colour space
181 switch ($channels) {
182 case 1: {
183 $colspace = 'DeviceGray';
184 break;
185 }
186 case 3: {
187 $colspace = 'DeviceRGB';
188 break;
189 }
190 case 4: {
191 $colspace = 'DeviceCMYK';
192 break;
193 }
194 default: {
195 $channels = 3;
196 $colspace = 'DeviceRGB';
197 break;
198 }
199 }
200 // get file content
201 $data = file_get_contents($file);
202 // check for embedded ICC profile
203 $icc = array();
204 $offset = 0;
205 while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
206 // get ICC sequence length
207 $length = (TCPDF_STATIC::_getUSHORT($data, ($pos - 2)) - 16);
208 // marker sequence number
209 $msn = max(1, ord($data[($pos + 12)]));
210 // number of markers (total of APP2 used)
211 $nom = max(1, ord($data[($pos + 13)]));
212 // get sequence segment
213 $icc[($msn - 1)] = substr($data, ($pos + 14), $length);
214 // move forward to next sequence
215 $offset = ($pos + 14 + $length);
216 }
217 // order and compact ICC segments
218 if (count($icc) > 0) {
219 ksort($icc);
220 $icc = implode('', $icc);
221 if ((ord($icc{36}) != 0x61) OR (ord($icc{37}) != 0x63) OR (ord($icc{38}) != 0x73) OR (ord($icc{39}) != 0x70)) {
222 // invalid ICC profile
223 $icc = false;
224 }
225 } else {
226 $icc = false;
227 }
228 return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
229 }
print $file
static _getUSHORT($str, $offset)
Get USHORT from string (Big Endian 16-bit unsigned integer).

References $data, $file, and TCPDF_STATIC\_getUSHORT().

Referenced by _toJPEG(), and TCPDF\Image().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _parsepng()

static TCPDF_IMAGES::_parsepng (   $file)
static

Extract info from a PNG file without using the GD library.

Parameters
$file(string) image file to parse
Returns
array structure containing the image data static

Definition at line 237 of file tcpdf_images.php.

237 {
238 $f = fopen($file, 'rb');
239 if ($f === false) {
240 // Can't open image file
241 return false;
242 }
243 //Check signature
244 if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
245 // Not a PNG file
246 return false;
247 }
248 //Read header chunk
249 fread($f, 4);
250 if (fread($f, 4) != 'IHDR') {
251 //Incorrect PNG file
252 return false;
253 }
256 $bpc = ord(fread($f, 1));
257 if ($bpc > 8) {
258 // 16-bit depth not supported
259 fclose($f);
260 return false;
261 }
262 $ct = ord(fread($f, 1));
263 if ($ct == 0) {
264 $colspace = 'DeviceGray';
265 } elseif ($ct == 2) {
266 $colspace = 'DeviceRGB';
267 } elseif ($ct == 3) {
268 $colspace = 'Indexed';
269 } else {
270 // alpha channel
271 fclose($f);
272 return 'pngalpha';
273 }
274 if (ord(fread($f, 1)) != 0) {
275 // Unknown compression method
276 fclose($f);
277 return false;
278 }
279 if (ord(fread($f, 1)) != 0) {
280 // Unknown filter method
281 fclose($f);
282 return false;
283 }
284 if (ord(fread($f, 1)) != 0) {
285 // Interlacing not supported
286 fclose($f);
287 return false;
288 }
289 fread($f, 4);
290 $channels = ($ct == 2 ? 3 : 1);
291 $parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
292 //Scan chunks looking for palette, transparency and image data
293 $pal = '';
294 $trns = '';
295 $data = '';
296 $icc = false;
297 do {
299 $type = fread($f, 4);
300 if ($type == 'PLTE') {
301 // read palette
302 $pal = TCPDF_STATIC::rfread($f, $n);
303 fread($f, 4);
304 } elseif ($type == 'tRNS') {
305 // read transparency info
307 if ($ct == 0) {
308 $trns = array(ord($t{1}));
309 } elseif ($ct == 2) {
310 $trns = array(ord($t{1}), ord($t{3}), ord($t{5}));
311 } else {
312 $pos = strpos($t, chr(0));
313 if ($pos !== false) {
314 $trns = array($pos);
315 }
316 }
317 fread($f, 4);
318 } elseif ($type == 'IDAT') {
319 // read image data block
321 fread($f, 4);
322 } elseif ($type == 'iCCP') {
323 // skip profile name
324 $len = 0;
325 while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
326 ++$len;
327 }
328 // skip null separator
329 fread($f, 1);
330 // get compression method
331 if (ord(fread($f, 1)) != 0) {
332 // Unknown filter method
333 fclose($f);
334 return false;
335 }
336 // read ICC Color Profile
337 $icc = TCPDF_STATIC::rfread($f, ($n - $len - 2));
338 // decompress profile
339 $icc = gzuncompress($icc);
340 fread($f, 4);
341 } elseif ($type == 'IEND') {
342 break;
343 } else {
344 TCPDF_STATIC::rfread($f, $n + 4);
345 }
346 } while ($n);
347 if (($colspace == 'Indexed') AND (empty($pal))) {
348 // Missing palette
349 fclose($f);
350 return false;
351 }
352 fclose($f);
353 return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
354 }
$n
Definition: RandomTest.php:80
static _freadint($f)
Read a 4-byte (32 bit) integer from file.
static rfread($handle, $length)
Binary-safe and URL-safe file read.

References $data, $file, $n, $t, TCPDF_STATIC\_freadint(), and TCPDF_STATIC\rfread().

Referenced by _toPNG().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _toJPEG()

static TCPDF_IMAGES::_toJPEG (   $image,
  $quality 
)
static

Convert the loaded image to a JPEG and then return a structure for the PDF creator.

This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.

Parameters
$image(image) Image object.
$quality(int) JPEG quality. return image JPEG image object. static

Definition at line 146 of file tcpdf_images.php.

146 {
147 $tempname = TCPDF_STATIC::getObjFilename('jpg');
148 imagejpeg($image, $tempname, $quality);
149 imagedestroy($image);
150 $retvars = self::_parsejpeg($tempname);
151 // tidy up by removing temporary image
152 unlink($tempname);
153 return $retvars;
154 }
static _parsejpeg($file)
Extract info from a JPEG file without using the GD library.
static getObjFilename($name)
Returns a temporary filename for caching object on filesystem.

References _parsejpeg(), and TCPDF_STATIC\getObjFilename().

Referenced by TCPDF\Image().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _toPNG()

static TCPDF_IMAGES::_toPNG (   $image)
static

Convert the loaded image to a PNG and then return a structure for the PDF creator.

This function requires GD library and write access to the directory defined on K_PATH_CACHE constant.

Parameters
$image(image) Image object. return image PNG image object.
Since
4.9.016 (2010-04-20) static

Definition at line 122 of file tcpdf_images.php.

122 {
123 // set temporary image file name
124 $tempname = TCPDF_STATIC::getObjFilename('png');
125 // turn off interlaced mode
126 imageinterlace($image, 0);
127 // create temporary PNG image
128 imagepng($image, $tempname);
129 // remove image from memory
130 imagedestroy($image);
131 // get PNG image data
132 $retvars = self::_parsepng($tempname);
133 // tidy up by removing temporary image
134 unlink($tempname);
135 return $retvars;
136 }
static _parsepng($file)
Extract info from a PNG file without using the GD library.

References _parsepng(), and TCPDF_STATIC\getObjFilename().

Referenced by TCPDF\Image().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageFileType()

static TCPDF_IMAGES::getImageFileType (   $imgfile,
  $iminfo = array() 
)
static

Return the image type given the file name or array returned by getimagesize() function.

Parameters
$imgfile(string) image file name
$iminfo(array) array of image information returned by getimagesize() function.
Returns
string image type
Since
4.8.017 (2009-11-27) static

Definition at line 71 of file tcpdf_images.php.

71 {
72 $type = '';
73 if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
74 $mime = explode('/', $iminfo['mime']);
75 if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
76 $type = strtolower(trim($mime[1]));
77 }
78 }
79 if (empty($type)) {
80 $fileinfo = pathinfo($imgfile);
81 if (isset($fileinfo['extension']) AND (!TCPDF_STATIC::empty_string($fileinfo['extension']))) {
82 $type = strtolower(trim($fileinfo['extension']));
83 }
84 }
85 if ($type == 'jpg') {
86 $type = 'jpeg';
87 }
88 return $type;
89 }
static empty_string($str)
Determine whether a string is empty.

References TCPDF_STATIC\empty_string().

Referenced by TCPDF\Header(), TCPDF\Image(), TCPDF\openHTMLTagHandler(), and TCPDF\startSVGElementHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setGDImageTransparency()

static TCPDF_IMAGES::setGDImageTransparency (   $new_image,
  $image 
)
static

Set the transparency for the given GD image.

Parameters
$new_image(image) GD image object
$image(image) GD image object. return GD image object.
Since
4.9.016 (2010-04-20) static

Definition at line 99 of file tcpdf_images.php.

99 {
100 // transparency index
101 $tid = imagecolortransparent($image);
102 // default transparency color
103 $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
104 if ($tid >= 0) {
105 // get the colors for the transparency index
106 $tcol = imagecolorsforindex($image, $tid);
107 }
108 $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
109 imagefill($new_image, 0, 0, $tid);
110 imagecolortransparent($new_image, $tid);
111 return $new_image;
112 }

Referenced by TCPDF\Image().

+ Here is the caller graph for this function:

Field Documentation

◆ $svginheritprop

TCPDF_IMAGES::$svginheritprop = array('clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cursor', 'direction', 'fill', 'fill-opacity', 'fill-rule', 'font', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'image-rendering', 'kerning', 'letter-spacing', 'marker', 'marker-end', 'marker-mid', 'marker-start', 'pointer-events', 'shape-rendering', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-rendering', 'visibility', 'word-spacing', 'writing-mode')
static

Array of hinheritable SVG properties.

Since
5.0.000 (2010-05-02) static

Definition at line 59 of file tcpdf_images.php.

Referenced by TCPDF\startSVGElementHandler().


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