Skip to content

Commit

Permalink
Add $supportTransparency class variable
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Sep 28, 2020
1 parent 0db24cb commit 25cb7b4
Show file tree
Hide file tree
Showing 2 changed files with 11 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
2 changes: 1 addition & 1 deletion system/Images/Handlers/GDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected function process(string $action)
$dest = $create($this->width, $this->height);

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

2 comments on commit 25cb7b4

@orionstar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVIF doesn't support transparency too?

@michalsn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVIF is not yet supported by GD.

Please sign in to comment.