Skip to content

Commit fd127ef

Browse files
authored
Merge pull request #779 from samsullivan/imagesavealpha
Save PNG alpha information when using remote images.
2 parents cf6319d + f4ec74a commit fd127ef

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
@@ -334,6 +334,10 @@ public function getImageStringData($base64 = false)
334334
// Read image binary data and convert to hex/base64 string
335335
if ($this->sourceType == self::SOURCE_GD) {
336336
$imageResource = call_user_func($this->imageCreateFunc, $actualSource);
337+
if ($this->imageType === 'image/png') {
338+
// PNG images need to preserve alpha channel information
339+
imagesavealpha($imageResource, true);
340+
}
337341
ob_start();
338342
call_user_func($this->imageFunc, $imageResource);
339343
$imageBinary = ob_get_contents();

src/PhpWord/Writer/AbstractWriter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ protected function addFilesToPackage(ZipArchive $zip, $elements)
352352
// Retrive GD image content or get local media
353353
if (isset($element['isMemImage']) && $element['isMemImage']) {
354354
$image = call_user_func($element['createFunction'], $element['source']);
355+
if ($element['imageType'] === 'image/png') {
356+
// PNG images need to preserve alpha channel information
357+
imagesavealpha($image, true);
358+
}
355359
ob_start();
356360
call_user_func($element['imageFunction'], $image);
357361
$imageContents = ob_get_contents();

0 commit comments

Comments
 (0)