From ec1ad319b6f1a36d6b3838d9a67345118c74158d Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 15 Apr 2023 19:10:37 -0700 Subject: [PATCH] frimagick: add flipfloprotate Signed-off-by: Varun Patil --- test.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test.php b/test.php index cef4014a..69780deb 100644 --- a/test.php +++ b/test.php @@ -27,6 +27,12 @@ class ImageState { public ?float $cropWidth = null; /** Crop height */ public ?float $cropHeight = null; + /** Rotation */ + public ?int $rotation = null; + /** Flipped X */ + public bool $isFlippedX = false; + /** Flipped Y */ + public bool $isFlippedY = false; public function __construct(array $json) { @@ -61,6 +67,9 @@ class ImageState { $this->_set($crop, 'width', 'cropWidth'); $this->_set($crop, 'height', 'cropHeight'); } + $this->_set($props, 'rotation'); + $this->_set($props, 'isFlippedX'); + $this->_set($props, 'isFlippedY'); } } @@ -84,6 +93,7 @@ class KonvaMagick { public function apply() { $this->applyCrop(); + $this->applyFlipRotation(); foreach ($this->state->finetuneOrder as $key) { $method = 'apply' . $key; @@ -106,6 +116,18 @@ class KonvaMagick { } } + protected function applyFlipRotation() { + if ($this->state->isFlippedX) { + $this->image->flopImage(); + } + if ($this->state->isFlippedY) { + $this->image->flipImage(); + } + if ($this->state->rotation) { + $this->image->rotateImage(new \ImagickPixel(), $this->state->rotation); + } + } + protected function applyBrighten() { $brightness = $this->state->brightness ?? 0; if ($brightness === 0) { @@ -208,6 +230,9 @@ $imageState = new ImageState([ 'width' => 0.47661152675402463, 'height' => 0.47661153565936554, ], + 'rotation' => 90, + 'isFlippedX' => false, + 'isFlippedY' => true, ] ]);