From af7f105c46b911a3e97a27ff2fb099eca2daa6e8 Mon Sep 17 00:00:00 2001 From: nicolaasuni Date: Fri, 25 Feb 2011 10:22:22 +0100 Subject: [PATCH] 5.9.058 --- CHANGELOG.TXT | 3 +++ README.TXT | 4 ++-- tcpdf.php | 61 +++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 86c3ab9..d85ce87 100755 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -1,3 +1,6 @@ +5.9.058 (2011-02-25) + - Image() method was improved to cache images with transparency layers (thanks to Korneliusz Jarzębski for reporting this problem). + 5.9.057 (2011-02-24) - A problem with image caching system was fixed (thanks to Korneliusz Jarzębski for reporting this problem). diff --git a/README.TXT b/README.TXT index 3b45472..30a7cde 100755 --- a/README.TXT +++ b/README.TXT @@ -8,8 +8,8 @@ http://sourceforge.net/donate/index.php?group_id=128076 ------------------------------------------------------------ Name: TCPDF -Version: 5.9.057 -Release date: 2011-02-24 +Version: 5.9.058 +Release date: 2011-02-25 Author: Nicola Asuni Copyright (c) 2002-2011: diff --git a/tcpdf.php b/tcpdf.php index bb66143..57b4e8f 100755 --- a/tcpdf.php +++ b/tcpdf.php @@ -1,9 +1,9 @@ * @package com.tecnick.tcpdf * @author Nicola Asuni - * @version 5.9.057 + * @version 5.9.058 */ // Main configuration file. Define the K_TCPDF_EXTERNAL_CONFIG constant to skip this file. @@ -146,7 +146,7 @@ require_once(dirname(__FILE__).'/config/tcpdf_config.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 5.9.057 + * @version 5.9.058 * @author Nicola Asuni - info@tecnick.com */ class TCPDF { @@ -157,7 +157,7 @@ class TCPDF { * Current TCPDF version. * @private */ - private $tcpdf_version = '5.9.057'; + private $tcpdf_version = '5.9.058'; // Protected properties @@ -7237,7 +7237,14 @@ class TCPDF { } } if ($imsize === FALSE) { - $this->Error('[Image] Unable to get image: '.$file); + if (substr($file, 0, -34) == K_PATH_CACHE.'msk') { // mask file + // get measures from specified data + $pw = $this->getHTMLUnitToUnits($w, 0, $this->pdfunit, true) * $this->imgscale * $this->k; + $ph = $this->getHTMLUnitToUnits($h, 0, $this->pdfunit, true) * $this->imgscale * $this->k; + $imsize = array($pw, $ph); + } else { + $this->Error('[Image] Unable to get image: '.$file); + } } // get original image width and height in pixels list($pixw, $pixh) = $imsize; @@ -7328,10 +7335,32 @@ class TCPDF { $newimage = false; // get existing image data $info = $this->getImageBuffer($file); - // check if the newer image is larger - $oldsize = ($info['w'] * $info['h']); - if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) { - $newimage = true; + if (substr($file, 0, -34) != K_PATH_CACHE.'msk') { + // check if the newer image is larger + $oldsize = ($info['w'] * $info['h']); + if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) { + $newimage = true; + } + } + } elseif (substr($file, 0, -34) != K_PATH_CACHE.'msk') { + // check for cached images with alpha channel + $filehash = md5($file); + $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash; + $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash; + if (in_array($tempfile_plain, $this->imagekeys)) { + // get existing image data + $info = $this->getImageBuffer($tempfile_plain); + // check if the newer image is larger + $oldsize = ($info['w'] * $info['h']); + if ((($oldsize < $newsize) AND ($resize)) OR (($oldsize < $pixsize) AND (!$resize))) { + $newimage = true; + } else { + $newimage = false; + // embed mask image + $imgmask = $this->Image($tempfile_alpha, $x, $y, $w, $h, 'PNG', '', '', $resize, $dpi, '', true, false); + // embed image, masked with previously embedded mask + return $this->Image($tempfile_plain, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, false, $imgmask); + } } } if ($newimage) { @@ -7353,7 +7382,7 @@ class TCPDF { // TCPDF image functions $info = $this->$mtd($file); if ($info == 'pngalpha') { - return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign); + return $this->ImagePngAlpha($file, $x, $y, $pixw, $pixh, $w, $h, 'PNG', $link, $align, $resize, $dpi, $palign, $filehash); } } if (!$info) { @@ -7793,16 +7822,20 @@ class TCPDF { * @param $resize (boolean) If true resize (reduce) the image to fit $w and $h (requires GD library). * @param $dpi (int) dot-per-inch resolution used on resize * @param $palign (string) Allows to center or align the image on the current line. Possible values are: + * @param $filehash (string) File hash used to build unique file names. * @author Nicola Asuni * @protected * @since 4.3.007 (2008-12-04) * @see Image() */ - protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign) { + protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $filehash='') { + if (empty($filehash)) { + $filehash = md5($file); + } // create temp image file (without alpha channel) - $tempfile_plain = K_PATH_CACHE.'mskp_'.md5($file); + $tempfile_plain = K_PATH_CACHE.'mskp_'.$filehash; // create temp alpha file - $tempfile_alpha = K_PATH_CACHE.'mska_'.md5($file); + $tempfile_alpha = K_PATH_CACHE.'mska_'.$filehash; if (extension_loaded('imagick')) { // ImageMagick // ImageMagick library $img = new Imagick();