From 5889391fc87d5176bd20a823a1fabc02a4033843 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 26 Nov 2023 13:29:41 +0100 Subject: [PATCH] Add modifier methods --- src/Image.php | 18 ++++++++++++++++++ src/Interfaces/ImageInterface.php | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/Image.php b/src/Image.php index 6e6319ae..d10debef 100644 --- a/src/Image.php +++ b/src/Image.php @@ -26,8 +26,11 @@ use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\Interfaces\ProfileInterface; use Intervention\Image\Interfaces\ResolutionInterface; use Intervention\Image\Interfaces\SizeInterface; +use Intervention\Image\Modifiers\ColorspaceModifier; use Intervention\Image\Modifiers\GreyscaleModifier; use Intervention\Image\Modifiers\PixelateModifier; +use Intervention\Image\Modifiers\ProfileModifier; +use Intervention\Image\Modifiers\ResolutionModifier; use Intervention\Image\Modifiers\RotateModifier; use Intervention\Image\Modifiers\SharpenModifier; use Intervention\Image\Modifiers\TextModifier; @@ -112,11 +115,21 @@ class Image implements ImageInterface, Countable return $this->analyze(new ColorspaceAnalyzer()); } + public function setColorspace(string|ColorspaceInterface $colorspace): ImageInterface + { + return $this->modify(new ColorspaceModifier($colorspace)); + } + public function resolution(): ResolutionInterface { return $this->analyze(new ResolutionAnalyzer()); } + public function setResolution(float $x, float $y): ImageInterface + { + return $this->modify(new ResolutionModifier($x, $y)); + } + public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface { return $this->analyze(new PixelColorAnalyzer($x, $y, $frame_key)); @@ -132,6 +145,11 @@ class Image implements ImageInterface, Countable return $this->analyze(new ProfileAnalyzer()); } + public function setProfile(ProfileInterface $profile): ImageInterface + { + return $this->modify(new ProfileModifier($profile)); + } + public function sharpen(int $amount = 10): ImageInterface { return $this->modify(new SharpenModifier($amount)); diff --git a/src/Interfaces/ImageInterface.php b/src/Interfaces/ImageInterface.php index 5978c480..c192a93c 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Interfaces; use Countable; use Intervention\Image\EncodedImage; +use Intervention\Image\Modifiers\ColorspaceModifier; use IteratorAggregate; interface ImageInterface extends IteratorAggregate, Countable @@ -95,6 +96,16 @@ interface ImageInterface extends IteratorAggregate, Countable */ public function resolution(): ResolutionInterface; + + /** + * Set image resolution + * + * @param float $x + * @param float $y + * @return ImageInterface + */ + public function setResolution(float $x, float $y): ImageInterface; + /** * Get the colorspace of the image * @@ -102,6 +113,14 @@ interface ImageInterface extends IteratorAggregate, Countable */ public function colorspace(): ColorspaceInterface; + /** + * Transform image to given colorspace + * + * @param string|ColorspaceInterface $colorspace + * @return ImageInterface + */ + public function setColorspace(string|ColorspaceInterface $colorspace): ImageInterface; + /** * Return color of pixel at given position on given frame position * @@ -128,6 +147,14 @@ interface ImageInterface extends IteratorAggregate, Countable */ public function profile(): ProfileInterface; + /** + * Set given icc color profile to image + * + * @param ProfileInterface $profile + * @return ImageInterface + */ + public function setProfile(ProfileInterface $profile): ImageInterface; + /** * Sharpen the current image with given strength *