Update Composer packages
This commit is contained in:
parent
0320235f6c
commit
a8b68fb61b
378 changed files with 28466 additions and 28852 deletions
|
@ -15,23 +15,16 @@ class Camera
|
|||
{
|
||||
/**
|
||||
* Make exif data
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $make;
|
||||
protected string|null $make;
|
||||
|
||||
/**
|
||||
* Model exif data
|
||||
*
|
||||
* @var string|null
|
||||
* @var
|
||||
*/
|
||||
protected $model;
|
||||
protected string|null $model;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $exif
|
||||
*/
|
||||
public function __construct(array $exif)
|
||||
{
|
||||
$this->make = $exif['Make'] ?? null;
|
||||
|
@ -40,28 +33,22 @@ class Camera
|
|||
|
||||
/**
|
||||
* Returns the make of the camera
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function make(): ?string
|
||||
public function make(): string|null
|
||||
{
|
||||
return $this->make;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the camera model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model(): ?string
|
||||
public function model(): string|null
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the object into a nicely readable array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
|
@ -73,8 +60,6 @@ class Camera
|
|||
|
||||
/**
|
||||
* Returns the full make + model name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
|
@ -83,8 +68,6 @@ class Camera
|
|||
|
||||
/**
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
|
|
|
@ -16,20 +16,15 @@ use Exception;
|
|||
*/
|
||||
class Darkroom
|
||||
{
|
||||
public static $types = [
|
||||
public static array $types = [
|
||||
'gd' => 'Kirby\Image\Darkroom\GdLib',
|
||||
'im' => 'Kirby\Image\Darkroom\ImageMagick'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $settings = [];
|
||||
protected array $settings = [];
|
||||
|
||||
/**
|
||||
* Darkroom constructor
|
||||
*
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct(array $settings = [])
|
||||
{
|
||||
|
@ -40,12 +35,9 @@ class Darkroom
|
|||
* Creates a new Darkroom instance for the given
|
||||
* type/driver
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $settings
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function factory(string $type, array $settings = [])
|
||||
public static function factory(string $type, array $settings = []): object
|
||||
{
|
||||
if (isset(static::$types[$type]) === false) {
|
||||
throw new Exception('Invalid Darkroom type');
|
||||
|
@ -57,8 +49,6 @@ class Darkroom
|
|||
|
||||
/**
|
||||
* Returns the default thumb settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function defaults(): array
|
||||
{
|
||||
|
@ -78,9 +68,6 @@ class Darkroom
|
|||
|
||||
/**
|
||||
* Normalizes all thumb options
|
||||
*
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
protected function options(array $options = []): array
|
||||
{
|
||||
|
@ -108,9 +95,7 @@ class Darkroom
|
|||
unset($options['bw']);
|
||||
}
|
||||
|
||||
if ($options['quality'] === null) {
|
||||
$options['quality'] = $this->settings['quality'];
|
||||
}
|
||||
$options['quality'] ??= $this->settings['quality'];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -119,12 +104,8 @@ class Darkroom
|
|||
* Calculates the dimensions of the final thumb based
|
||||
* on the given options and returns a full array with
|
||||
* all the final options to be used for the image generator
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public function preprocess(string $file, array $options = [])
|
||||
public function preprocess(string $file, array $options = []): array
|
||||
{
|
||||
$options = $this->options($options);
|
||||
$image = new Image($file);
|
||||
|
@ -148,10 +129,6 @@ class Darkroom
|
|||
/**
|
||||
* This method must be replaced by the driver to run the
|
||||
* actual image processing job.
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public function process(string $file, array $options = []): array
|
||||
{
|
||||
|
|
|
@ -19,10 +19,6 @@ class GdLib extends Darkroom
|
|||
{
|
||||
/**
|
||||
* Processes the image with the SimpleImage library
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public function process(string $file, array $options = []): array
|
||||
{
|
||||
|
@ -45,12 +41,8 @@ class GdLib extends Darkroom
|
|||
/**
|
||||
* Activates the autoOrient option in SimpleImage
|
||||
* unless this is deactivated
|
||||
*
|
||||
* @param \claviska\SimpleImage $image
|
||||
* @param $options
|
||||
* @return \claviska\SimpleImage
|
||||
*/
|
||||
protected function autoOrient(SimpleImage $image, $options)
|
||||
protected function autoOrient(SimpleImage $image, array $options): SimpleImage
|
||||
{
|
||||
if ($options['autoOrient'] === false) {
|
||||
return $image;
|
||||
|
@ -61,12 +53,8 @@ class GdLib extends Darkroom
|
|||
|
||||
/**
|
||||
* Wrapper around SimpleImage's resize and crop methods
|
||||
*
|
||||
* @param \claviska\SimpleImage $image
|
||||
* @param array $options
|
||||
* @return \claviska\SimpleImage
|
||||
*/
|
||||
protected function resize(SimpleImage $image, array $options)
|
||||
protected function resize(SimpleImage $image, array $options): SimpleImage
|
||||
{
|
||||
if ($options['crop'] === false) {
|
||||
return $image->resize($options['width'], $options['height']);
|
||||
|
@ -77,12 +65,8 @@ class GdLib extends Darkroom
|
|||
|
||||
/**
|
||||
* Applies the correct blur settings for SimpleImage
|
||||
*
|
||||
* @param \claviska\SimpleImage $image
|
||||
* @param array $options
|
||||
* @return \claviska\SimpleImage
|
||||
*/
|
||||
protected function blur(SimpleImage $image, array $options)
|
||||
protected function blur(SimpleImage $image, array $options): SimpleImage
|
||||
{
|
||||
if ($options['blur'] === false) {
|
||||
return $image;
|
||||
|
@ -93,12 +77,8 @@ class GdLib extends Darkroom
|
|||
|
||||
/**
|
||||
* Applies grayscale conversion if activated in the options.
|
||||
*
|
||||
* @param \claviska\SimpleImage $image
|
||||
* @param array $options
|
||||
* @return \claviska\SimpleImage
|
||||
*/
|
||||
protected function grayscale(SimpleImage $image, array $options)
|
||||
protected function grayscale(SimpleImage $image, array $options): SimpleImage
|
||||
{
|
||||
if ($options['grayscale'] === false) {
|
||||
return $image;
|
||||
|
@ -109,11 +89,8 @@ class GdLib extends Darkroom
|
|||
|
||||
/**
|
||||
* Returns mime type based on `format` option
|
||||
*
|
||||
* @param array $options
|
||||
* @return string|null
|
||||
*/
|
||||
protected function mime(array $options): ?string
|
||||
protected function mime(array $options): string|null
|
||||
{
|
||||
if ($options['format'] === null) {
|
||||
return null;
|
||||
|
|
|
@ -20,52 +20,42 @@ class ImageMagick extends Darkroom
|
|||
/**
|
||||
* Activates imagemagick's auto-orient feature unless
|
||||
* it is deactivated via the options
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function autoOrient(string $file, array $options)
|
||||
protected function autoOrient(string $file, array $options): string|null
|
||||
{
|
||||
if ($options['autoOrient'] === true) {
|
||||
return '-auto-orient';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the blur settings
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function blur(string $file, array $options)
|
||||
protected function blur(string $file, array $options): string|null
|
||||
{
|
||||
if ($options['blur'] !== false) {
|
||||
return '-blur ' . escapeshellarg('0x' . $options['blur']);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep animated gifs
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function coalesce(string $file, array $options)
|
||||
protected function coalesce(string $file, array $options): string|null
|
||||
{
|
||||
if (F::extension($file) === 'gif') {
|
||||
return '-coalesce';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the convert command with the right path to the binary file
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function convert(string $file, array $options): string
|
||||
{
|
||||
|
@ -88,8 +78,6 @@ class ImageMagick extends Darkroom
|
|||
|
||||
/**
|
||||
* Returns additional default parameters for imagemagick
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function defaults(): array
|
||||
{
|
||||
|
@ -101,40 +89,33 @@ class ImageMagick extends Darkroom
|
|||
|
||||
/**
|
||||
* Applies the correct settings for grayscale images
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function grayscale(string $file, array $options)
|
||||
protected function grayscale(string $file, array $options): string|null
|
||||
{
|
||||
if ($options['grayscale'] === true) {
|
||||
return '-colorspace gray';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the correct settings for interlaced JPEGs if
|
||||
* activated via options
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function interlace(string $file, array $options)
|
||||
protected function interlace(string $file, array $options): string|null
|
||||
{
|
||||
if ($options['interlace'] === true) {
|
||||
return '-interlace line';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and runs the full imagemagick command
|
||||
* to process the image
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(string $file, array $options = []): array
|
||||
|
@ -169,10 +150,6 @@ class ImageMagick extends Darkroom
|
|||
|
||||
/**
|
||||
* Applies the correct JPEG compression quality settings
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function quality(string $file, array $options): string
|
||||
{
|
||||
|
@ -182,10 +159,6 @@ class ImageMagick extends Darkroom
|
|||
/**
|
||||
* Creates the correct options to crop or resize the image
|
||||
* and translates the crop positions for imagemagick
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function resize(string $file, array $options): string
|
||||
{
|
||||
|
@ -218,10 +191,6 @@ class ImageMagick extends Darkroom
|
|||
|
||||
/**
|
||||
* Creates the option for the output file
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function save(string $file, array $options): string
|
||||
{
|
||||
|
@ -234,10 +203,6 @@ class ImageMagick extends Darkroom
|
|||
|
||||
/**
|
||||
* Removes all metadata from the image
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function strip(string $file, array $options): string
|
||||
{
|
||||
|
|
|
@ -16,36 +16,14 @@ namespace Kirby\Image;
|
|||
*/
|
||||
class Dimensions
|
||||
{
|
||||
/**
|
||||
* the height of the parent object
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $height = 0;
|
||||
|
||||
/**
|
||||
* the width of the parent object
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $width = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*/
|
||||
public function __construct(int $width, int $height)
|
||||
{
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
public function __construct(
|
||||
public int $width,
|
||||
public int $height
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
|
@ -54,8 +32,6 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Echos the dimensions as width × height
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
|
@ -65,11 +41,9 @@ class Dimensions
|
|||
/**
|
||||
* Crops the dimensions by width and height
|
||||
*
|
||||
* @param int $width
|
||||
* @param int|null $height
|
||||
* @return $this
|
||||
*/
|
||||
public function crop(int $width, int $height = null)
|
||||
public function crop(int $width, int|null $height = null): static
|
||||
{
|
||||
$this->width = $width;
|
||||
$this->height = $width;
|
||||
|
@ -83,10 +57,8 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Returns the height
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function height()
|
||||
public function height(): int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
@ -112,7 +84,7 @@ class Dimensions
|
|||
* upscaled to fit the box if smaller
|
||||
* @return $this object with recalculated dimensions
|
||||
*/
|
||||
public function fit(int $box, bool $force = false)
|
||||
public function fit(int $box, bool $force = false): static
|
||||
{
|
||||
if ($this->width === 0 || $this->height === 0) {
|
||||
$this->width = $box;
|
||||
|
@ -164,7 +136,7 @@ class Dimensions
|
|||
* upscaled to fit the box if smaller
|
||||
* @return $this object with recalculated dimensions
|
||||
*/
|
||||
public function fitHeight(int $fit = null, bool $force = false)
|
||||
public function fitHeight(int|null $fit = null, bool $force = false): static
|
||||
{
|
||||
return $this->fitSize('height', $fit, $force);
|
||||
}
|
||||
|
@ -178,7 +150,7 @@ class Dimensions
|
|||
* upscaled to fit the box if smaller
|
||||
* @return $this object with recalculated dimensions
|
||||
*/
|
||||
protected function fitSize(string $ref, int $fit = null, bool $force = false)
|
||||
protected function fitSize(string $ref, int|null $fit = null, bool $force = false): static
|
||||
{
|
||||
if ($fit === 0 || $fit === null) {
|
||||
return $this;
|
||||
|
@ -217,7 +189,7 @@ class Dimensions
|
|||
* upscaled to fit the box if smaller
|
||||
* @return $this object with recalculated dimensions
|
||||
*/
|
||||
public function fitWidth(int $fit = null, bool $force = false)
|
||||
public function fitWidth(int|null $fit = null, bool $force = false): static
|
||||
{
|
||||
return $this->fitSize('width', $fit, $force);
|
||||
}
|
||||
|
@ -227,11 +199,13 @@ class Dimensions
|
|||
*
|
||||
* @param int|null $width the max height
|
||||
* @param int|null $height the max width
|
||||
* @param bool $force
|
||||
* @return $this
|
||||
*/
|
||||
public function fitWidthAndHeight(int $width = null, int $height = null, bool $force = false)
|
||||
{
|
||||
public function fitWidthAndHeight(
|
||||
int|null $width = null,
|
||||
int|null $height = null,
|
||||
bool $force = false
|
||||
): static {
|
||||
if ($this->width > $this->height) {
|
||||
$this->fitWidth($width, $force);
|
||||
|
||||
|
@ -253,11 +227,8 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Detect the dimensions for an image file
|
||||
*
|
||||
* @param string $root
|
||||
* @return static
|
||||
*/
|
||||
public static function forImage(string $root)
|
||||
public static function forImage(string $root): static
|
||||
{
|
||||
if (file_exists($root) === false) {
|
||||
return new static(0, 0);
|
||||
|
@ -269,11 +240,8 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Detect the dimensions for a svg file
|
||||
*
|
||||
* @param string $root
|
||||
* @return static
|
||||
*/
|
||||
public static function forSvg(string $root)
|
||||
public static function forSvg(string $root): static
|
||||
{
|
||||
// avoid xml errors
|
||||
libxml_use_internal_errors(true);
|
||||
|
@ -299,8 +267,6 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Checks if the dimensions are landscape
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function landscape(): bool
|
||||
{
|
||||
|
@ -309,10 +275,8 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Returns a string representation of the orientation
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function orientation()
|
||||
public function orientation(): string|false
|
||||
{
|
||||
if (!$this->ratio()) {
|
||||
return false;
|
||||
|
@ -331,8 +295,6 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Checks if the dimensions are portrait
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function portrait(): bool
|
||||
{
|
||||
|
@ -349,8 +311,6 @@ class Dimensions
|
|||
* // output: 1.5625
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function ratio(): float
|
||||
{
|
||||
|
@ -362,20 +322,19 @@ class Dimensions
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int|null $width
|
||||
* @param int|null $height
|
||||
* @param bool $force
|
||||
* Resizes image
|
||||
* @return $this
|
||||
*/
|
||||
public function resize(int $width = null, int $height = null, bool $force = false)
|
||||
{
|
||||
public function resize(
|
||||
int|null $width = null,
|
||||
int|null $height = null,
|
||||
bool $force = false
|
||||
): static {
|
||||
return $this->fitWidthAndHeight($width, $height, $force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the dimensions are square
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function square(): bool
|
||||
{
|
||||
|
@ -385,10 +344,9 @@ class Dimensions
|
|||
/**
|
||||
* Resize and crop
|
||||
*
|
||||
* @param array $options
|
||||
* @return $this
|
||||
*/
|
||||
public function thumb(array $options = [])
|
||||
public function thumb(array $options = []): static
|
||||
{
|
||||
$width = $options['width'] ?? null;
|
||||
$height = $options['height'] ?? null;
|
||||
|
@ -405,8 +363,6 @@ class Dimensions
|
|||
/**
|
||||
* Converts the dimensions object
|
||||
* to a plain PHP array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
|
@ -420,8 +376,6 @@ class Dimensions
|
|||
|
||||
/**
|
||||
* Returns the width
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function width(): int
|
||||
{
|
||||
|
|
|
@ -16,75 +16,55 @@ use Kirby\Toolkit\V;
|
|||
class Exif
|
||||
{
|
||||
/**
|
||||
* the parent image object
|
||||
* @var \Kirby\Image\Image
|
||||
* The parent image object
|
||||
*/
|
||||
protected $image;
|
||||
protected Image $image;
|
||||
|
||||
/**
|
||||
* the raw exif array
|
||||
* @var array
|
||||
* The raw exif array
|
||||
*/
|
||||
protected $data = [];
|
||||
protected array $data = [];
|
||||
|
||||
/**
|
||||
* the camera object with model and make
|
||||
* @var Camera
|
||||
* The camera object with model and make
|
||||
*/
|
||||
protected $camera;
|
||||
protected Camera|null $camera = null;
|
||||
|
||||
/**
|
||||
* the location object
|
||||
* @var Location
|
||||
* The location object
|
||||
*/
|
||||
protected $location;
|
||||
protected Location|null $location = null;
|
||||
|
||||
/**
|
||||
* the timestamp
|
||||
*
|
||||
* @var string
|
||||
* The timestamp
|
||||
*/
|
||||
protected $timestamp;
|
||||
protected string|null $timestamp = null;
|
||||
|
||||
/**
|
||||
* the exposure value
|
||||
*
|
||||
* @var string
|
||||
* The exposure value
|
||||
*/
|
||||
protected $exposure;
|
||||
protected string|null $exposure = null;
|
||||
|
||||
/**
|
||||
* the aperture value
|
||||
*
|
||||
* @var string
|
||||
* The aperture value
|
||||
*/
|
||||
protected $aperture;
|
||||
protected string|null $aperture = null;
|
||||
|
||||
/**
|
||||
* iso value
|
||||
*
|
||||
* @var string
|
||||
* ISO value
|
||||
*/
|
||||
protected $iso;
|
||||
protected string|null $iso = null;
|
||||
|
||||
/**
|
||||
* focal length
|
||||
*
|
||||
* @var string
|
||||
* Focal length
|
||||
*/
|
||||
protected $focalLength;
|
||||
protected string|null $focalLength = null;
|
||||
|
||||
/**
|
||||
* color or black/white
|
||||
* @var bool
|
||||
* Color or black/white
|
||||
*/
|
||||
protected $isColor;
|
||||
protected bool|null $isColor = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Kirby\Image\Image $image
|
||||
*/
|
||||
public function __construct(Image $image)
|
||||
{
|
||||
$this->image = $image;
|
||||
|
@ -94,8 +74,6 @@ class Exif
|
|||
|
||||
/**
|
||||
* Returns the raw data array from the parser
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function data(): array
|
||||
{
|
||||
|
@ -104,10 +82,8 @@ class Exif
|
|||
|
||||
/**
|
||||
* Returns the Camera object
|
||||
*
|
||||
* @return \Kirby\Image\Camera|null
|
||||
*/
|
||||
public function camera()
|
||||
public function camera(): Camera
|
||||
{
|
||||
if ($this->camera !== null) {
|
||||
return $this->camera;
|
||||
|
@ -118,10 +94,8 @@ class Exif
|
|||
|
||||
/**
|
||||
* Returns the location object
|
||||
*
|
||||
* @return \Kirby\Image\Location|null
|
||||
*/
|
||||
public function location()
|
||||
public function location(): Location
|
||||
{
|
||||
if ($this->location !== null) {
|
||||
return $this->location;
|
||||
|
@ -132,78 +106,62 @@ class Exif
|
|||
|
||||
/**
|
||||
* Returns the timestamp
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function timestamp()
|
||||
public function timestamp(): string|null
|
||||
{
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exposure
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function exposure()
|
||||
public function exposure(): string|null
|
||||
{
|
||||
return $this->exposure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the aperture
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function aperture()
|
||||
public function aperture(): string|null
|
||||
{
|
||||
return $this->aperture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the iso value
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function iso()
|
||||
public function iso(): string|null
|
||||
{
|
||||
return $this->iso;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is a color picture
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function isColor()
|
||||
public function isColor(): bool|null
|
||||
{
|
||||
return $this->isColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this is a bw picture
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function isBW(): ?bool
|
||||
public function isBW(): bool|null
|
||||
{
|
||||
return ($this->isColor !== null) ? $this->isColor === false : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the focal length
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function focalLength()
|
||||
public function focalLength(): string|null
|
||||
{
|
||||
return $this->focalLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the exif data of the image object if possible
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function read(): array
|
||||
{
|
||||
|
@ -219,8 +177,6 @@ class Exif
|
|||
|
||||
/**
|
||||
* Get all computed data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function computed(): array
|
||||
{
|
||||
|
@ -228,9 +184,9 @@ class Exif
|
|||
}
|
||||
|
||||
/**
|
||||
* Pareses and stores all relevant exif data
|
||||
* Parses and stores all relevant exif data
|
||||
*/
|
||||
protected function parse()
|
||||
protected function parse(): void
|
||||
{
|
||||
$this->timestamp = $this->parseTimestamp();
|
||||
$this->exposure = $this->data['ExposureTime'] ?? null;
|
||||
|
@ -242,13 +198,13 @@ class Exif
|
|||
|
||||
/**
|
||||
* Return the timestamp when the picture has been taken
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
protected function parseTimestamp()
|
||||
protected function parseTimestamp(): string
|
||||
{
|
||||
if (isset($this->data['DateTimeOriginal']) === true) {
|
||||
return strtotime($this->data['DateTimeOriginal']);
|
||||
if ($time = strtotime($this->data['DateTimeOriginal'])) {
|
||||
return (string)$time;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data['FileDateTime'] ?? $this->image->modified();
|
||||
|
@ -256,24 +212,22 @@ class Exif
|
|||
|
||||
/**
|
||||
* Return the focal length
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function parseFocalLength()
|
||||
protected function parseFocalLength(): string|null
|
||||
{
|
||||
return $this->data['FocalLength'] ?? $this->data['FocalLengthIn35mmFilm'] ?? null;
|
||||
return $this->data['FocalLength'] ??
|
||||
$this->data['FocalLengthIn35mmFilm'] ??
|
||||
null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the object into a nicely readable array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'camera' => $this->camera() ? $this->camera()->toArray() : null,
|
||||
'location' => $this->location() ? $this->location()->toArray() : null,
|
||||
'camera' => $this->camera()->toArray(),
|
||||
'location' => $this->location()->toArray(),
|
||||
'timestamp' => $this->timestamp(),
|
||||
'exposure' => $this->exposure(),
|
||||
'aperture' => $this->aperture(),
|
||||
|
@ -285,8 +239,6 @@ class Exif
|
|||
|
||||
/**
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Kirby\Image;
|
||||
|
||||
use Kirby\Exception\LogicException;
|
||||
use Kirby\Filesystem\File;
|
||||
use Kirby\Toolkit\Html;
|
||||
|
||||
|
@ -22,20 +23,10 @@ use Kirby\Toolkit\Html;
|
|||
*/
|
||||
class Image extends File
|
||||
{
|
||||
/**
|
||||
* @var \Kirby\Image\Exif|null
|
||||
*/
|
||||
protected $exif;
|
||||
protected Exif|null $exif = null;
|
||||
protected Dimensions|null $dimensions = null;
|
||||
|
||||
/**
|
||||
* @var \Kirby\Image\Dimensions|null
|
||||
*/
|
||||
protected $dimensions;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $resizableTypes = [
|
||||
public static array $resizableTypes = [
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'gif',
|
||||
|
@ -43,10 +34,7 @@ class Image extends File
|
|||
'webp'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $viewableTypes = [
|
||||
public static array $viewableTypes = [
|
||||
'avif',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
|
@ -58,10 +46,8 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Validation rules to be used for `::match()`
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $validations = [
|
||||
public static array $validations = [
|
||||
'maxsize' => ['size', 'max'],
|
||||
'minsize' => ['size', 'min'],
|
||||
'maxwidth' => ['width', 'max'],
|
||||
|
@ -73,8 +59,6 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Returns the `<img>` tag for the image object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
|
@ -83,10 +67,8 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Returns the dimensions of the file if possible
|
||||
*
|
||||
* @return \Kirby\Image\Dimensions
|
||||
*/
|
||||
public function dimensions()
|
||||
public function dimensions(): Dimensions
|
||||
{
|
||||
if ($this->dimensions !== null) {
|
||||
return $this->dimensions;
|
||||
|
@ -111,18 +93,14 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Returns the exif object for this file (if image)
|
||||
*
|
||||
* @return \Kirby\Image\Exif
|
||||
*/
|
||||
public function exif()
|
||||
public function exif(): Exif
|
||||
{
|
||||
return $this->exif ??= new Exif($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the asset
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function height(): int
|
||||
{
|
||||
|
@ -131,19 +109,18 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Converts the file to html
|
||||
*
|
||||
* @param array $attr
|
||||
* @return string
|
||||
*/
|
||||
public function html(array $attr = []): string
|
||||
{
|
||||
return Html::img($this->url(), $attr);
|
||||
if ($url = $this->url()) {
|
||||
return Html::img($url, $attr);
|
||||
}
|
||||
|
||||
throw new LogicException('Calling Image::html() requires that the URL property is not null');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PHP imagesize array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function imagesize(): array
|
||||
{
|
||||
|
@ -152,8 +129,6 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Checks if the dimensions of the asset are portrait
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPortrait(): bool
|
||||
{
|
||||
|
@ -162,8 +137,6 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Checks if the dimensions of the asset are landscape
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLandscape(): bool
|
||||
{
|
||||
|
@ -172,8 +145,6 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Checks if the dimensions of the asset are square
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSquare(): bool
|
||||
{
|
||||
|
@ -182,8 +153,6 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Checks if the file is a resizable image
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isResizable(): bool
|
||||
{
|
||||
|
@ -193,8 +162,6 @@ class Image extends File
|
|||
/**
|
||||
* Checks if a preview can be displayed for the file
|
||||
* in the Panel or in the frontend
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isViewable(): bool
|
||||
{
|
||||
|
@ -203,8 +170,6 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Returns the ratio of the asset
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function ratio(): float
|
||||
{
|
||||
|
@ -213,19 +178,15 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Returns the orientation as string
|
||||
* landscape | portrait | square
|
||||
*
|
||||
* @return string
|
||||
* `landscape` | `portrait` | `square`
|
||||
*/
|
||||
public function orientation(): string
|
||||
public function orientation(): string|false
|
||||
{
|
||||
return $this->dimensions()->orientation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the object to an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
|
@ -241,8 +202,6 @@ class Image extends File
|
|||
|
||||
/**
|
||||
* Returns the width of the asset
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function width(): int
|
||||
{
|
||||
|
|
|
@ -14,19 +14,8 @@ namespace Kirby\Image;
|
|||
*/
|
||||
class Location
|
||||
{
|
||||
/**
|
||||
* latitude
|
||||
*
|
||||
* @var float|null
|
||||
*/
|
||||
protected $lat;
|
||||
|
||||
/**
|
||||
* longitude
|
||||
*
|
||||
* @var float|null
|
||||
*/
|
||||
protected $lng;
|
||||
protected float|null $lat = null;
|
||||
protected float|null $lng = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -47,32 +36,24 @@ class Location
|
|||
|
||||
/**
|
||||
* Returns the latitude
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function lat()
|
||||
public function lat(): float|null
|
||||
{
|
||||
return $this->lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the longitude
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function lng()
|
||||
public function lng(): float|null
|
||||
{
|
||||
return $this->lng;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the gps coordinates
|
||||
*
|
||||
* @param string|array $coord
|
||||
* @param string $hemi
|
||||
* @return float
|
||||
*/
|
||||
protected function gps($coord, string $hemi): float
|
||||
protected function gps(array $coord, string $hemi): float
|
||||
{
|
||||
$degrees = count($coord) > 0 ? $this->num($coord[0]) : 0;
|
||||
$minutes = count($coord) > 1 ? $this->num($coord[1]) : 0;
|
||||
|
@ -86,9 +67,6 @@ class Location
|
|||
|
||||
/**
|
||||
* Converts coordinates to floats
|
||||
*
|
||||
* @param string $part
|
||||
* @return float
|
||||
*/
|
||||
protected function num(string $part): float
|
||||
{
|
||||
|
@ -103,8 +81,6 @@ class Location
|
|||
|
||||
/**
|
||||
* Converts the object into a nicely readable array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
|
@ -116,8 +92,6 @@ class Location
|
|||
|
||||
/**
|
||||
* Echos the entire location as lat, lng
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
|
@ -126,8 +100,6 @@ class Location
|
|||
|
||||
/**
|
||||
* Improved `var_dump` output
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue