Skip to content

Commit 615edda

Browse files
committed
Add Image::hasAlpha method
1 parent 386d21b commit 615edda

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/Image.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public function save(?string $filename = null) : bool
338338
*/
339339
public function send() : bool
340340
{
341-
if (\in_array($this->getType(), [\IMAGETYPE_PNG, \IMAGETYPE_GIF, \IMAGETYPE_AVIF], true)) {
341+
if ($this->hasAlpha()) {
342342
\imagesavealpha($this->instance, true);
343343
}
344344
return match ($this->getType()) {
@@ -539,7 +539,7 @@ public function opacity(int $opacity = 100) : static
539539
*/
540540
public function rotate(float $angle) : static
541541
{
542-
if (\in_array($this->getType(), [\IMAGETYPE_PNG, \IMAGETYPE_GIF, \IMAGETYPE_AVIF], true)) {
542+
if ($this->hasAlpha()) {
543543
\imagealphablending($this->instance, false);
544544
\imagesavealpha($this->instance, true);
545545
$background = \imagecolorallocatealpha($this->instance, 0, 0, 0, 127);
@@ -557,6 +557,19 @@ public function rotate(float $angle) : static
557557
return $this;
558558
}
559559

560+
public function hasAlpha() : bool
561+
{
562+
return \in_array(
563+
$this->getType(),
564+
[
565+
\IMAGETYPE_PNG,
566+
\IMAGETYPE_GIF,
567+
\IMAGETYPE_AVIF,
568+
],
569+
true
570+
);
571+
}
572+
560573
/**
561574
* Scales the image.
562575
*

0 commit comments

Comments
 (0)