Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
180 lines
3.7 KiB
PHP
180 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Intervention\Image;
|
|
|
|
use ArrayIterator;
|
|
use Intervention\Image\Exceptions\InvalidArgumentException;
|
|
use Intervention\Image\Interfaces\ResolutionInterface;
|
|
use IteratorAggregate;
|
|
use JsonSerializable;
|
|
use Stringable;
|
|
use Traversable;
|
|
|
|
/**
|
|
* @implements IteratorAggregate<float>
|
|
*/
|
|
class Resolution implements ResolutionInterface, Stringable, IteratorAggregate, JsonSerializable
|
|
{
|
|
/**
|
|
* Create new instance.
|
|
*
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
public function __construct(
|
|
protected float $x,
|
|
protected float $y,
|
|
protected Length $length = Length::INCH,
|
|
) {
|
|
if ($x < 0) {
|
|
throw new InvalidArgumentException(
|
|
'The value of the X-axis for ' . $this::class . ' must be greater or equal to 0',
|
|
);
|
|
}
|
|
|
|
if ($y < 0) {
|
|
throw new InvalidArgumentException(
|
|
'The value of the Y-axis for ' . $this::class . ' must be greater or equal to 0',
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::dpi()
|
|
*
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
public static function dpi(float $x, float $y): ResolutionInterface
|
|
{
|
|
return new self($x, $y, Length::INCH);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::ppi()
|
|
*
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
public static function ppi(float $x, float $y): ResolutionInterface
|
|
{
|
|
return new self($x, $y, Length::CM);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see IteratorAggregate::getIterator()
|
|
*/
|
|
public function getIterator(): Traversable
|
|
{
|
|
return new ArrayIterator([$this->x, $this->y]);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::x()
|
|
*/
|
|
public function x(): float
|
|
{
|
|
return $this->x;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::y()
|
|
*/
|
|
public function y(): float
|
|
{
|
|
return $this->y;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::length()
|
|
*/
|
|
public function length(): Length
|
|
{
|
|
return $this->length;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::perInch()
|
|
*/
|
|
public function perInch(): self
|
|
{
|
|
return match ($this->length) {
|
|
// @phpstan-ignore missingType.checkedException
|
|
Length::CM => new self(
|
|
$this->x * 2.54,
|
|
$this->y * 2.54,
|
|
Length::INCH,
|
|
),
|
|
default => $this
|
|
};
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::perCm()
|
|
*/
|
|
public function perCm(): self
|
|
{
|
|
return match ($this->length) {
|
|
// @phpstan-ignore missingType.checkedException
|
|
Length::INCH => new self(
|
|
$this->x / 2.54,
|
|
$this->y / 2.54,
|
|
Length::CM,
|
|
),
|
|
default => $this,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see JsonSerializable::jsonSerialize()
|
|
*/
|
|
public function jsonSerialize(): mixed
|
|
{
|
|
return $this->toString();
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::toString()
|
|
*/
|
|
public function toString(): string
|
|
{
|
|
return sprintf(
|
|
"%1\$.2f x %2\$.2f %3\$s",
|
|
$this->x,
|
|
$this->y,
|
|
match ($this->length) {
|
|
Length::INCH => 'dpi',
|
|
Length::CM => 'dpcm',
|
|
},
|
|
);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*
|
|
* @see ResolutionInterface::__toString()
|
|
*/
|
|
public function __toString(): string
|
|
{
|
|
return $this->toString();
|
|
}
|
|
}
|