From ec1cc1013267b7a760addb9ecb5be5d78eaab2b2 Mon Sep 17 00:00:00 2001 From: "Ben Scholzen (DASPRiD)" Date: Sun, 5 Apr 2026 21:44:09 +0200 Subject: [PATCH] feat(imagick): add antialias option to ImagickImageBackEnd (#209) Add a $antialias constructor parameter (default true) to allow disabling antialiasing for sharper images, smaller file sizes, and better nearest-neighbor scalability. Closes #209 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Renderer/Image/ImagickImageBackEnd.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Renderer/Image/ImagickImageBackEnd.php b/src/Renderer/Image/ImagickImageBackEnd.php index a16a663..1270ac9 100644 --- a/src/Renderer/Image/ImagickImageBackEnd.php +++ b/src/Renderer/Image/ImagickImageBackEnd.php @@ -40,7 +40,9 @@ final class ImagickImageBackEnd implements ImageBackEndInterface private ?int $matrixIndex; - public function __construct(string $imageFormat = 'png', int $compressionQuality = 100) + private bool $antialias; + + public function __construct(string $imageFormat = 'png', int $compressionQuality = 100, bool $antialias = true) { if (! class_exists(Imagick::class)) { throw new RuntimeException('You need to install the imagick extension to use this back end'); @@ -48,6 +50,7 @@ public function __construct(string $imageFormat = 'png', int $compressionQuality $this->imageFormat = $imageFormat; $this->compressionQuality = $compressionQuality; + $this->antialias = $antialias; } public function new(int $size, ColorInterface $backgroundColor) : void @@ -57,6 +60,12 @@ public function new(int $size, ColorInterface $backgroundColor) : void $this->image->setImageFormat($this->imageFormat); $this->image->setCompressionQuality($this->compressionQuality); $this->draw = new ImagickDraw(); + + if (! $this->antialias) { + $this->image->setAntiAlias(false); + $this->draw->setStrokeAntialias(false); + } + $this->gradientCount = 0; $this->matrices = [new TransformationMatrix()]; $this->matrixIndex = 0;