Skip to content

Commit

Permalink
return early
Browse files Browse the repository at this point in the history
  • Loading branch information
psion-ar committed Jul 3, 2024
1 parent 0687d1b commit 4c379a5
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/Drivers/Imagick/ImagickDriver.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Spatie\Image\Drivers\Imagick;

use Imagick;
Expand Down Expand Up @@ -56,13 +58,6 @@ public function new(int $width, int $height, ?string $backgroundColor = null): s
return (new self())->setImage($image);
}

protected function setImage(Imagick $image): static
{
$this->image = $image;

return $this;
}

public function image(): Imagick
{
return $this->image;
Expand All @@ -88,11 +83,6 @@ public function loadFile(string $path, bool $autoRotate = true): static
return $this;
}

protected function isAnimated(): bool
{
return count($this->image) > 1;
}

public function getWidth(): int
{
return $this->image->getImageWidth();
Expand Down Expand Up @@ -133,7 +123,7 @@ public function fit(
}

if ($fit === Fit::FillMax) {
if (is_null($desiredWidth) || is_null($desiredHeight)) {
if (null === $desiredWidth || null === $desiredHeight) {
throw new MissingParameter('Both desiredWidth and desiredHeight must be set when using Fit::FillMax');
}

Expand Down Expand Up @@ -265,7 +255,7 @@ public function save(?string $path = null): static
$formats[] = 'JFIF';
}

if (! in_array(strtoupper($extension), $formats)) {
if (! in_array(mb_strtoupper($extension), $formats)) {
throw UnsupportedImageFormat::make($extension);
}

Expand Down Expand Up @@ -354,7 +344,7 @@ public function manualCrop(int $width, int $height, ?int $x = null, ?int $y = nu
$cropped = new Size($width, $height);
$position = new Point($x ?? 0, $y ?? 0);

if (is_null($x) && is_null($y)) {
if (null === $x && null === $y) {
$position = $this
->getSize()
->align(AlignPosition::Center)
Expand Down Expand Up @@ -429,7 +419,7 @@ public function overlay(ImageDriver $bottomImage, ImageDriver $topImage, int $x

public function orientation(?Orientation $orientation = null): static
{
if (is_null($orientation)) {
if (null === $orientation) {
$orientation = $this->getOrientationFromExif($this->exif);
}

Expand Down Expand Up @@ -470,14 +460,16 @@ public function flip(FlipDirection $flip): static

public function pixelate(int $pixelate = 50): static
{
if ($pixelate !== 0) {
$width = $this->getWidth();
$height = $this->getHeight();
if ($pixelate === 0) {
return $this;
}

foreach ($this->image as $image) {
$image->scaleImage(max(1, (int) ($width / $pixelate)), max(1, (int) ($height / $pixelate)));
$image->scaleImage($width, $height);
}
$width = $this->getWidth();
$height = $this->getHeight();

foreach ($this->image as $image) {
$image->scaleImage(max(1, (int) ($width / $pixelate)), max(1, (int) ($height / $pixelate)));
$image->scaleImage($width, $height);
}

return $this;
Expand Down Expand Up @@ -724,4 +716,16 @@ public function wrapText(string $text, int $fontSize, string $fontPath = '', int

return $wrapped;
}

protected function setImage(Imagick $image): static
{
$this->image = $image;

return $this;
}

protected function isAnimated(): bool
{
return count($this->image) > 1;
}
}

0 comments on commit 4c379a5

Please sign in to comment.