Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/PhpWord/Element/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/PhpWord/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down