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

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 245 of file tcpdf_images.php.

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

References $data, $file, $h, $n, $t, $w, 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,
  $tempfile 
)
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.
$tempfile(string) Temporary file name. return image JPEG image object. static

Definition at line 147 of file tcpdf_images.php.

147 {
148 imagejpeg($image, $tempfile, $quality);
149 imagedestroy($image);
150 $retvars = self::_parsejpeg($tempfile);
151 // tidy up by removing temporary image
152 unlink($tempfile);
153 return $retvars;
154 }
static _parsejpeg($file)
Extract info from a JPEG file without using the GD library.

References _parsejpeg().

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,
  $tempfile 
)
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.
$tempfile(string) Temporary file name. return image PNG image object.
Since
4.9.016 (2010-04-20) static

Definition at line 124 of file tcpdf_images.php.

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

References _parsepng().

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 // default transparency color (white)
101 $tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
102 // transparency index
103 $tid = imagecolortransparent($image);
104 $palletsize = imagecolorstotal($image);
105 if (($tid >= 0) AND ($tid < $palletsize)) {
106 // get the colors for the transparency index
107 $tcol = imagecolorsforindex($image, $tid);
108 }
109 $tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
110 imagefill($new_image, 0, 0, $tid);
111 imagecolortransparent($new_image, $tid);
112 return $new_image;
113 }

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', 'display', '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: