From ba20cfd66c88cff004f7883e24793a0e43bb98f8 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 25 Oct 2013 21:33:23 +0000 Subject: [PATCH] Don't process alpha channel of PNG images --- include/mpdf/config.php | 4 ++++ include/mpdf/mpdf.php | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/mpdf/config.php b/include/mpdf/config.php index 79d6ce491..55c64b648 100755 --- a/include/mpdf/config.php +++ b/include/mpdf/config.php @@ -568,5 +568,9 @@ $this->outerblocktags = array('DIV','FORM','CENTER','DL','FIELDSET','ARTICLE','A $this->innerblocktags = array('P','BLOCKQUOTE','ADDRESS','PRE','H1','H2','H3','H4','H5','H6','DT','DD','CAPTION'); +// OSTICKET CUSTOM ------------------------------- +// Don't process alpha channels of PNG images +$this->png_alpha_use_white_matte = true; + ?> diff --git a/include/mpdf/mpdf.php b/include/mpdf/mpdf.php index b2a28b06b..91d310dda 100755 --- a/include/mpdf/mpdf.php +++ b/include/mpdf/mpdf.php @@ -9859,7 +9859,23 @@ function _getImage(&$file, $firsttime=true, $allowvector=true, $orig_srcpath=fal if ($im) { $tempfile = _MPDF_TEMP_PATH.'_tempImgPNG'.RAND(1,10000).'.png'; // Alpha channel set - if ($pngalpha) { + if ($pngalpha && $this->png_alpha_use_white_matte) { + $imgmat = imagecreatetruecolor($w, $h); + imagesavealpha($imgmat, false); + imageinterlace($imgmat, false); + imagefill($imgmat, 0, 0, imagecolorallocate($imgmat, 255, 255, 255)); + imagecopy($imgmat, $im, 0, 0, 0, 0, $w, $h); + ob_start(); + $check = @imagepng($imgmat); + if (!$check) { return $this->_imageError($file, $firsttime, 'Error creating temporary image object whilst using GD library to parse PNG image'); } + $this->_tempimg = ob_get_contents(); + $this->_tempimglnk = 'var:_tempimg'; + ob_end_clean(); + $info = $this->_getImage($this->_tempimglnk, false); + if (!$info) { return $this->_imageError($file, $firsttime, 'Error parsing temporary file image object created with GD library to parse PNG image'); } + imagedestroy($imgmat); + } + elseif ($pngalpha) { if ($this->PDFA) { $this->Error("PDFA1-b does not permit images with alpha channel transparency (".$file.")."); } $imgalpha = imagecreate($w, $h); // generate gray scale pallete -- GitLab