Phase 0: Fundament für Inhaus
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>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,17 @@
<?php
namespace Illuminate\Image\Drivers;
use Intervention\Image\Drivers\Gd\Driver as InterventionGdDriver;
use Intervention\Image\ImageManager;
class GdDriver extends InterventionDriver
{
/**
* Create the underlying Intervention image manager.
*/
protected function createManager(): ImageManager
{
return ImageManager::usingDriver(InterventionGdDriver::class);
}
}

View file

@ -0,0 +1,17 @@
<?php
namespace Illuminate\Image\Drivers;
use Intervention\Image\Drivers\Imagick\Driver as InterventionImagickDriver;
use Intervention\Image\ImageManager;
class ImagickDriver extends InterventionDriver
{
/**
* Create the underlying Intervention image manager.
*/
protected function createManager(): ImageManager
{
return ImageManager::usingDriver(InterventionImagickDriver::class);
}
}

View file

@ -0,0 +1,226 @@
<?php
namespace Illuminate\Image\Drivers;
use finfo;
use Illuminate\Contracts\Image\Driver;
use Illuminate\Image\ImageException;
use Illuminate\Image\ImageOutputOptions;
use Illuminate\Image\ImagePipeline;
use Illuminate\Image\Transformations\Blur;
use Illuminate\Image\Transformations\Contain;
use Illuminate\Image\Transformations\Cover;
use Illuminate\Image\Transformations\Crop;
use Illuminate\Image\Transformations\FlipHorizontally;
use Illuminate\Image\Transformations\FlipVertically;
use Illuminate\Image\Transformations\Grayscale;
use Illuminate\Image\Transformations\Orient;
use Illuminate\Image\Transformations\Resize;
use Illuminate\Image\Transformations\Rotate;
use Illuminate\Image\Transformations\Scale;
use Illuminate\Image\Transformations\Sharpen;
use Intervention\Image\Direction;
use Intervention\Image\Encoders\AvifEncoder;
use Intervention\Image\Encoders\BmpEncoder;
use Intervention\Image\Encoders\GifEncoder;
use Intervention\Image\Encoders\HeicEncoder;
use Intervention\Image\Encoders\JpegEncoder;
use Intervention\Image\Encoders\MediaTypeEncoder;
use Intervention\Image\Encoders\PngEncoder;
use Intervention\Image\Encoders\WebpEncoder;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageInterface;
abstract class InterventionDriver implements Driver
{
/**
* The registered transformation handlers.
*
* @var array<class-string<\Illuminate\Contracts\Image\Transformation>, callable>
*/
protected array $transformationHandlers = [];
/**
* The Intervention image manager instance.
*/
protected ImageManager $manager;
/**
* Create a new Intervention driver instance.
*/
public function __construct()
{
$this->manager = $this->createManager();
}
/**
* Create the underlying Intervention image manager.
*/
abstract protected function createManager(): ImageManager;
/**
* Ensure Intervention Image is installed.
*
* @throws ImageException
*/
public function ensureRequirementsAreMet(): void
{
if (! class_exists(ImageManager::class)) {
throw new ImageException(
'Intervention Image is required to use this driver. '.
'You may install it via: composer require intervention/image:^4.0',
);
}
}
/**
* Process the given image contents with the specified pipeline.
*/
public function process(string $contents, ImagePipeline $pipeline): string
{
$mimeType = (new finfo(FILEINFO_MIME_TYPE))->buffer($contents);
if (! in_array($mimeType, ['image/jpeg', 'image/png', 'image/bmp', 'image/gif', 'image/webp', 'image/avif', 'image/x-avif', 'image/heic', 'image/x-heic', 'image/heif'])) {
throw new ImageException("The image format [{$mimeType}] is not supported.");
}
$image = $this->manager->decode($contents);
foreach ($pipeline->transformations as $transformation) {
if ($handler = $this->transformationHandlerFor($transformation)) {
$image = $handler($image, $transformation);
continue;
}
$image = match (true) {
$transformation instanceof Orient => $image->orient(),
$transformation instanceof Cover => $image->cover($transformation->width, $transformation->height),
$transformation instanceof Contain => $image->contain(
$transformation->width,
$transformation->height,
$this->resolveBackground($image, $transformation->background),
),
$transformation instanceof Crop => $image->crop($transformation->width, $transformation->height, $transformation->x, $transformation->y),
$transformation instanceof Resize => $image->resize($transformation->width, $transformation->height),
$transformation instanceof Rotate => $image->rotate(
$transformation->angle,
$this->resolveBackground($image, $transformation->background),
),
$transformation instanceof Scale => $image->scaleDown($transformation->width, $transformation->height),
$transformation instanceof Blur => $image->blur($transformation->amount),
$transformation instanceof Grayscale => $image->grayscale(),
$transformation instanceof Sharpen => $image->sharpen($transformation->amount),
$transformation instanceof FlipVertically => $image->flip(Direction::VERTICAL),
$transformation instanceof FlipHorizontally => $image->flip(Direction::HORIZONTAL),
default => throw new ImageException('The image transformation ['.get_class($transformation).'] is not supported.'),
};
}
$quality = $pipeline->output->quality ?? ImageOutputOptions::DEFAULT_QUALITY;
try {
if ($pipeline->output->format !== null) {
return $image->encode(match ($pipeline->output->format) {
'webp' => new WebpEncoder($quality),
'jpg', 'jpeg' => new JpegEncoder($quality),
'png' => new PngEncoder,
'gif' => new GifEncoder,
'avif' => new AvifEncoder($quality),
'heic' => new HeicEncoder($quality),
'bmp' => new BmpEncoder,
})->toString();
}
$mediaType = match ($image->origin()->mediaType()) {
'image/x-gif' => 'image/gif',
default => null,
};
return $image->encode(new MediaTypeEncoder($mediaType, quality: $quality))->toString();
} finally {
unset($image);
}
}
/**
* Get the dimensions of the given image contents.
*
* @return array{0: int, 1: int}
*/
public function dimensions(string $contents): array
{
$image = $this->manager->decode($contents);
try {
return [$image->width(), $image->height()];
} finally {
unset($image);
}
}
/**
* Resolve a background color, expanding the "dominant" sentinel when needed.
*/
protected function resolveBackground(ImageInterface $image, ?string $background): ?string
{
return $background === 'dominant'
? $this->dominantColorFrom($image)
: $background;
}
/**
* Get the dominant (average) color of the image as a hex string.
*/
public function dominantColor(string $contents): string
{
$image = $this->manager->decode($contents);
try {
return $this->dominantColorFrom($image);
} finally {
unset($image);
}
}
/**
* Sample the dominant color by resizing the image to a single pixel.
*/
protected function dominantColorFrom(ImageInterface $image): string
{
$sample = clone $image;
try {
// Interpolation during the 1x1 resize can leave alpha slightly non-opaque, so it's dropped here.
return substr($sample->resize(1, 1)->colorAt(0, 0)->toHex(true), 0, 7);
} finally {
unset($sample);
}
}
/**
* Register a transformation handler.
*
* @param class-string<\Illuminate\Contracts\Image\Transformation> $transformation
*/
public function transformUsing(string $transformation, callable $callback): static
{
$this->transformationHandlers[$transformation] = $callback;
return $this;
}
/**
* Get the handler for the given transformation.
*/
protected function transformationHandlerFor(object $transformation): ?callable
{
foreach ($this->transformationHandlers as $class => $handler) {
if ($transformation instanceof $class) {
return $handler;
}
}
return null;
}
}

