From adfcc62e644f1fe6ce24f5392803cebdf9a02760 Mon Sep 17 00:00:00 2001 From: Sam Sullivan Date: Mon, 11 Apr 2016 12:48:43 -0500 Subject: [PATCH 1/2] imagesavealpha() in Writer\AbstractWriter --- src/PhpWord/Writer/AbstractWriter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 55b2023294..c6b64c280e 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -360,6 +360,10 @@ protected function addFilesToPackage(ZipArchive $zip, $elements) // Retrive GD image content or get local media if (isset($element['isMemImage']) && $element['isMemImage']) { $image = call_user_func($element['createFunction'], $element['source']); + if ($element['imageType'] === 'image/png') { + // PNG images need to preserve alpha channel information + imagesavealpha($image, true); + } ob_start(); call_user_func($element['imageFunction'], $image); $imageContents = ob_get_contents(); From f4ec74a4c5338f1df4a3dbb58a19b946ab627005 Mon Sep 17 00:00:00 2001 From: Sam Sullivan Date: Mon, 11 Apr 2016 12:49:18 -0500 Subject: [PATCH 2/2] imagesavealpha() in Element\Image --- src/PhpWord/Element/Image.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php index f5cc7ccccf..64ddfd86ed 100644 --- a/src/PhpWord/Element/Image.php +++ b/src/PhpWord/Element/Image.php @@ -335,6 +335,10 @@ public function getImageStringData($base64 = false) // Read image binary data and convert to hex/base64 string if ($this->sourceType == self::SOURCE_GD) { $imageResource = call_user_func($this->imageCreateFunc, $actualSource); + if ($this->imageType === 'image/png') { + // PNG images need to preserve alpha channel information + imagesavealpha($imageResource, true); + } ob_start(); call_user_func($this->imageFunc, $imageResource); $imageBinary = ob_get_contents();