Skip to content

Commit

Permalink
Merge pull request #3692 from michalsn/fix/webp-transparent
Browse files Browse the repository at this point in the history
Fix transparency handling for webp
  • Loading branch information
MGatner authored Sep 28, 2020
2 parents e7bb006 + 25cb7b4 commit 9292923
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions system/Images/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ abstract class BaseHandler implements ImageHandlerInterface
'shadowOffset' => 3,
];

/**
* Image types with support for transparency.
*
* @var array
*/
protected $supportTransparency = [
IMAGETYPE_PNG,
IMAGETYPE_WEBP,
];

/**
* Temporary image used by the different engines.
*
Expand Down
3 changes: 2 additions & 1 deletion system/Images/Handlers/GDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ protected function process(string $action)

$dest = $create($this->width, $this->height);

if ($this->image()->imageType === IMAGETYPE_PNG) // png we can actually preserve transparency
// for png and webp we can actually preserve transparency
if (in_array($this->image()->imageType, $this->supportTransparency, true))
{
imagealphablending($dest, false);
imagesavealpha($dest, true);
Expand Down

0 comments on commit 9292923

Please sign in to comment.