diff --git a/src/Image/Image.php b/src/Image/Image.php index ad191b4..319948b 100644 --- a/src/Image/Image.php +++ b/src/Image/Image.php @@ -106,8 +106,17 @@ public static function getGravityTypes(): array * * @throws \Throwable */ - public function crop(int $width, int $height, string $gravity = Image::GRAVITY_CENTER) + public function crop(int $width, int $height, string $gravity = Image::GRAVITY_CENTER): self { + // if no changes to Gravity, Width or Height, don't process image + if ($gravity === Image::GRAVITY_CENTER && + ( + (! empty($width) && ! empty($height)) && + ($width == $this->width && $height == $this->height) + )) { + return $this; + } + $originalAspect = $this->width / $this->height; if (empty($width)) { @@ -552,4 +561,17 @@ protected function getSizeByFixedWidth(int $newWidth): int return intval($newHeight); } + + public static function setResourceLimit(string $type, int $value): void + { + match ($type) { + 'area' => Imagick::setResourceLimit(Imagick::RESOURCETYPE_AREA, $value), + 'disk' => Imagick::setResourceLimit(Imagick::RESOURCETYPE_DISK, $value), + 'file' => Imagick::setResourceLimit(Imagick::RESOURCETYPE_FILE, $value), + 'map' => Imagick::setResourceLimit(Imagick::RESOURCETYPE_MAP, $value), + 'memory' => Imagick::setResourceLimit(Imagick::RESOURCETYPE_MEMORY, $value), + 'thread' => Imagick::setResourceLimit(Imagick::RESOURCETYPE_THREAD, $value), + default => null, + }; + } }