Skip to content

Commit

Permalink
Add ImageManager interface (#1336)
Browse files Browse the repository at this point in the history
adamaveray authored Apr 26, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
1 parent 33cbb21 commit 8e00dd3
Showing 2 changed files with 78 additions and 40 deletions.
50 changes: 10 additions & 40 deletions src/ImageManager.php
Original file line number Diff line number Diff line change
@@ -4,14 +4,14 @@

namespace Intervention\Image;

use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageManagerInterface;

final class ImageManager
final class ImageManager implements ImageManagerInterface
{
protected DriverInterface $driver;

@@ -59,47 +59,19 @@ public static function imagick(): self
}

/**
* Create new image instance with given width & height
* {@inheritdoc}
*
* @link https://image.intervention.io/v3/basics/instantiation#creating-new-images
* @param int $width
* @param int $height
* @throws RuntimeException
* @return ImageInterface
* @see ImageManagerInterface::create()
*/
public function create(int $width, int $height): ImageInterface
{
return $this->driver->createImage($width, $height);
}

/**
* Create new image instance from given input which can be one of the following
* {@inheritdoc}
*
* - Path in filesystem
* - File Pointer resource
* - SplFileInfo object
* - Raw binary image data
* - Base64 encoded image data
* - Data Uri
* - Intervention\Image\Image Instance
*
* To decode the raw input data, you can optionally specify a decoding strategy
* with the second parameter. This can be an array of class names or objects
* of decoders to be processed in sequence. In this case, the input must be
* decodedable with one of the decoders passed. It is also possible to pass
* a single object or class name of a decoder.
*
* All decoders that implement the `DecoderInterface::class` can be passed. Usually
* a selection of classes of the namespace `Intervention\Image\Decoders`
*
* If the second parameter is not set, an attempt to decode the input is made
* with all available decoders of the driver.
*
* @link https://image.intervention.io/v3/basics/instantiation#reading-images
* @param mixed $input
* @param string|array|DecoderInterface $decoders
* @throws RuntimeException
* @return ImageInterface
* @see ImageManagerInterface::read()
*/
public function read(mixed $input, string|array|DecoderInterface $decoders = []): ImageInterface
{
@@ -113,21 +85,19 @@ public function read(mixed $input, string|array|DecoderInterface $decoders = [])
}

/**
* Create new animated image by given callback
* {@inheritdoc}
*
* @link https://image.intervention.io/v3/basics/instantiation#creating-animations
* @param callable $init
* @return ImageInterface
* @see ImageManagerInterface::animate()
*/
public function animate(callable $init): ImageInterface
{
return $this->driver->createAnimation($init);
}

/**
* Return currently used driver
* {@inheritdoc}
*
* @return DriverInterface
* @see ImageManagerInterface::driver()
*/
public function driver(): DriverInterface
{
68 changes: 68 additions & 0 deletions src/Interfaces/ImageManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Intervention\Image\Interfaces;

use Intervention\Image\Exceptions\RuntimeException;

interface ImageManagerInterface
{
/**
* Create new image instance with given width & height
*
* @link https://image.intervention.io/v3/basics/instantiation#creating-new-images
* @param int $width
* @param int $height
* @throws RuntimeException
* @return ImageInterface
*/
public function create(int $width, int $height): ImageInterface;

/**
* Create new image instance from given input which can be one of the following
*
* - Path in filesystem
* - File Pointer resource
* - SplFileInfo object
* - Raw binary image data
* - Base64 encoded image data
* - Data Uri
* - Intervention\Image\Image Instance
*
* To decode the raw input data, you can optionally specify a decoding strategy
* with the second parameter. This can be an array of class names or objects
* of decoders to be processed in sequence. In this case, the input must be
* decodedable with one of the decoders passed. It is also possible to pass
* a single object or class name of a decoder.
*
* All decoders that implement the `DecoderInterface::class` can be passed. Usually
* a selection of classes of the namespace `Intervention\Image\Decoders`
*
* If the second parameter is not set, an attempt to decode the input is made
* with all available decoders of the driver.
*
* @link https://image.intervention.io/v3/basics/instantiation#reading-images
* @param mixed $input
* @param string|array|DecoderInterface $decoders
* @throws RuntimeException
* @return ImageInterface
*/
public function read(mixed $input, string|array|DecoderInterface $decoders = []): ImageInterface;

/**
* Create new animated image by given callback
*
* @link https://image.intervention.io/v3/basics/instantiation#creating-animations
* @param callable $init
* @return ImageInterface
*/
public function animate(callable $init): ImageInterface;

/**
* Return currently used driver
*
* @return DriverInterface
*/
public function driver(): DriverInterface;
}

0 comments on commit 8e00dd3

Please sign in to comment.