From 035e533c02b943f4c11bdc43e8b5afeefc90afe5 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 22 Feb 2022 11:47:36 +0200 Subject: [PATCH] Image classes: added support for dependencies and extra params --- system/src/Grav/Framework/Image/Image.php | 23 ++++++++++++++++++- .../Image/Traits/ImageOperationsTrait.php | 5 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Framework/Image/Image.php b/system/src/Grav/Framework/Image/Image.php index d82d8bf97..41f637d25 100644 --- a/system/src/Grav/Framework/Image/Image.php +++ b/system/src/Grav/Framework/Image/Image.php @@ -5,12 +5,13 @@ namespace Grav\Framework\Image; use Grav\Framework\Compat\Serializable; use Grav\Framework\Contracts\Image\ImageOperationsInterface; use Grav\Framework\Image\Traits\ImageOperationsTrait; +use JsonSerializable; use RuntimeException; /** * Image class. */ -class Image implements ImageOperationsInterface +class Image implements ImageOperationsInterface, JsonSerializable { use ImageOperationsTrait; use Serializable; @@ -25,6 +26,8 @@ class Image implements ImageOperationsInterface protected $modified; /** @var int */ protected $size; + /** @var array */ + public $extra = []; /** * @param string $filepath @@ -33,6 +36,8 @@ class Image implements ImageOperationsInterface public function __construct(string $filepath, array $info) { $this->filepath = $filepath; + $this->modified = $info['modified'] ?? 0; + $this->size = $info['size'] ?? 0; $this->origWidth = $this->width = $info['width'] ?? 0; $this->origHeight = $this->height = $info['height'] ?? 0; $this->orientation = isset($info['exif']['Orientation']) ? (int)$info['exif']['Orientation'] : null; @@ -46,12 +51,16 @@ class Image implements ImageOperationsInterface return [ 'image' => 1, 'filepath' => $this->filepath, + 'modified' => $this->modified, + 'size' => $this->size, 'orientation' => $this->orientation, 'orig_width' => $this->origWidth, 'orig_height' => $this->origHeight, 'width' => $this->width, 'height' => $this->height, + 'dependencies' => $this->dependencies, 'operations' => $this->operations, + 'extra' => $this->extra ]; } @@ -67,12 +76,24 @@ class Image implements ImageOperationsInterface } $this->filepath = $data['filepath']; + $this->modified = $data['modified']; + $this->size = $data['size']; $this->origWidth = $data['orig_width']; $this->origHeight = $data['orig_height']; $this->orientation = $data['orientation']; $this->width = $data['width']; $this->height = $data['height']; + $this->dependencies = $data['dependencies']; $this->operations = $data['operations']; + $this->extra = $data['extra']; + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + return ['hash' => $this->generateHash()] + $this->__serialize(); } /** diff --git a/system/src/Grav/Framework/Image/Traits/ImageOperationsTrait.php b/system/src/Grav/Framework/Image/Traits/ImageOperationsTrait.php index 8bb7dc87d..42260e68e 100644 --- a/system/src/Grav/Framework/Image/Traits/ImageOperationsTrait.php +++ b/system/src/Grav/Framework/Image/Traits/ImageOperationsTrait.php @@ -17,6 +17,8 @@ trait ImageOperationsTrait /** @var int|null */ protected $orientation = null; /** @var array */ + protected $dependencies = []; + /** @var array */ protected $operations = []; /** @@ -475,8 +477,9 @@ trait ImageOperationsTrait */ public function merge(Image $other, int $x = 0, int $y = 0, int $width = 0, int $height = 0) { - $serialized = $other->__serialize(); + $serialized = $other->jsonSerialize(); + $dependencies[] = $serialized; $this->operations[] = ['merge', [$serialized, $x, $y, $width, $height]]; return $this;