ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
static setGDImageTransparency ($new_image, $image)
 Set the transparency for the given GD image.
static _toPNG ($image)
 Convert the loaded image to a PNG and then return a structure for the PDF creator.
static _toJPEG ($image, $quality)
 Convert the loaded image to a JPEG and then return a structure for the PDF creator.
static _parsejpeg ($file)
 Extract info from a JPEG file without using the GD library.
static _parsepng ($file)
 Extract info from a PNG file without using the GD library.

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.

Detailed Description

Static image methods used by the TCPDF class.

Definition at line 52 of file tcpdf_images.php.

Member Function Documentation

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.

References $file, and TCPDF_STATIC\_getUSHORT().

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

{
$a = getimagesize($file);
if (empty($a)) {
//Missing or incorrect image file
return false;
}
if ($a[2] != 2) {
// Not a JPEG file
return false;
}
// bits per pixel
$bpc = isset($a['bits']) ? intval($a['bits']) : 8;
// number of image channels
if (!isset($a['channels'])) {
$channels = 3;
} else {
$channels = intval($a['channels']);
}
// default colour space
switch ($channels) {
case 1: {
$colspace = 'DeviceGray';
break;
}
case 3: {
$colspace = 'DeviceRGB';
break;
}
case 4: {
$colspace = 'DeviceCMYK';
break;
}
default: {
$channels = 3;
$colspace = 'DeviceRGB';
break;
}
}
// get file content
$data = file_get_contents($file);
// check for embedded ICC profile
$icc = array();
$offset = 0;
while (($pos = strpos($data, "ICC_PROFILE\0", $offset)) !== false) {
// get ICC sequence length
$length = (TCPDF_STATIC::_getUSHORT($data, ($pos - 2)) - 16);
// marker sequence number
$msn = max(1, ord($data[($pos + 12)]));
// number of markers (total of APP2 used)
$nom = max(1, ord($data[($pos + 13)]));
// get sequence segment
$icc[($msn - 1)] = substr($data, ($pos + 14), $length);
// move forward to next sequence
$offset = ($pos + 14 + $length);
}
// order and compact ICC segments
if (count($icc) > 0) {
ksort($icc);
$icc = implode('', $icc);
if ((ord($icc{36}) != 0x61) OR (ord($icc{37}) != 0x63) OR (ord($icc{38}) != 0x73) OR (ord($icc{39}) != 0x70)) {
// invalid ICC profile
$icc = false;
}
} else {
$icc = false;
}
return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

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

Referenced by _toPNG().

{
$f = fopen($file, 'rb');
if ($f === false) {
// Can't open image file
return false;
}
//Check signature
if (fread($f, 8) != chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) {
// Not a PNG file
return false;
}
//Read header chunk
fread($f, 4);
if (fread($f, 4) != 'IHDR') {
//Incorrect PNG file
return false;
}
$bpc = ord(fread($f, 1));
if ($bpc > 8) {
// 16-bit depth not supported
fclose($f);
return false;
}
$ct = ord(fread($f, 1));
if ($ct == 0) {
$colspace = 'DeviceGray';
} elseif ($ct == 2) {
$colspace = 'DeviceRGB';
} elseif ($ct == 3) {
$colspace = 'Indexed';
} else {
// alpha channel
fclose($f);
return 'pngalpha';
}
if (ord(fread($f, 1)) != 0) {
// Unknown compression method
fclose($f);
return false;
}
if (ord(fread($f, 1)) != 0) {
// Unknown filter method
fclose($f);
return false;
}
if (ord(fread($f, 1)) != 0) {
// Interlacing not supported
fclose($f);
return false;
}
fread($f, 4);
$channels = ($ct == 2 ? 3 : 1);
$parms = '/DecodeParms << /Predictor 15 /Colors '.$channels.' /BitsPerComponent '.$bpc.' /Columns '.$w.' >>';
//Scan chunks looking for palette, transparency and image data
$pal = '';
$trns = '';
$data = '';
$icc = false;
do {
$type = fread($f, 4);
if ($type == 'PLTE') {
// read palette
$pal = TCPDF_STATIC::rfread($f, $n);
fread($f, 4);
} elseif ($type == 'tRNS') {
// read transparency info
if ($ct == 0) {
$trns = array(ord($t{1}));
} elseif ($ct == 2) {
$trns = array(ord($t{1}), ord($t{3}), ord($t{5}));
} else {
$pos = strpos($t, chr(0));
if ($pos !== false) {
$trns = array($pos);
}
}
fread($f, 4);
} elseif ($type == 'IDAT') {
// read image data block
$data .= TCPDF_STATIC::rfread($f, $n);
fread($f, 4);
} elseif ($type == 'iCCP') {
// skip profile name
$len = 0;
while ((ord(fread($f, 1)) > 0) AND ($len < 80)) {
++$len;
}
// skip null separator
fread($f, 1);
// get compression method
if (ord(fread($f, 1)) != 0) {
// Unknown filter method
fclose($f);
return false;
}
// read ICC Color Profile
$icc = TCPDF_STATIC::rfread($f, ($n - $len - 2));
// decompress profile
$icc = gzuncompress($icc);
fread($f, 4);
} elseif ($type == 'IEND') {
break;
} else {
}
} while ($n);
if (($colspace == 'Indexed') AND (empty($pal))) {
// Missing palette
fclose($f);
return false;
}
fclose($f);
return array('w' => $w, 'h' => $h, 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

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

Referenced by TCPDF\Image().

{
$tempname = TCPDF_STATIC::getObjFilename('jpg');
imagejpeg($image, $tempname, $quality);
imagedestroy($image);
$retvars = self::_parsejpeg($tempname);
// tidy up by removing temporary image
unlink($tempname);
return $retvars;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

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

Referenced by TCPDF\Image().

{
// set temporary image file name
$tempname = TCPDF_STATIC::getObjFilename('png');
// turn off interlaced mode
imageinterlace($image, 0);
// create temporary PNG image
imagepng($image, $tempname);
// remove image from memory
imagedestroy($image);
// get PNG image data
$retvars = self::_parsepng($tempname);
// tidy up by removing temporary image
unlink($tempname);
return $retvars;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References TCPDF_STATIC\empty_string().

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

{
$type = '';
if (isset($iminfo['mime']) AND !empty($iminfo['mime'])) {
$mime = explode('/', $iminfo['mime']);
if ((count($mime) > 1) AND ($mime[0] == 'image') AND (!empty($mime[1]))) {
$type = strtolower(trim($mime[1]));
}
}
if (empty($type)) {
$fileinfo = pathinfo($imgfile);
if (isset($fileinfo['extension']) AND (!TCPDF_STATIC::empty_string($fileinfo['extension']))) {
$type = strtolower(trim($fileinfo['extension']));
}
}
if ($type == 'jpg') {
$type = 'jpeg';
}
return $type;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Referenced by TCPDF\Image().

{
// transparency index
$tid = imagecolortransparent($image);
// default transparency color
$tcol = array('red' => 255, 'green' => 255, 'blue' => 255);
if ($tid >= 0) {
// get the colors for the transparency index
$tcol = imagecolorsforindex($image, $tid);
}
$tid = imagecolorallocate($new_image, $tcol['red'], $tcol['green'], $tcol['blue']);
imagefill($new_image, 0, 0, $tid);
imagecolortransparent($new_image, $tid);
return $new_image;
}

+ Here is the caller graph for this function:

Field Documentation

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: