charger une image

This commit is contained in:
2026-01-09 10:51:56 +01:00
parent d0f4ed4eb2
commit e5714b47c6
518 changed files with 40175 additions and 44 deletions

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface AnalyzerInterface
{
/**
* Analyze given image and return the retrieved data
*
* @throws RuntimeException
*/
public function analyze(ImageInterface $image): mixed;
}

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Traversable;
/**
* @extends Traversable<int|string, mixed>
*/
interface CollectionInterface extends Traversable
{
/**
* Determine if the collection has item at given key
*/
public function has(int|string $key): bool;
/**
* Add item to collection
*
* @return CollectionInterface<int|string, mixed>
*/
public function push(mixed $item): self;
/**
* Return item for given key or return default is key does not exist
*/
public function get(int|string $key, mixed $default = null): mixed;
/**
* Return item at given numeric position starting at 0
*/
public function getAtPosition(int $key = 0, mixed $default = null): mixed;
/**
* Return first item in collection
*/
public function first(): mixed;
/**
* Return last item in collection
*/
public function last(): mixed;
/**
* Return item count of collection
*/
public function count(): int;
/**
* Empty collection
*
* @return CollectionInterface<int|string, mixed>
*/
public function empty(): self;
/**
* Transform collection as array
*
* @return array<int|string, mixed>
*/
public function toArray(): array;
/**
* Extract items based on given values and discard the rest.
*
* @return CollectionInterface<int|string, mixed>
*/
public function slice(int $offset, ?int $length = 0): self;
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
interface ColorChannelInterface
{
/**
* Create new instance by either value or normalized value
*
* @throws ColorException
*/
public function __construct(?int $value = null, ?float $normalized = null);
/**
* Return color channels integer value
*/
public function value(): int;
/**
* Return the channels value normalized to a float value form 0 to 1 by its range
*/
public function normalize(int $precision = 32): float;
/**
* Throw exception if the given value is not applicable for channel
* otherwise the value is returned unchanged.
*
* @throws ColorException
*/
public function validate(mixed $value): mixed;
/**
* Return the the minimal possible value of the color channel
*/
public function min(): int;
/*
* Return the the maximal possible value of the color channel
*
* @return int
*/
public function max(): int;
/**
* Cast color channel's value to string
*/
public function toString(): string;
/**
* Cast color channel's value to string
*/
public function __toString(): string;
}

View File

@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\RuntimeException;
interface ColorInterface
{
/**
* Static color factory method that takes any supported color format
* and returns a corresponding color object
*
* @throws RuntimeException
*/
public static function create(mixed $input): self;
/**
* Return colorspace of current color
*/
public function colorspace(): ColorspaceInterface;
/**
* Cast color object to string
*/
public function toString(): string;
/**
* Cast color object to array
*
* @return array<int>
*/
public function toArray(): array;
/**
* Cast color object to hex encoded web color
*/
public function toHex(string $prefix = ''): string;
/**
* Return array of all color channels
*
* @return array<ColorChannelInterface>
*/
public function channels(): array;
/**
* Return array of normalized color channel values
*
* @return array<float>
*/
public function normalize(): array;
/**
* Retrieve the color channel by its classname
*
* @throws ColorException
*/
public function channel(string $classname): ColorChannelInterface;
/**
* Convert color to given colorspace
*/
public function convertTo(string|ColorspaceInterface $colorspace): self;
/**
* Determine if the current color is gray
*/
public function isGreyscale(): bool;
/**
* Determine if the current color is (semi) transparent
*/
public function isTransparent(): bool;
/**
* Determine whether the current color is completely transparent
*/
public function isClear(): bool;
/**
* Cast color object to string
*/
public function __toString(): string;
}

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
interface ColorProcessorInterface
{
/**
* Turn given color in the driver's color implementation
*
* @throws ColorException
*/
public function colorToNative(ColorInterface $color): mixed;
/**
* Turn the given driver's definition of a color into a color object
*
* @throws ColorException
*/
public function nativeToColor(mixed $native): ColorInterface;
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface ColorspaceInterface
{
/**
* Convert given color to the format of the current colorspace
*/
public function importColor(ColorInterface $color): ColorInterface;
/**
* Create new color in colorspace from given normalized channel values
*
* @param array<float> $normalized
*/
public function colorFromNormalized(array $normalized): ColorInterface;
}

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\AnimationException;
interface CoreInterface extends CollectionInterface
{
/**
* return driver's representation of the image core.
*
* @throws AnimationException
*/
public function native(): mixed;
/**
* Set driver's representation of the image core.
*
* @return CoreInterface<FrameInterface>
*/
public function setNative(mixed $native): self;
/**
* Count number of frames of animated image core
*/
public function count(): int;
/**
* Return frame of given position in an animated image
*
* @throws AnimationException
*/
public function frame(int $position): FrameInterface;
/**
* Add new frame to core
*
* @return CoreInterface<FrameInterface>
*/
public function add(FrameInterface $frame): self;
/**
* Return number of repetitions of an animated image
*/
public function loops(): int;
/**
* Set the number of repetitions for an animation. Where a
* value of 0 means infinite repetition.
*
* @return CoreInterface<FrameInterface>
*/
public function setLoops(int $loops): self;
/**
* Get first frame in core
*
* @throws AnimationException
*/
public function first(): FrameInterface;
/**
* Get last frame in core
*
* @throws AnimationException
*/
public function last(): FrameInterface;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface DecoderInterface
{
/**
* Decode given input either to color or image
*
* @throws RuntimeException
*/
public function decode(mixed $input): ImageInterface|ColorInterface;
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Closure;
interface DrawableFactoryInterface
{
/**
* Create a new factory instance statically
*/
public static function init(null|Closure|DrawableInterface $init = null): self;
/**
* Create the end product of the factory
*/
public function create(): DrawableInterface;
/**
* Define the background color of the drawable object
*/
public function background(mixed $color): self;
/**
* Set the border size & color of the drawable object to be produced
*/
public function border(mixed $color, int $size = 1): self;
/**
* Create the end product by invoking the factory
*/
public function __invoke(): DrawableInterface;
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface DrawableInterface
{
/**
* Position of the drawable object
*/
public function position(): PointInterface;
/**
* Set position of the drawable object
*/
public function setPosition(PointInterface $position): self;
/**
* Set the background color of the drawable object
*/
public function setBackgroundColor(mixed $color): self;
/**
* Return background color of drawable object
*/
public function backgroundColor(): mixed;
/**
* Determine if a background color was set
*/
public function hasBackgroundColor(): bool;
/**
* Set border color & size of the drawable object
*/
public function setBorder(mixed $color, int $size = 1): self;
/**
* Set border size of the drawable object
*/
public function setBorderSize(int $size): self;
/**
* Set border color of the drawable object
*/
public function setBorderColor(mixed $color): self;
/**
* Get border size
*/
public function borderSize(): int;
/**
* Get border color of drawable object
*/
public function borderColor(): mixed;
/**
* Determine if the drawable object has a border
*/
public function hasBorder(): bool;
}

View File

@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Config;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\FileExtension;
use Intervention\Image\Format;
use Intervention\Image\MediaType;
interface DriverInterface
{
/**
* Return drivers unique id
*/
public function id(): string;
/**
* Get driver configuration
*/
public function config(): Config;
/**
* Resolve given (generic) object into a specialized version for the current driver
*
* @throws NotSupportedException
* @throws DriverException
*/
public function specialize(
ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface $object
): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface;
/**
* Resolve array of classnames or objects into their specialized version for the current driver
*
* @param array<string|object> $objects
* @throws NotSupportedException
* @throws DriverException
* @return array<object>
*/
public function specializeMultiple(array $objects): array;
/**
* Create new image instance with the current driver in given dimensions
*
* @throws RuntimeException
*/
public function createImage(int $width, int $height): ImageInterface;
/**
* Create new animated image
*
* @throws RuntimeException
*/
public function createAnimation(callable $init): ImageInterface;
/**
* Handle given input by decoding it to ImageInterface or ColorInterface
*
* @param array<string|DecoderInterface> $decoders
* @throws RuntimeException
*/
public function handleInput(mixed $input, array $decoders = []): ImageInterface|ColorInterface;
/**
* Return color processor for the given colorspace
*/
public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface;
/**
* Return font processor of the current driver
*/
public function fontProcessor(): FontProcessorInterface;
/**
* Check whether all requirements for operating the driver are met and
* throw exception if the check fails.
*
* @throws DriverException
*/
public function checkHealth(): void;
/**
* Check if the current driver supports the given format and if the
* underlying PHP extension was built with support for the format.
*/
public function supports(string|Format|FileExtension|MediaType $identifier): bool;
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface EncodedImageInterface extends FileInterface
{
/**
* Return Media (MIME) Type of encoded image
*/
public function mediaType(): string;
/**
* Alias of self::mediaType()
*/
public function mimetype(): string;
/**
* Transform encoded image data into an data uri string
*/
public function toDataUri(): string;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface EncoderInterface
{
/**
* Encode given image
*
* @throws RuntimeException
*/
public function encode(ImageInterface $image): EncodedImageInterface;
}

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface FileInterface
{
/**
* Save data in given path in file system
*
* @throws RuntimeException
*/
public function save(string $filepath): void;
/**
* Create file pointer from encoded data
*
* @return resource
*/
public function toFilePointer();
/**
* Return size in bytes
*/
public function size(): int;
/**
* Turn encoded data into string
*/
public function toString(): string;
/**
* Cast encoded data into string
*/
public function __toString(): string;
}

View File

@@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\FontException;
interface FontInterface
{
/**
* Set color of font
*/
public function setColor(mixed $color): self;
/**
* Get color of font
*/
public function color(): mixed;
/**
* Set stroke color of font
*/
public function setStrokeColor(mixed $color): self;
/**
* Get stroke color of font
*/
public function strokeColor(): mixed;
/**
/**
* Set stroke width of font
*
* @throws FontException
*/
public function setStrokeWidth(int $width): self;
/**
* Get stroke width of font
*/
public function strokeWidth(): int;
/**
* Determine if the font is drawn with outline stroke effect
*/
public function hasStrokeEffect(): bool;
/**
* Set font size
*/
public function setSize(float $size): self;
/**
* Get font size
*/
public function size(): float;
/**
* Set rotation angle of font
*/
public function setAngle(float $angle): self;
/**
* Get rotation angle of font
*/
public function angle(): float;
/**
* Set font filename
*/
public function setFilename(string $filename): self;
/**
* Get font filename
*/
public function filename(): ?string;
/**
* Determine if font has a corresponding filename
*/
public function hasFilename(): bool;
/**
* Set horizontal alignment of font
*/
public function setAlignment(string $align): self;
/**
* Get horizontal alignment of font
*/
public function alignment(): string;
/**
* Set vertical alignment of font
*/
public function setValignment(string $align): self;
/**
* Get vertical alignment of font
*/
public function valignment(): string;
/**
* Set typographical line height
*/
public function setLineHeight(float $value): self;
/**
* Get line height of font
*/
public function lineHeight(): float;
/**
* Set the wrap width with which the text is rendered
*/
public function setWrapWidth(?int $width): self;
/**
* Get wrap width with which the text is rendered
*/
public function wrapWidth(): ?int;
}

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Typography\TextBlock;
interface FontProcessorInterface
{
/**
* Calculate size of bounding box of given text in conjunction with the given font
*
* @throws FontException
*/
public function boxSize(string $text, FontInterface $font): SizeInterface;
/**
* Build TextBlock object from text string and align every line according
* to text modifier's font object and position.
*
* @throws FontException
*/
public function textBlock(string $text, FontInterface $font, PointInterface $position): TextBlock;
/**
* Calculate the actual font size to pass at the driver level
*/
public function nativeFontSize(FontInterface $font): float;
/**
* Calculate the typographical font size in pixels
*
* @throws FontException
*/
public function typographicalSize(FontInterface $font): int;
/**
* Calculates typographical cap height
*
* @throws FontException
*/
public function capHeight(FontInterface $font): int;
/**
* Calculates typographical leading size
*
* @throws FontException
*/
public function leading(FontInterface $font): int;
}

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface FrameInterface
{
/**
* Return image data of frame in driver specific format
*/
public function native(): mixed;
/**
* Set image data of drame in driver specific format
*/
public function setNative(mixed $native): self;
/**
* Transform frame into an image
*
* @throws RuntimeException
*/
public function toImage(DriverInterface $driver): ImageInterface;
/**
* Get image size of current frame
*/
public function size(): SizeInterface;
/**
* Return animation delay of current frame in seconds
*/
public function delay(): float;
/**
* Set animation frame delay in seoncds
*/
public function setDelay(float $delay): self;
/**
* Get disposal method of current frame
*/
public function dispose(): int;
/**
* Set disposal method of current frame
*/
public function setDispose(int $dispose): self;
/**
* Set pixel offset of current frame
*/
public function setOffset(int $left, int $top): self;
/**
* Get left offset in pixels
*/
public function offsetLeft(): int;
/**
* Set left pixel offset for current frame
*/
public function setOffsetLeft(int $offset): self;
/**
* Get top pixel offset of current frame
*/
public function offsetTop(): int;
/**
* Set top pixel offset of current frame
*/
public function setOffsetTop(int $offset): self;
}

View File

@@ -0,0 +1,771 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Closure;
use Countable;
use Intervention\Image\Encoders\AutoEncoder;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\FileExtension;
use Intervention\Image\Geometry\Bezier;
use Intervention\Image\Geometry\Circle;
use Intervention\Image\Geometry\Ellipse;
use Intervention\Image\Geometry\Line;
use Intervention\Image\Geometry\Polygon;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\MediaType;
use Intervention\Image\Origin;
use IteratorAggregate;
/**
* @extends IteratorAggregate<FrameInterface>
*/
interface ImageInterface extends IteratorAggregate, Countable
{
/**
* Return driver of current image
*/
public function driver(): DriverInterface;
/**
* Return core of current image
*/
public function core(): CoreInterface;
/**
* Return the origin of the image
*/
public function origin(): Origin;
/**
* Set the origin of the image
*/
public function setOrigin(Origin $origin): self;
/**
* Return width of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#read-the-pixel-width
*
* @throws RuntimeException
*/
public function width(): int;
/**
* Return height of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#read-the-pixel-height
*
* @throws RuntimeException
*/
public function height(): int;
/**
* Return size of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#read-the-image-size-as-an-object
*
* @throws RuntimeException
*/
public function size(): SizeInterface;
/**
* Encode image with given encoder
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images
*
* @throws RuntimeException
*/
public function encode(EncoderInterface $encoder = new AutoEncoder()): EncodedImageInterface;
/**
* Save the image to the specified path in the file system. If no path is
* given, the image will be saved at its original location.
*
* @link https://image.intervention.io/v3/basics/image-output#encode--save-combined
*
* @throws RuntimeException
*/
public function save(?string $path = null, mixed ...$options): self;
/**
* Apply given modifier to current image
*
* @link https://image.intervention.io/v3/modifying-images/custom-modifiers
*
* @throws RuntimeException
*/
public function modify(ModifierInterface $modifier): self;
/**
* Analyzer current image with given analyzer
*
* @throws RuntimeException
*/
public function analyze(AnalyzerInterface $analyzer): mixed;
/**
* Determine if current image is animated
*
* @link https://image.intervention.io/v3/modifying-images/animations#check-the-current-image-instance-for-animation
*/
public function isAnimated(): bool;
/**
* Remove all frames but keep the one at the specified position
*
* It is possible to specify the position as integer or string values.
* With the former, the exact position passed is searched for, while
* string values must represent a percentage value between '0%' and '100%'
* and the respective frame position is only determined approximately.
*
* @link https://image.intervention.io/v3/modifying-images/animations#remove-animation
*
* @throws RuntimeException
*/
public function removeAnimation(int|string $position = 0): self;
/**
* Extract animation frames based on given values and discard the rest
*
* @link https://image.intervention.io/v3/modifying-images/animations#change-the-animation-iteration-count
*
* @throws RuntimeException
*/
public function sliceAnimation(int $offset = 0, ?int $length = null): self;
/**
* Return loop count of animated image
*
* @link https://image.intervention.io/v3/modifying-images/animations#read-the-animation-iteration-count
*/
public function loops(): int;
/**
* Set loop count of animated image
*
* @link https://image.intervention.io/v3/modifying-images/animations#change-the-animation-iteration-count
*/
public function setLoops(int $loops): self;
/**
* Return exif data of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#exif-information
*/
public function exif(?string $query = null): mixed;
/**
* Set exif data for the image object
*/
public function setExif(CollectionInterface $exif): self;
/**
* Return image resolution/density
*
* @link https://image.intervention.io/v3/basics/meta-information#image-resolution
*
* @throws RuntimeException
*/
public function resolution(): ResolutionInterface;
/**
* Set image resolution
*
* @link https://image.intervention.io/v3/basics/meta-information#image-resolution
*
* @throws RuntimeException
*/
public function setResolution(float $x, float $y): self;
/**
* Get the colorspace of the image
*
* @link https://image.intervention.io/v3/basics/colors#read-the-image-colorspace
*
* @throws RuntimeException
*/
public function colorspace(): ColorspaceInterface;
/**
* Transform image to given colorspace
*
* @link https://image.intervention.io/v3/basics/colors#change-the-image-colorspace
*
* @throws RuntimeException
*/
public function setColorspace(string|ColorspaceInterface $colorspace): self;
/**
* Return color of pixel at given position on given frame position
*
* @link https://image.intervention.io/v3/basics/colors#color-information
*
* @throws RuntimeException
*/
public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface;
/**
* Return all colors of pixel at given position for all frames of image
*
* @link https://image.intervention.io/v3/basics/colors#color-information
*
* @throws RuntimeException
*/
public function pickColors(int $x, int $y): CollectionInterface;
/**
* Return color that is mixed with transparent areas when converting to a format which
* does not support transparency.
*
* @throws RuntimeException
*/
public function blendingColor(): ColorInterface;
/**
* Set blending color will have no effect unless image is converted into a format
* which does not support transparency.
*
* @throws RuntimeException
*/
public function setBlendingColor(mixed $color): self;
/**
* Replace transparent areas of the image with given color
*
* @throws RuntimeException
*/
public function blendTransparency(mixed $color = null): self;
/**
* Retrieve ICC color profile of image
*
* @link https://image.intervention.io/v3/basics/colors#color-profiles
*
* @throws RuntimeException
*/
public function profile(): ProfileInterface;
/**
* Set given icc color profile to image
*
* @link https://image.intervention.io/v3/basics/colors#color-profiles
*
* @throws RuntimeException
*/
public function setProfile(ProfileInterface $profile): self;
/**
* Remove ICC color profile from the current image
*
* @link https://image.intervention.io/v3/basics/colors#color-profiles
*
* @throws RuntimeException
*/
public function removeProfile(): self;
/**
* Apply color quantization to the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#reduce-colors
*
* @throws RuntimeException
*/
public function reduceColors(int $limit, mixed $background = 'transparent'): self;
/**
* Sharpen the current image with given strength
*
* @link https://image.intervention.io/v3/modifying-images/effects#sharpening-effect
*
* @throws RuntimeException
*/
public function sharpen(int $amount = 10): self;
/**
* Turn image into a greyscale version
*
* @link https://image.intervention.io/v3/modifying-images/effects#convert-image-to-a-greyscale-version
*
* @throws RuntimeException
*/
public function greyscale(): self;
/**
* Adjust brightness of the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#change-the-image-brightness
*
* @throws RuntimeException
*/
public function brightness(int $level): self;
/**
* Adjust color contrast of the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#change-the-image-contrast
*
* @throws RuntimeException
*/
public function contrast(int $level): self;
/**
* Apply gamma correction on the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#gamma-correction
*
* @throws RuntimeException
*/
public function gamma(float $gamma): self;
/**
* Adjust the intensity of the RGB color channels
*
* @link https://image.intervention.io/v3/modifying-images/effects#color-correction
*
* @throws RuntimeException
*/
public function colorize(int $red = 0, int $green = 0, int $blue = 0): self;
/**
* Mirror the current image vertically by swapping top and bottom
*
* @link https://image.intervention.io/v3/modifying-images/effects#mirror-image-vertically
*
* @throws RuntimeException
*/
public function flip(): self;
/**
* Mirror the current image horizontally by swapping left and right
*
* @link https://image.intervention.io/v3/modifying-images/effects#mirror-image-horizontally
*
* @throws RuntimeException
*/
public function flop(): self;
/**
* Blur current image by given strength
*
* @link https://image.intervention.io/v3/modifying-images/effects#blur-effect
*
* @throws RuntimeException
*/
public function blur(int $amount = 5): self;
/**
* Invert the colors of the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#invert-colors
*
* @throws RuntimeException
*/
public function invert(): self;
/**
* Apply pixelation filter effect on current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#pixelation-effect
*
* @throws RuntimeException
*/
public function pixelate(int $size): self;
/**
* Rotate current image by given angle
*
* @link https://image.intervention.io/v3/modifying-images/effects#image-rotation
*
* @param string $background
* @throws RuntimeException
*/
public function rotate(float $angle, mixed $background = 'ffffff'): self;
/**
* Rotate the image to be upright according to exif information
*
* @link https://image.intervention.io/v3/modifying-images/effects#image-orientation-according-to-exif-data
*
* @throws RuntimeException
*/
public function orient(): self;
/**
* Draw text on image
*
* @link https://image.intervention.io/v3/modifying-images/text-fonts
*
* @throws RuntimeException
*/
public function text(string $text, int $x, int $y, callable|Closure|FontInterface $font): self;
/**
* Resize image to the given width and/or height
*
* @link https://image.intervention.io/v3/modifying-images/resizing#simple-image-resizing
*
* @throws RuntimeException
*/
public function resize(?int $width = null, ?int $height = null): self;
/**
* Resize image to the given width and/or height without exceeding the original dimensions
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-without-exceeding-the-original-size
*
* @throws RuntimeException
*/
public function resizeDown(?int $width = null, ?int $height = null): self;
/**
* Resize image to the given width and/or height and keep the original aspect ratio
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-images-proportionally
*
* @throws RuntimeException
*/
public function scale(?int $width = null, ?int $height = null): self;
/**
* Resize image to the given width and/or height, keep the original aspect ratio
* and do not exceed the original image width or height
*
* @link https://image.intervention.io/v3/modifying-images/resizing#scale-images-but-do-not-exceed-the-original-size
*
* @throws RuntimeException
*/
public function scaleDown(?int $width = null, ?int $height = null): self;
/**
* Takes the specified width and height and scales them to the largest
* possible size that fits within the original size. This scaled size is
* then positioned on the original and cropped, before this result is resized
* to the desired size using the arguments
*
* @link https://image.intervention.io/v3/modifying-images/resizing#cropping--resizing-combined
*
* @throws RuntimeException
*/
public function cover(int $width, int $height, string $position = 'center'): self;
/**
* Same as cover() but do not exceed the original image size
*
* @link https://image.intervention.io/v3/modifying-images/resizing#fitted-resizing-without-exceeding-the-original-size
*
* @throws RuntimeException
*/
public function coverDown(int $width, int $height, string $position = 'center'): self;
/**
* Resize the boundaries of the current image to given width and height.
* An anchor position can be defined to determine where the original image
* is fixed. A background color can be passed to define the color of the
* new emerging areas.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-image-boundaries-without-resampling-the-original-image
*
* @throws RuntimeException
*/
public function resizeCanvas(
?int $width = null,
?int $height = null,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* Resize canvas in the same way as resizeCanvas() but takes relative values
* for the width and height, which will be added or subtracted to the
* original image size.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-image-boundaries-relative-to-the-original
*
* @throws RuntimeException
*/
public function resizeCanvasRelative(
?int $width = null,
?int $height = null,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* Padded resizing means that the original image is scaled until it fits the
* defined target size with unchanged aspect ratio. The original image is
* not scaled up but only down.
*
* Compared to the cover() method, this method does not create cropped areas,
* but possibly new empty areas on the sides of the result image. These are
* filled with the specified background color.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resizing--padding-combined
*
* @param string $background
* @throws RuntimeException
*/
public function pad(
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* This method does the same as pad(), but the original image is also scaled
* up if the target size exceeds the original size.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#padded-resizing-with-upscaling
*
* @param string $background
* @throws RuntimeException
*/
public function contain(
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* Cut out a rectangular part of the current image with given width and
* height at a given position. Define optional x,y offset coordinates
* to move the cutout by the given amount of pixels.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#cut-out-a-rectangular-part
*
* @throws RuntimeException
*/
public function crop(
int $width,
int $height,
int $offset_x = 0,
int $offset_y = 0,
mixed $background = 'ffffff',
string $position = 'top-left'
): self;
/**
* Trim the image by removing border areas of similar color within a the given tolerance
*
* @link https://image.intervention.io/v3/modifying-images/resizing#remove-border-areas-in-similar-color
*
* @throws RuntimeException
* @throws AnimationException
*/
public function trim(int $tolerance = 0): self;
/**
* Place another image into the current image instance
*
* @link https://image.intervention.io/v3/modifying-images/inserting#insert-images
*
* @throws RuntimeException
*/
public function place(
mixed $element,
string $position = 'top-left',
int $offset_x = 0,
int $offset_y = 0,
int $opacity = 100
): self;
/**
* Fill image with given color
*
* If an optional position is specified for the filling process ln the form
* of x and y coordinates, the process is executed as flood fill. This means
* that the color at the specified position is taken as a reference and all
* adjacent pixels are also filled with the filling color.
*
* If no coordinates are specified, the entire image area is filled.
*
* @link https://image.intervention.io/v3/modifying-images/drawing#fill-images-with-color
*
* @throws RuntimeException
*/
public function fill(mixed $color, ?int $x = null, ?int $y = null): self;
/**
* Draw a single pixel at given position defined by the coordinates x and y in a given color.
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-pixels
*
* @throws RuntimeException
*/
public function drawPixel(int $x, int $y, mixed $color): self;
/**
* Draw a rectangle on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-rectangle
*
* @throws RuntimeException
*/
public function drawRectangle(int $x, int $y, callable|Closure|Rectangle $init): self;
/**
* Draw ellipse on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-ellipses
*
* @throws RuntimeException
*/
public function drawEllipse(int $x, int $y, callable|Closure|Ellipse $init): self;
/**
* Draw circle on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-circle
*
* @throws RuntimeException
*/
public function drawCircle(int $x, int $y, callable|Closure|Circle $init): self;
/**
* Draw a polygon on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-polygon
*
* @throws RuntimeException
*/
public function drawPolygon(callable|Closure|Polygon $init): self;
/**
* Draw a line on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-line
*
* @throws RuntimeException
*/
public function drawLine(callable|Closure|Line $init): self;
/**
* Draw a bezier curve on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-bezier-curves
*
* @throws RuntimeException
*/
public function drawBezier(callable|Closure|Bezier $init): self;
/**
* Encode image to given media (mime) type. If no type is given the image
* will be encoded to the format of the originally read image.
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images-by-media-mime-type
*
* @throws RuntimeException
*/
public function encodeByMediaType(null|string|MediaType $type = null, mixed ...$options): EncodedImageInterface;
/**
* Encode the image into the format represented by the given extension. If no
* extension is given the image will be encoded to the format of the
* originally read image.
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images-by-file-extension
*
* @throws RuntimeException
*/
public function encodeByExtension(
null|string|FileExtension $extension = null,
mixed ...$options
): EncodedImageInterface;
/**
* Encode the image into the format represented by the given extension of
* the given file path extension is given the image will be encoded to
* the format of the originally read image.
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images-by-file-path
*
* @throws RuntimeException
*/
public function encodeByPath(?string $path = null, mixed ...$options): EncodedImageInterface;
/**
* Encode image to JPEG format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-jpeg-format
*
* @throws RuntimeException
*/
public function toJpeg(mixed ...$options): EncodedImageInterface;
/**
* Encode image to Jpeg2000 format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-jpeg-2000-format
*
* @throws RuntimeException
*/
public function toJpeg2000(mixed ...$options): EncodedImageInterface;
/**
* Encode image to Webp format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-webp-format
*
* @throws RuntimeException
*/
public function toWebp(mixed ...$options): EncodedImageInterface;
/**
* Encode image to PNG format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-png-format
*
* @throws RuntimeException
*/
public function toPng(mixed ...$options): EncodedImageInterface;
/**
* Encode image to GIF format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-gif-format
*
* @throws RuntimeException
*/
public function toGif(mixed ...$options): EncodedImageInterface;
/**
* Encode image to Bitmap format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-windows-bitmap-format
*
* @throws RuntimeException
*/
public function toBitmap(mixed ...$options): EncodedImageInterface;
/**
* Encode image to AVIF format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-av1-image-file-format-avif
*
* @throws RuntimeException
*/
public function toAvif(mixed ...$options): EncodedImageInterface;
/**
* Encode image to TIFF format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-tiff-format
*
* @throws RuntimeException
*/
public function toTiff(mixed ...$options): EncodedImageInterface;
/**
* Encode image to HEIC format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-heic-format
*
* @throws RuntimeException
*/
public function toHeic(mixed ...$options): EncodedImageInterface;
}

View File

@@ -0,0 +1,63 @@
<?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#create-new-images
*
* @throws RuntimeException
*/
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#read-image-sources
*
* @param string|array<string|DecoderInterface>|DecoderInterface $decoders
* @throws RuntimeException
*/
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#create-animations
*
* @throws RuntimeException
*/
public function animate(callable $init): ImageInterface;
/**
* Return currently used driver
*/
public function driver(): DriverInterface;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface InputHandlerInterface
{
/**
* Try to decode the given input with each decoder of the the handler chain
*
* @throws RuntimeException
*/
public function handle(mixed $input): ImageInterface|ColorInterface;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface ModifierInterface
{
/**
* Apply modifications of the current modifier to the given image
*
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface;
}

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface PointInterface
{
/**
* Return x position
*/
public function x(): int;
/**
* Return y position
*/
public function y(): int;
/**
* Set x position
*/
public function setX(int $x): self;
/**
* Set y position
*/
public function setY(int $y): self;
/**
* Move X coordinate
*/
public function moveX(int $value): self;
/**
* Move Y coordinate
*/
public function moveY(int $value): self;
/**
* Move position of current point by given coordinates
*/
public function move(int $x, int $y): self;
/**
* Set position of point
*/
public function setPosition(int $x, int $y): self;
/**
* Rotate point counter clock wise around given pivot point
*/
public function rotate(float $angle, self $pivot): self;
}

View File

@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface ProfileInterface
{
/**
* Cast color profile object to string
*/
public function __toString(): string;
}

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface ResolutionInterface
{
/**
* Return resolution of x-axis
*/
public function x(): float;
/**
* Set resolution on x-axis
*/
public function setX(float $x): self;
/**
* Return resolution on y-axis
*/
public function y(): float;
/**
* Set resolution on y-axis
*/
public function setY(float $y): self;
/**
* Convert the resolution to DPI
*/
public function perInch(): self;
/**
* Convert the resolution to DPCM
*/
public function perCm(): self;
/**
* Return string representation of unit
*/
public function unit(): string;
/**
* Transform object to string
*/
public function toString(): string;
/**
* Cast object to string
*/
public function __toString(): string;
}

View File

@@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\GeometryException;
interface SizeInterface
{
/**
* Get width
*/
public function width(): int;
/**
* Get height
*/
public function height(): int;
/**
* Get pivot point
*/
public function pivot(): PointInterface;
/**
* Set width
*/
public function setWidth(int $width): self;
/**
* Set height
*/
public function setHeight(int $height): self;
/**
* Set pivot point
*/
public function setPivot(PointInterface $pivot): self;
/**
* Calculate aspect ratio of the current size
*/
public function aspectRatio(): float;
/**
* Determine if current size fits into given size
*/
public function fitsInto(self $size): bool;
/**
* Determine if size is in landscape format
*/
public function isLandscape(): bool;
/**
* Determine if size is in portrait format
*/
public function isPortrait(): bool;
/**
* Move pivot to given position in size
*/
public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0): self;
/**
* Align pivot of current object to given position
*/
public function alignPivotTo(self $size, string $position): self;
/**
* Calculate the relative position to another Size
* based on the pivot point settings of both sizes.
*/
public function relativePositionTo(self $size): PointInterface;
/**
* @see ImageInterface::resize()
*
* @throws GeometryException
*/
public function resize(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::resizeDown()
*
* @throws GeometryException
*/
public function resizeDown(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::scale()
*
* @throws GeometryException
*/
public function scale(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::scaleDown()
*
* @throws GeometryException
*/
public function scaleDown(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::cover()
*
* @throws GeometryException
*/
public function cover(int $width, int $height): self;
/**
* @see ImageInterface::contain()
*
* @throws GeometryException
*/
public function contain(int $width, int $height): self;
/**
* @throws GeometryException
*/
public function containMax(int $width, int $height): self;
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\DriverException;
interface SpecializableInterface
{
/**
* Return an array of constructor parameters, which is usually passed from
* the generic object to the specialized object
*
* @return array<string, mixed>
*/
public function specializable(): array;
/**
* Set the driver for which the object is specialized
*
* @throws DriverException
*/
public function setDriver(DriverInterface $driver): self;
/**
* Return the driver for which the object was specialized
*/
public function driver(): DriverInterface;
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface SpecializedInterface
{
//
}