diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 529f473..9b17617 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -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) - Bug #836 "Optional EOL marker before endstream" was fixed. - Some additional controls were added to avoid "division by zero" error with badly formatted input. diff --git a/README.TXT b/README.TXT index 98b9c25..3c470cb 100644 --- a/README.TXT +++ b/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 6.0.031 -Release date: 2013-09-18 +Version: 6.0.032 +Release date: 2013-09-23 Author: Nicola Asuni 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). Link : http://projects.arabeyes.org/ + ============================================================ diff --git a/composer.json b/composer.json index 2f745dd..96ab866 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tecnick.com/tcpdf", - "version": "6.0.031", + "version": "6.0.032", "homepage": "http://www.tcpdf.org/", "type": "library", "description": "TCPDF is a PHP class for generating PDF documents.", diff --git a/include/tcpdf_static.php b/include/tcpdf_static.php index a6fa611..d2067e9 100644 --- a/include/tcpdf_static.php +++ b/include/tcpdf_static.php @@ -55,7 +55,7 @@ class TCPDF_STATIC { * Current TCPDF version. * @private static */ - private static $tcpdf_version = '6.0.031'; + private static $tcpdf_version = '6.0.032'; /** * String alias for total number of pages. diff --git a/tcpdf.php b/tcpdf.php index de552bc..b33a1a1 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -1,9 +1,9 @@ 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. +// * PDF/A-1b support //============================================================+ /** @@ -139,7 +104,7 @@ * Tools to encode your unicode fonts are on fonts/utils directory.

* @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 6.0.031 + * @version 6.0.032 */ // 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.
* @package com.tecnick.tcpdf * @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 */ 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); } } - if (!$info) { - if (function_exists($gdfunction)) { + if (($info === false) AND function_exists($gdfunction)) { + try { // GD library $img = $gdfunction($file); if ($resize) { @@ -7012,7 +6977,12 @@ class TCPDF { $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 $img = new Imagick(); if ($type == 'SVG') { @@ -7063,12 +7033,12 @@ class TCPDF { $info = TCPDF_IMAGES::_parsejpeg($tempname); unlink($tempname); $img->destroy(); - } else { - return; + } catch(Exception $e) { + $info = false; } } if ($info === false) { - //If false, we cannot process image + // unable to process image return; } TCPDF_STATIC::set_mqr($mqr); @@ -7199,54 +7169,76 @@ class TCPDF { $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash; // create temp alpha file $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash; - if (extension_loaded('imagick')) { // ImageMagick extension - // ImageMagick library - $img = new Imagick(); - $img->readImage($file); - // clone image object - $imga = TCPDF_STATIC::objclone($img); - // extract alpha channel - if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) { - $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT); - } else { - $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE); - $img->negateImage(true); - } - $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); - } 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); + $parsed = false; + $parse_error = ''; + // ImageMagick extension + if (($parsed === false) AND extension_loaded('imagick')) { + try { + // ImageMagick library + $img = new Imagick(); + $img->readImage($file); + // clone image object + $imga = TCPDF_STATIC::objclone($img); + // extract alpha channel + if (method_exists($img, 'setImageAlphaChannel') AND defined('Imagick::ALPHACHANNEL_EXTRACT')) { + $img->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT); + } else { + $img->separateImageChannel(8); // 8 = (imagick::CHANNEL_ALPHA | imagick::CHANNEL_OPACITY | imagick::CHANNEL_MATTE); + $img->negateImage(true); } + $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 $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false);