frimagick: add flipfloprotate

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/579/head
Varun Patil 2023-04-15 19:10:37 -07:00
parent e23afa41cc
commit ec1ad319b6
1 changed files with 25 additions and 0 deletions

View File

@ -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,
]
]);