mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 10:46:54 +02:00
Image classes: added support for dependencies and extra params
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user