Skip to content

Commit bab8f7c

Browse files
committed
Add method to allocate background
1 parent 615edda commit bab8f7c

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

phpmd.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset name="Mess Detector">
33
<!-- cleancode -->
4-
<rule ref="rulesets/cleancode.xml">
5-
<exclude name="ElseExpression"/>
6-
</rule>
4+
<rule ref="rulesets/cleancode.xml"/>
75
<!-- codesize -->
86
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
97
<properties>

src/Image.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,7 @@ public function opacity(int $opacity = 100) : static
539539
*/
540540
public function rotate(float $angle) : static
541541
{
542-
if ($this->hasAlpha()) {
543-
\imagealphablending($this->instance, false);
544-
\imagesavealpha($this->instance, true);
545-
$background = \imagecolorallocatealpha($this->instance, 0, 0, 0, 127);
546-
} else {
547-
$background = \imagecolorallocate($this->instance, 255, 255, 255);
548-
}
542+
$background = $this->allocateBackground();
549543
if ($background === false) {
550544
throw new RuntimeException('Image could not allocate a color');
551545
}
@@ -557,6 +551,16 @@ public function rotate(float $angle) : static
557551
return $this;
558552
}
559553

554+
protected function allocateBackground() : false | int
555+
{
556+
if ($this->hasAlpha()) {
557+
\imagealphablending($this->instance, false);
558+
\imagesavealpha($this->instance, true);
559+
return \imagecolorallocatealpha($this->instance, 0, 0, 0, 127);
560+
}
561+
return \imagecolorallocate($this->instance, 255, 255, 255);
562+
}
563+
560564
public function hasAlpha() : bool
561565
{
562566
return \in_array(

0 commit comments

Comments
 (0)