30
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-06-05 15:20:49 +00:00

6.0.032 (2013-09-23)

- Bug #838 "Fatal error when imagick cannot handle the image, even though GD is available and can" was fixed.
This commit is contained in:
nicolaasuni 2013-09-23 10:22:53 +01:00
parent 0c26f23abf
commit 940dc4b24a
5 changed files with 92 additions and 96 deletions

View File

@ -1,3 +1,6 @@
6.0.032 (2013-09-23)
- Bug #838 "Fatal error when imagick cannot handle the image, even though GD is available and can" was fixed.
6.0.031 (2013-09-18) 6.0.031 (2013-09-18)
- Bug #836 "Optional EOL marker before endstream" was fixed. - Bug #836 "Optional EOL marker before endstream" was fixed.
- Some additional controls were added to avoid "division by zero" error with badly formatted input. - Some additional controls were added to avoid "division by zero" error with badly formatted input.

View File

@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076
------------------------------------------------------------ ------------------------------------------------------------
Name: TCPDF Name: TCPDF
Version: 6.0.031 Version: 6.0.032
Release date: 2013-09-18 Release date: 2013-09-23
Author: Nicola Asuni Author: Nicola Asuni
Copyright (c) 2002-2013: Copyright (c) 2002-2013:
@ -107,4 +107,5 @@ Third party fonts:
The binary files (.z) that begins with the prefix "ae" have been extracted from the Arabeyes.org collection (GNU-GPLv2). The binary files (.z) that begins with the prefix "ae" have been extracted from the Arabeyes.org collection (GNU-GPLv2).
Link : http://projects.arabeyes.org/ Link : http://projects.arabeyes.org/
============================================================ ============================================================

View File

