Skip to content

Commit 365ce26

Browse files
committed
Backport PHPOffice#779
1 parent 74f924e commit 365ce26

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/PhpWord/Element/Image.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ public function getImageStringData($base64 = false)
336336
// Read image binary data and convert to hex/base64 string
337337
if ($this->sourceType == self::SOURCE_GD) {
338338
$imageResource = call_user_func($this->imageCreateFunc, $actualSource);
339+
if ($this->imageType === 'image/png') {
340+
// PNG images need to preserve alpha channel information
341+
imagesavealpha($imageResource, true);
342+
}
339343
ob_start();
340344
call_user_func($this->imageFunc, $imageResource);
341345
$imageBinary = ob_get_contents();

src/PhpWord/Writer/AbstractWriter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ protected function addFilesToPackage(ZipArchive $zip, $elements)
360360
// Retrive GD image content or get local media
361361
if (isset($element['isMemImage']) && $element['isMemImage']) {
362362
$image = call_user_func($element['createFunction'], $element['source']);
363+
if ($this->imageType === 'image/png') {
364+
// PNG images need to preserve alpha channel information
365+
imagesavealpha($imageResource, true);
366+
}
363367
ob_start();
364368
call_user_func($element['imageFunction'], $image);
365369
$imageContents = ob_get_contents();

0 commit comments

Comments
 (0)