View file

@ -0,0 +1,657 @@
<?php
namespace Illuminate\Image;
use Closure;
use finfo;
use Illuminate\Container\Container;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
use Illuminate\Contracts\Image\Driver;
use Illuminate\Contracts\Image\Transformation;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Response;
use Illuminate\Http\UploadedFile;
use Illuminate\Image\Transformations\Blur;
use Illuminate\Image\Transformations\Contain;
use Illuminate\Image\Transformations\Cover;
use Illuminate\Image\Transformations\Crop;
use Illuminate\Image\Transformations\FlipHorizontally;
use Illuminate\Image\Transformations\FlipVertically;
use Illuminate\Image\Transformations\Grayscale;
use Illuminate\Image\Transformations\Orient;
use Illuminate\Image\Transformations\Resize;
use Illuminate\Image\Transformations\Rotate;
use Illuminate\Image\Transformations\Scale;
use Illuminate\Image\Transformations\Sharpen;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use Stringable;
use Throwable;
class Image implements Responsable, Stringable
{
use Conditionable, Macroable;
/**
* The image processing pipeline.
*/
protected ImagePipeline $pipeline;
/**
* The driver override.
*/
protected ?string $driver = null;
/**
* The image contents, or a lazy loader that resolves them.
*/
protected Closure|string $contents;
/**
* Whether the image has been processed.
*/
protected bool $processed = false;
/**
* The cached hash name.
*/
protected ?string $hashName = null;
/**
* Create a new image instance.
*/
public function __construct(
Closure|string $contents,
protected ?UploadedFile $file = null,
) {
$this->contents = $contents instanceof Closure
? $this->resolveOnce($contents)
: $contents;
$this->pipeline = new ImagePipeline;
}
/**
* Wrap a lazy contents loader so it is invoked at most once, even across clones.
*/
protected function resolveOnce(Closure $loader): Closure
{
return function () use ($loader) {
static $contents;
return $contents ??= $loader();
};
}
/**
* Set the cover dimensions.
*
* @param int<1, max> $width
* @param int<1, max> $height
*/
public function cover(int $width, int $height): static
{
return $this->transform(new Cover(max(1, $width), max(1, $height)));
}
/**
* Set the contain dimensions.
*
* @param int<1, max> $width
* @param int<1, max> $height
*/
public function contain(int $width, int $height, ?string $background = null): static
{
return $this->transform(new Contain(max(1, $width), max(1, $height), $background));
}
/**
* Crop the image to the given dimensions and position.
*
* @param int<1, max> $width
* @param int<1, max> $height
*/
public function crop(int $width, int $height, int $x = 0, int $y = 0): static
{
return $this->transform(new Crop(max(1, $width), max(1, $height), $x, $y));
}
/**
* Resize the image to the given dimensions.
*
* @param int<1, max>|null $width
* @param int<1, max>|null $height
*/
public function resize(?int $width = null, ?int $height = null): static
{
if ($width === null && $height === null) {
throw new ImageException('At least one resize dimension must be specified.');
}
return $this->transform(new Resize(
$width === null ? null : max(1, $width),
$height === null ? null : max(1, $height),
));
}
/**
* Rotate the image clockwise by the given angle.
*/
public function rotate(float $angle, ?string $background = null): static
{
return $this->transform(new Rotate($angle, $background));
}
/**
* Set the scale dimensions.
*
* @param int<1, max>|null $width
* @param int<1, max>|null $height
*/
public function scale(?int $width = null, ?int $height = null): static
{
if ($width === null && $height === null) {
throw new ImageException('At least one scale dimension must be specified.');
}
return $this->transform(new Scale(
$width === null ? null : max(1, $width),
$height === null ? null : max(1, $height),
));
}
/**
* Auto-orient the image based on EXIF data.
*/
public function orient(): static
{
return $this->transform(new Orient);
}
/**
* Apply a blur effect.
*
* @param int<0, 100> $amount
*/
public function blur(int $amount = 5): static
{
return $this->transform(new Blur(max(0, min(100, $amount))));
}
/**
* Convert the image to grayscale.
*/
public function grayscale(): static
{
return $this->transform(new Grayscale);
}
/**
* Sharpen the image.
*
* @param int<0, 100> $amount
*/
public function sharpen(int $amount = 10): static
{
return $this->transform(new Sharpen(max(0, min(100, $amount))));
}
/**
* Flip the image vertically.
*/
public function flipVertically(): static
{
return $this->transform(new FlipVertically);
}
/**
* Flip the image horizontally.
*/
public function flipHorizontally(): static
{
return $this->transform(new FlipHorizontally);
}
/**
* Flip the image vertically.
*/
public function flip(): static
{
return $this->flipVertically();
}
/**
* Flip the image horizontally.
*/
public function flop(): static
{
return $this->flipHorizontally();
}
/**
* Add a transformation to the image pipeline.
*/
public function transform(Transformation $transformation): static
{
return $this->withClone(fn (Image $image) => $image->pipeline->add($transformation));
}
/**
* Set the optimization options.
*
* @throws ImageException
*/
public function optimize(string $format = 'webp', int $quality = ImageOutputOptions::DEFAULT_QUALITY): static
{
return $this->toFormat($format)->quality($quality);
}
/**
* Set the output quality.
*
* @param int<1, 100> $quality
*/
public function quality(int $quality): static
{
return $this->withOutput(fn (ImageOutputOptions $output) => $output->quality = max(1, min(100, $quality)));
}
/**
* Convert the image to WebP format.
*/
public function toWebp(): static
{
return $this->toFormat('webp');
}
/**
* Convert the image to JPEG format.
*/
public function toJpg(): static
{
return $this->toFormat('jpg');
}
/**
* Convert the image to JPEG format.
*/
public function toJpeg(): static
{
return $this->toJpg();
}
/**
* Convert the image to PNG format.
*/
public function toPng(): static
{
return $this->toFormat('png');
}
/**
* Convert the image to GIF format.
*/
public function toGif(): static
{
return $this->toFormat('gif');
}
/**
* Convert the image to AVIF format.
*/
public function toAvif(): static
{
return $this->toFormat('avif');
}
/**
* Convert the image to HEIC format.
*/
public function toHeic(): static
{
return $this->toFormat('heic');
}
/**
* Convert the image to BMP format.
*/
public function toBmp(): static
{
return $this->toFormat('bmp');
}
/**
* Set the output format.
*
* @throws ImageException
*/
public function toFormat(string $format): static
{
if (! in_array($format, ['webp', 'jpg', 'jpeg', 'png', 'gif', 'avif', 'heic', 'heif', 'bmp'])) {
throw new ImageException("The [{$format}] format is not supported.");
}
$format = $format === 'heif' ? 'heic' : $format;
return $this->withOutput(fn (ImageOutputOptions $output) => $output->format = $format);
}
/**
* Store the processed image on a filesystem disk.
*
* @param array<string, mixed> $options
*/
public function store(string $path = '', ?string $disk = null, array $options = []): string|false
{
return $this->storeAs($path, $this->hashName(), $disk, $options);
}
/**
* Store the processed image on a filesystem disk with public visibility.
*
* @param array<string, mixed> $options
*/
public function storePublicly(string $path = '', ?string $disk = null, array $options = []): string|false
{
$options['visibility'] = 'public';
return $this->storeAs($path, $this->hashName(), $disk, $options);
}
/**
* Store the processed image on a filesystem disk with a given name.
*
* @param array<string, mixed> $options
*/
public function storeAs(string $path, ?string $name = null, ?string $disk = null, array $options = []): string|false
{
if (is_null($name)) {
[$path, $name] = ['', $path];
}
$path = trim($path.'/'.$name, '/');
$result = Container::getInstance()->make(FilesystemFactory::class)
->disk($disk)
->put($path, $this->toBytes(), $options);
return $result ? $path : false;
}
/**
* Store the processed image on a filesystem disk with public visibility and a given name.
*
* @param array<string, mixed> $options
*/
public function storePubliclyAs(string $path, ?string $name = null, ?string $disk = null, array $options = []): string|false
{
if (is_null($name)) {
[$path, $name] = ['', $path];
}
$options['visibility'] = 'public';
return $this->storeAs($path, $name, $disk, $options);
}
/**
* Get a hashed filename with the correct extension.
*/
public function hashName(string $path = ''): string
{
$this->hashName ??= Str::random(40);
$hash = $this->hashName.'.'.$this->extension();
return $path ? $path.'/'.$hash : $hash;
}
/**
* Process the image and return the raw bytes.
*/
public function toBytes(): string
{
if ($this->pipeline->hasChanges() && ! $this->processed) {
try {
$this->contents = $this->resolveDriver()->process(
value($this->contents), $this->pipeline
);
} catch (ImageException $e) {
throw $e;
} catch (Throwable $e) {
throw new ImageException("Failed to process image: {$e->getMessage()}", 0, $e);
}
$this->pipeline = new ImagePipeline;
$this->processed = true;
}
return value($this->contents);
}
/**
* Process the image and return as a base64 encoded string.
*/
public function toBase64(): string
{
return base64_encode($this->toBytes());
}
/**
* Process the image and return as a data URI.
*/
public function toDataUri(): string
{
return 'data:'.$this->mimeType().';base64,'.$this->toBase64();
}
/**
* Get the file extension based on the MIME type.
*/
public function extension(): string
{
return match ($this->mimeType()) {
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
'image/webp' => 'webp',
'image/avif', 'image/x-avif' => 'avif',
'image/heic', 'image/x-heic', 'image/heif' => 'heic',
'image/bmp' => 'bmp',
'image/svg+xml' => 'svg',
'image/tiff' => 'tiff',
default => 'bin',
};
}
/**
* Get the MIME type of the processed image.
*/
public function mimeType(): string
{
return once(function () {
return (new finfo(FILEINFO_MIME_TYPE))->buffer($this->toBytes());
});
}
/**
* Get the dimensions of the processed image.
*
* @return array{0: int, 1: int}
*/
public function dimensions(): array
{
return once(function () {
$contents = $this->toBytes();
// getimagesize() misreports HEIC's coded / padded frame size, so read HEIC via the driver...
if (in_array($this->mimeType(), ['image/heic', 'image/heif', 'image/x-heic'], true)) {
try {
return $this->resolveDriver()->dimensions($contents);
} catch (Throwable) {
// The driver can't decode this image; fall back to the native reader below...
}
}
$size = @getimagesizefromstring($contents);
if ($size === false) {
throw new ImageException('Unable to determine the dimensions of the image.');
}
return [$size[0], $size[1]];
});
}
/**
* Get the width of the processed image.
*/
public function width(): int
{
return $this->dimensions()[0];
}
/**
* Get the height of the processed image.
*/
public function height(): int
{
return $this->dimensions()[1];
}
/**
* Get the dominant (average) color of the image as a hex string.
*/
public function dominantColor(): string
{
return once(function () {
$contents = value($this->contents);
if ($this->pipeline->hasChanges() && ! $this->processed) {
$contents = $this->resolveDriver()->process($contents, clone $this->pipeline);
}
return $this->resolveDriver()->dominantColor($contents);
});
}
/**
* Set the driver to use for processing.
*/
public function using(string $driver): static
{
$clone = $this->newClone();
$clone->driver = $driver;
return $clone;
}
/**
* Use the GD driver for processing.
*/
public function usingGd(): static
{
return $this->using('gd');
}
/**
* Use the Imagick driver for processing.
*/
public function usingImagick(): static
{
return $this->using('imagick');
}
/**
* Resolve the image processing driver.
*/
protected function resolveDriver(): Driver
{
$manager = Container::getInstance()->make('image');
return $this->driver
? $manager->driver($this->driver)
: $manager->driver();
}
/**
* Get the underlying uploaded file instance.
*/
public function file(): ?UploadedFile
{
return $this->file;
}
/**
* Create an immutable clone with copied options.
*/
protected function newClone(): static
{
$clone = clone $this;
$clone->pipeline = clone $this->pipeline;
$clone->processed = false;
return $clone;
}
/**
* Create an immutable clone with updated output options.
*/
protected function withOutput(Closure $callback): static
{
return $this->withClone(fn (Image $image) => $callback($image->pipeline->output));
}
/**
* Create an immutable clone with the given callback applied.
*/
protected function withClone(Closure $callback): static
{
$clone = $this->newClone();
$callback($clone);
return $clone;
}
/**
* Create an HTTP response that represents the image.
*
* @param \Illuminate\Http\Request $request
*/
public function toResponse($request): Response
{
return new Response($this->toBytes(), 200, [
'Content-Type' => $this->mimeType(),
]);
}
/**
* Prevent serialization of the image.
*
* @throws ImageException
*/
public function __serialize(): never
{
throw new ImageException('Images cannot be serialized. Store the image first and serialize the path instead.');
}
/**
* Get the string representation of the image.
*/
public function toString(): string
{
return $this->toDataUri();
}
/**
* Get the string representation of the image.
*/
public function __toString(): string
{
return $this->toString();
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Illuminate\Image;
use RuntimeException;
class ImageException extends RuntimeException
{
//
}

View file

@ -0,0 +1,170 @@
<?php
namespace Illuminate\Image;
use BackedEnum;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
use Illuminate\Contracts\Image\Driver;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Client\Factory as HttpFactory;
use Illuminate\Http\UploadedFile;
use Illuminate\Image\Drivers\GdDriver;
use Illuminate\Image\Drivers\ImagickDriver;
use Illuminate\Support\Manager;
use InvalidArgumentException;
use function Illuminate\Support\enum_value;
class ImageManager extends Manager
{
/**
* The registered transformation handlers.
*
* @var array<string, array<class-string<\Illuminate\Contracts\Image\Transformation>, callable>>
*/
protected array $transformationHandlers = [];
/**
* Create an image instance from raw bytes.
*/
public function fromBytes(string $contents): Image
{
return new Image($contents);
}
/**
* Create an image instance from a stream.
*
* @param resource $stream
*/
public function fromStream(mixed $stream): Image
{
return new Image(
fn () => stream_get_contents($stream) ?: throw new ImageException('Invalid stream image data.'),
);
}
/**
* Create an image instance from a base64 encoded string.
*/
public function fromBase64(string $base64): Image
{
return new Image(
fn () => base64_decode($base64, true) ?: throw new ImageException('Invalid base64 image data.'),
);
}
/**
* Create an image instance from a file path.
*/
public function fromPath(string $path): Image
{
return new Image(
fn () => $this->container->make(Filesystem::class)->get($path),
);
}
/**
* Create an image instance from a storage disk path.
*/
public function fromStorage(string $path, BackedEnum|string|null $disk = null): Image
{
$disk = enum_value($disk);
return new Image(
fn () => $this->container->make(FilesystemFactory::class)->disk($disk)->get($path),
);
}
/**
* Create an image instance from an uploaded file.
*/
public function fromUpload(UploadedFile $file): Image
{
return new Image(fn () => $file->getContent(), $file);
}
/**
* Create an image instance from a URL.
*/
public function fromUrl(string $url): Image
{
return new Image(
fn () => $this->container->make(HttpFactory::class)->get($url)
->throw()
->body(),
);
}
/**
* Create a new driver instance.
*
* @throws InvalidArgumentException
*/
protected function createDriver($driver): Driver
{
try {
$instance = parent::createDriver($driver);
} catch (InvalidArgumentException $e) {
throw new InvalidArgumentException("Image driver [{$driver}] is not supported.", 0, $e);
}
if (method_exists($instance, 'ensureRequirementsAreMet')) {
$instance->ensureRequirementsAreMet();
}
$this->applyTransformationHandlers($driver, $instance);
return $instance;
}
/**
* Create the GD image driver.
*/
protected function createGdDriver(): GdDriver
{
return new GdDriver;
}
/**
* Create the Imagick image driver.
*/
protected function createImagickDriver(): ImagickDriver
{
return new ImagickDriver;
}
/**
* Register a transformation handler for the given driver.
*
* @param class-string<\Illuminate\Contracts\Image\Transformation> $transformation
*/
public function transformUsing(string $driver, string $transformation, callable $callback): static
{
$this->transformationHandlers[$driver][$transformation] = $callback;
if (isset($this->drivers[$driver])) {
$this->applyTransformationHandlers($driver, $this->drivers[$driver]);
}
return $this;
}
/**
* Apply registered transformation handlers to the given driver instance.
*/
protected function applyTransformationHandlers(string $driver, Driver $instance): void
{
foreach ($this->transformationHandlers[$driver] ?? [] as $transformation => $callback) {
$instance->transformUsing($transformation, $callback);
}
}
/**
* Get the default image driver name.
*/
public function getDefaultDriver(): string
{
return $this->config->get('images.default', 'gd');
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Illuminate\Image;
class ImageOutputOptions
{
/**
* The default output quality.
*/
const DEFAULT_QUALITY = 70;
/**
* The output format.
*
* @var 'webp'|'jpg'|'jpeg'|'png'|'gif'|'avif'|'heic'|'bmp'|null
*/
public ?string $format = null;
/**
* The output quality (1-100).
*
* @var int<1, 100>|null
*/
public ?int $quality = null;
/**
* Determine if any output options have been set.
*/
public function hasChanges(): bool
{
return $this->format !== null || $this->quality !== null;
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace Illuminate\Image;
use Illuminate\Contracts\Image\Transformation;
class ImagePipeline
{
/**
* The ordered image transformations.
*
* @var array<int, \Illuminate\Contracts\Image\Transformation>
*/
public array $transformations = [];
/**
* Create a new image pipeline instance.
*/
public function __construct(public ImageOutputOptions $output = new ImageOutputOptions)
{
//
}
/**
* Add a transformation to the pipeline.
*/
public function add(Transformation $transformation): void
{
$this->transformations[] = $transformation;
}
/**
* Determine if the pipeline has transformations or output changes.
*/
public function hasChanges(): bool
{
return $this->transformations !== [] || $this->output->hasChanges();
}
/**
* Clone the output options with the pipeline.
*/
public function __clone(): void
{
$this->output = clone $this->output;
}
}

View file

@ -0,0 +1,29 @@
<?php
namespace Illuminate\Image;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
class ImageServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->scoped('image', function ($app) {
return new ImageManager($app);
});
}
/**
* Get the services provided by the provider.
*
* @return array<int, string>
*/
public function provides(): array
{
return ['image'];
}
}

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Taylor Otwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,16 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Blur implements Transformation
{
/**
* @param positive-int $amount
*/
public function __construct(public readonly int $amount)
{
//
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Contain implements Transformation
{
/**
* @param positive-int $width
* @param positive-int $height
*/
public function __construct(
public readonly int $width,
public readonly int $height,
public readonly ?string $background = null,
) {
//
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Cover implements Transformation
{
/**
* @param positive-int $width
* @param positive-int $height
*/
public function __construct(
public readonly int $width,
public readonly int $height,
) {
//
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Crop implements Transformation
{
/**
* @param positive-int $width
* @param positive-int $height
*/
public function __construct(
public readonly int $width,
public readonly int $height,
public readonly int $x = 0,
public readonly int $y = 0,
) {
//
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class FlipHorizontally implements Transformation
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class FlipVertically implements Transformation
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Grayscale implements Transformation
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Orient implements Transformation
{
//
}

View file

@ -0,0 +1,19 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Resize implements Transformation
{
/**
* @param positive-int|null $width
* @param positive-int|null $height
*/
public function __construct(
public readonly ?int $width,
public readonly ?int $height,
) {
//
}
}

View file

@ -0,0 +1,15 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Rotate implements Transformation
{
public function __construct(
public readonly float $angle,
public readonly ?string $background = null,
) {
//
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Scale implements Transformation
{
/**
* @param positive-int|null $width
* @param positive-int|null $height
*/
public function __construct(
public readonly ?int $width,
public readonly ?int $height,
) {
//
}
}

View file

@ -0,0 +1,16 @@
<?php
namespace Illuminate\Image\Transformations;
use Illuminate\Contracts\Image\Transformation;
class Sharpen implements Transformation
{
/**
* @param positive-int $amount
*/
public function __construct(public readonly int $amount)
{
//
}
}

View file

@ -0,0 +1,44 @@
{
"name": "illuminate/image",
"description": "The Illuminate Image package.",
"license": "MIT",
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"require": {
"php": "^8.3",
"illuminate/conditionable": "^13.0",
"illuminate/container": "^13.0",
"illuminate/contracts": "^13.0",
"illuminate/filesystem": "^13.0",
"illuminate/http": "^13.0",
"illuminate/macroable": "^13.0",
"illuminate/support": "^13.0"
},
"suggest": {
"ext-fileinfo": "Required to use the Image class.",
"intervention/image": "Required to use the GD and Imagick image drivers (^4.0)."
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Illuminate\\Image\\": ""
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "13.0.x-dev"
}
}
}