@ -1,6 +1,6 @@
{ {
"name": "tecnick.com/tcpdf", "name": "tecnick.com/tcpdf",
"version": "6.0.031", "version": "6.0.032",
"homepage": "http://www.tcpdf.org/", "homepage": "http://www.tcpdf.org/",
"type": "library", "type": "library",
"description": "TCPDF is a PHP class for generating PDF documents.", "description": "TCPDF is a PHP class for generating PDF documents.",

View File

@ -55,7 +55,7 @@ class TCPDF_STATIC {
* Current TCPDF version. * Current TCPDF version.
* @private static * @private static
*/ */
private static $tcpdf_version = '6.0.031'; private static $tcpdf_version = '6.0.032';
/** /**
* String alias for total number of pages. * String alias for total number of pages.

176
tcpdf.php
View File

@ -1,9 +1,9 @@
<?php <?php
//============================================================+ //============================================================+
// File name : tcpdf.php // File name : tcpdf.php
// Version : 6.0.031 // Version : 6.0.032
// Begin : 2002-08-03 // Begin : 2002-08-03
// Last Update : 2013-09-15 // Last Update : 2013-09-23
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html) // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -64,42 +64,7 @@
// * page compression (requires php-zlib extension); // * page compression (requires php-zlib extension);
// * XOBject Templates; // * XOBject Templates;
// * Layers and object visibility. // * Layers and object visibility.
// * PDF/A-1b support. // * PDF/A-1b support
//
// -----------------------------------------------------------
// THANKS TO:
//
// Olivier Plathey (http://www.fpdf.org) for original FPDF.
// Efthimios Mavrogeorgiadis (emavro@yahoo.com) for suggestions on RTL language support.
// Klemen Vodopivec (http://www.fpdf.de/downloads/addons/37/) for Encryption algorithm.
// Warren Sherliker (wsherliker@gmail.com) for better image handling.
// dullus for text Justification.
// Bob Vincent (pillarsdotnet@users.sourceforge.net) for <li> value attribute.
// Patrick Benny for text stretch suggestion on Cell().
// Johannes Güntert for JavaScript support.
// Denis Van Nuffelen for Dynamic Form.
// Jacek Czekaj for multibyte justification
// Anthony Ferrara for the reintroduction of legacy image methods.
// Sourceforge user 1707880 (hucste) for line-through mode.
// Larry Stanbery for page groups.
// Martin Hall-May for transparency.
// Aaron C. Spike for Polycurve method.
// Mohamad Ali Golkar, Saleh AlMatrafe, Charles Abbott for Arabic and Persian support.
// Moritz Wagner and Andreas Wurmser for graphic functions.
// Andrew Whitehead for core fonts support.
// Esteban Joël Marín for OpenType font conversion.
// Teus Hagen for several suggestions and fixes.
// Yukihiro Nakadaira for CID-0 CJK fonts fixes.
// Kosmas Papachristos for some CSS improvements.
// Marcel Partap for some fixes.
// Won Kyu Park for several suggestions, fixes and patches.
// Dominik Dzienia for QR-code support.
// Laurent Minguet for some suggestions.
// Christian Deligant for some suggestions and fixes.
// Travis Harris for crop mark suggestion.
// Aleksey Kuznetsov for some suggestions and text shadows.
// Jim Hanlon for several suggestions and patches.
// Anyone else that has reported a bug or sent a suggestion.
//============================================================+ //============================================================+
/** /**
@ -139,7 +104,7 @@
* Tools to encode your unicode fonts are on fonts/utils directory.</p> * Tools to encode your unicode fonts are on fonts/utils directory.</p>
* @package com.tecnick.tcpdf * @package com.tecnick.tcpdf
* @author Nicola Asuni * @author Nicola Asuni
* @version 6.0.031 * @version 6.0.032
*/ */
// TCPDF configuration // TCPDF configuration
@ -163,7 +128,7 @@ require_once(dirname(__FILE__).'/include/tcpdf_static.php');
* TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br> * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
* @package com.tecnick.tcpdf * @package com.tecnick.tcpdf
* @brief PHP class for generating PDF documents without requiring external extensions. * @brief PHP class for generating PDF documents without requiring external extensions.
* @version 6.0.031 * @version 6.0.032
* @author Nicola Asuni - info@tecnick.com * @author Nicola Asuni - info@tecnick.com
*/ */
class TCPDF { class TCPDF {
@ -6990,8 +6955,8 @@ class TCPDF {
return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash); return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash);
} }
} }
if (!$info) { if (($info === false) AND function_exists($gdfunction)) {
if (function_exists($gdfunction)) { try {
// GD library // GD library
$img = $gdfunction($file); $img = $gdfunction($file);
if ($resize) { if ($resize) {
@ -7012,7 +6977,12 @@ class TCPDF {
$info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality); $info = TCPDF_IMAGES::_toJPEG($img, $this->jpeg_quality);
} }
} }
} elseif (extension_loaded('imagick')) { } catch(Exception $e) {
$info = false;
}
}
if (($info === false) AND extension_loaded('imagick')) {
try {
// ImageMagick library // ImageMagick library
$img = new Imagick(); $img = new Imagick();
if ($type == 'SVG') { if ($type == 'SVG') {
@ -7063,12 +7033,12 @@ class TCPDF {
$info = TCPDF_IMAGES::_parsejpeg($tempname); $info = TCPDF_IMAGES::_parsejpeg($tempname);
unlink($tempname); unlink($tempname);
$img->destroy(); $img->destroy();
} else { } catch(Exception $e) {
return; $info = false;
} }
} }
if ($info === false) { if ($info === false) {
//If false, we cannot process image // unable to process image
return; return;
} }
TCPDF_STATIC::set_mqr($mqr); TCPDF_STATIC::set_mqr($mqr);
@ -7199,54 +7169,76 @@ class TCPDF {
$tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash; $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash;
// create temp alpha file // create temp alpha file
$tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash; $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash;
if (extension_loaded('imagick')) { // ImageMagick extension $parsed = false;
// ImageMagick library $parse_error = '';
$img = new Imagick(); // ImageMagick extension
$img->readImage($file); if (($parsed === false) AND extension_loaded('imagick')) {
// clone image object try {
$imga = TCPDF_STATIC::objclone($img); // ImageMagick library
// extract alpha channel $img = new Imagick();
if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) { $img->readImage($file);
$img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT); // clone image object
} else { $imga = TCPDF_STATIC::objclone($img);
$img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE); // extract alpha channel
$img->negateImage(true); if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) {
} $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
$img->setImageFormat('png'); } else {
$img->writeImage($tempfile_alpha); $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE);
// remove alpha channel $img->negateImage(true);
if (method_exists($imga, 'setImageMatte')) {
$imga->setImageMatte(false);
} else {
$imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
}
$imga->setImageFormat('png');
$imga->writeImage($tempfile_plain);
} elseif (function_exists('imagecreatefrompng')) { // GD extension
// generate images
$img = imagecreatefrompng($file);
$imgalpha = imagecreate($wpx, $hpx);
// generate gray scale palette (0 -> 255)
for ($c = 0; $c < 256; ++$c) {
ImageColorAllocate($imgalpha, $c, $c, $c);
}
// extract alpha channel
for ($xpx = 0; $xpx < $wpx; ++$xpx) {
for ($ypx = 0; $ypx < $hpx; ++$ypx) {
$color = imagecolorat($img, $xpx, $ypx);
$alpha = $this->getGDgamma($color); // correct gamma
imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
} }
$img->setImageFormat('png');
$img->writeImage($tempfile_alpha);
// remove alpha channel
if (method_exists($imga, 'setImageMatte')) {
$imga->setImageMatte(false);
} else {
$imga->separateImageChannel(39); // 39 = (imagick::CHANNEL_ALL & ~(imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE));
}
$imga->setImageFormat('png');
$imga->writeImage($tempfile_plain);
$parsed = true;
} catch (Exception $e) {
// Imagemagick fails, try with GD
$parse_error = 'Imagick library error: '.$e->getMessage();
}
}
// GD extension
if (($parsed === false) AND function_exists('imagecreatefrompng')) {
try {
// generate images
$img = imagecreatefrompng($file);
$imgalpha = imagecreate($wpx, $hpx);
// generate gray scale palette (0 -> 255)
for ($c = 0; $c < 256; ++$c) {
ImageColorAllocate($imgalpha, $c, $c, $c);
}
// extract alpha channel
for ($xpx = 0; $xpx < $wpx; ++$xpx) {
for ($ypx = 0; $ypx < $hpx; ++$ypx) {
$color = imagecolorat($img, $xpx, $ypx);
$alpha = $this->getGDgamma($color); // correct gamma
imagesetpixel($imgalpha, $xpx, $ypx, $alpha);
}
}
imagepng($imgalpha, $tempfile_alpha);
imagedestroy($imgalpha);
// extract image without alpha channel
$imgplain = imagecreatetruecolor($wpx, $hpx);
imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
imagepng($imgplain, $tempfile_plain);
imagedestroy($imgplain);
$parsed = true;
} catch (Exception $e) {
// GD fails
$parse_error = 'GD library error: '.$e->getMessage();
}
}
if ($parsed === false) {
if (empty($parse_error)) {
$this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
} else {
$this->Error($parse_error);
} }
imagepng($imgalpha, $tempfile_alpha);
imagedestroy($imgalpha);
// extract image without alpha channel
$imgplain = imagecreatetruecolor($wpx, $hpx);
imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
imagepng($imgplain, $tempfile_plain);
imagedestroy($imgplain);
} else {
$this->Error('TCPDF requires the Imagick or GD extension to handle PNG images with alpha channel.');
} }
// embed mask image // embed mask image
$imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false); $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);