1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 01:29:51 +02:00

Add docblocks

This commit is contained in:
Oliver Vogel
2023-11-26 11:39:58 +01:00
parent 08ae0df4f0
commit 9e0d9cb53f
11 changed files with 323 additions and 9 deletions

View File

@@ -7,6 +7,11 @@ use Intervention\Image\Interfaces\ImageInterface;
abstract class AbstractAnalyzer implements AnalyzerInterface abstract class AbstractAnalyzer implements AnalyzerInterface
{ {
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed public function analyze(ImageInterface $image): mixed
{ {
return $image->analyze($this); return $image->analyze($this);

View File

@@ -74,7 +74,7 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable
* *
* @return mixed * @return mixed
*/ */
public function first() public function first(): mixed
{ {
if ($item = reset($this->items)) { if ($item = reset($this->items)) {
return $item; return $item;
@@ -88,7 +88,7 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable
* *
* @return mixed * @return mixed
*/ */
public function last() public function last(): mixed
{ {
if ($item = end($this->items)) { if ($item = end($this->items)) {
return $item; return $item;
@@ -103,7 +103,7 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable
* @param integer $key * @param integer $key
* @return mixed * @return mixed
*/ */
public function getAtPosition(int $key = 0, $default = null) public function getAtPosition(int $key = 0, $default = null): mixed
{ {
if ($this->count() == 0) { if ($this->count() == 0) {
return $default; return $default;
@@ -117,7 +117,7 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable
return $positions[$key]; return $positions[$key];
} }
public function get(int|string $query, $default = null) public function get(int|string $query, $default = null): mixed
{ {
if ($this->count() == 0) { if ($this->count() == 0) {
return $default; return $default;

View File

@@ -11,6 +11,13 @@ use ReflectionClass;
abstract class AbstractDriver implements DriverInterface abstract class AbstractDriver implements DriverInterface
{ {
/**
* Return a specialized version for the current driver of the given object
*
* @param object $input
* @return object
* @throws NotSupportedException
*/
public function resolve(object $input): object public function resolve(object $input): object
{ {
if ($this->isExternal($input)) { if ($this->isExternal($input)) {
@@ -30,6 +37,12 @@ abstract class AbstractDriver implements DriverInterface
return new $specialized($input, $this); return new $specialized($input, $this);
} }
/**
* Determine if given object is external custom modifier, analyzer or encoder
*
* @param object $input
* @return bool
*/
private function isExternal(object $input): bool private function isExternal(object $input): bool
{ {
if ($input instanceof AbstractModifier) { if ($input instanceof AbstractModifier) {

View File

@@ -8,6 +8,11 @@ use Intervention\Image\Interfaces\ImageInterface;
abstract class AbstractEncoder implements EncoderInterface abstract class AbstractEncoder implements EncoderInterface
{ {
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage public function encode(ImageInterface $image): EncodedImage
{ {
return $image->encode($this); return $image->encode($this);

View File

@@ -4,5 +4,11 @@ namespace Intervention\Image\Interfaces;
interface AnalyzerInterface interface AnalyzerInterface
{ {
/**
* Analyze given image and return the retrieved data
*
* @param ImageInterface $image
* @return mixed
*/
public function analyze(ImageInterface $image): mixed; public function analyze(ImageInterface $image): mixed;
} }

View File

@@ -6,12 +6,65 @@ use Traversable;
interface CollectionInterface extends Traversable interface CollectionInterface extends Traversable
{ {
/**
* Determine if the collection has item at given key
*
* @param int|string $key
* @return bool
*/
public function has(int|string $key): bool; public function has(int|string $key): bool;
/**
* Add item to collection
*
* @param mixed $item
* @return CollectionInterface
*/
public function push($item): CollectionInterface; public function push($item): CollectionInterface;
public function get(int|string $key, $default = null);
public function getAtPosition(int $key = 0, $default = null); /**
public function first(); * Return item for given key or return default is key does not exist
public function last(); *
* @param int|string $key
* @param mixed $default
* @return mixed
*/
public function get(int|string $key, $default = null): mixed;
/**
* Return item at given numeric position starting at 0
*
* @param int $key
* @param mixed $default
* @return mixed
*/
public function getAtPosition(int $key = 0, $default = null): mixed;
/**
* Return first item in collection
*
* @return mixed
*/
public function first(): mixed;
/**
* Return last item in collection
*
* @return mixed
*/
public function last(): mixed;
/**
* Return item count of collection
*
* @return int
*/
public function count(): int; public function count(): int;
// public function empty(): CollectionInterface;
/**
* Empty collection
*
* @return CollectionInterface
*/
public function empty(): CollectionInterface;
} }

View File

@@ -4,6 +4,19 @@ namespace Intervention\Image\Interfaces;
interface ColorProcessorInterface interface ColorProcessorInterface
{ {
/**
* Turn given color in the driver's color implementation
*
* @param ColorInterface $color
* @return mixed
*/
public function colorToNative(ColorInterface $color); public function colorToNative(ColorInterface $color);
/**
* Turn the given driver's definition of a color into a color object
*
* @param mixed $native
* @return ColorInterface
*/
public function nativeToColor(mixed $native): ColorInterface; public function nativeToColor(mixed $native): ColorInterface;
} }

View File

@@ -6,10 +6,49 @@ use Traversable;
interface CoreInterface extends Traversable interface CoreInterface extends Traversable
{ {
/**
* return driver's representation of the image core.
*
* @return mixed
*/
public function native(): mixed; public function native(): mixed;
/**
* Set driver's representation of the image core.
*
* @param mixed $native
* @return CoreInterface
*/
public function setNative(mixed $native): CoreInterface; public function setNative(mixed $native): CoreInterface;
/**
* Count number of frames of animated image core
*
* @return int
*/
public function count(): int; public function count(): int;
/**
* Return frame of given position in an animated image
*
* @param int $position
* @return FrameInterface
*/
public function frame(int $position): FrameInterface; public function frame(int $position): FrameInterface;
/**
* Return number of repetitions of an animated image
*
* @return int
*/
public function loops(): int; public function loops(): int;
/**
* Set the number of repetitions for an animation. Where a
* value of 0 means infinite repetition.
*
* @param int $loops
* @return CoreInterface
*/
public function setLoops(int $loops): CoreInterface; public function setLoops(int $loops): CoreInterface;
} }

View File

@@ -4,9 +4,43 @@ namespace Intervention\Image\Interfaces;
interface DriverInterface interface DriverInterface
{ {
/**
* Return drivers unique id
*
* @return string
*/
public function id(): string; public function id(): string;
/**
* Resolve given object into a specialized version for the current driver
*
* @param object $input
* @return object
*/
public function resolve(object $input): object; public function resolve(object $input): object;
/**
* Create new image instance with the current driver in given dimensions
*
* @param int $width
* @param int $height
* @return ImageInterface
*/
public function createImage(int $width, int $height): ImageInterface; public function createImage(int $width, int $height): ImageInterface;
/**
* Handle given input by decoding it to ImageInterface or ColorInterface
*
* @param mixed $input
* @return ImageInterface|ColorInterface
*/
public function handleInput(mixed $input): ImageInterface|ColorInterface; public function handleInput(mixed $input): ImageInterface|ColorInterface;
/**
* Return color processor for the given colorspace
*
* @param ColorspaceInterface $colorspace
* @return ColorProcessorInterface
*/
public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface; public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface;
} }

View File

@@ -8,25 +8,166 @@ use IteratorAggregate;
interface ImageInterface extends IteratorAggregate, Countable interface ImageInterface extends IteratorAggregate, Countable
{ {
/**
* Return driver of current image
*
* @return DriverInterface
*/
public function driver(): DriverInterface; public function driver(): DriverInterface;
/**
* Return core of current image
*
* @return CoreInterface
*/
public function core(): CoreInterface; public function core(): CoreInterface;
/**
* Return width of current image
*
* @return int
*/
public function width(): int; public function width(): int;
/**
* Return height of current image
*
* @return int
*/
public function height(): int; public function height(): int;
/**
* Return size of current image
*
* @return SizeInterface
*/
public function size(): SizeInterface; public function size(): SizeInterface;
/**
* Encode image with given encoder
*
* @param EncoderInterface $encoder
* @return EncodedImage
*/
public function encode(EncoderInterface $encoder): EncodedImage; public function encode(EncoderInterface $encoder): EncodedImage;
/**
* Apply given modifier to current image
*
* @param ModifierInterface $modifier
* @return ImageInterface
*/
public function modify(ModifierInterface $modifier): ImageInterface; public function modify(ModifierInterface $modifier): ImageInterface;
/**
* Analyzer current image with given analyzer
*
* @param AnalyzerInterface $analyzer
* @return mixed
*/
public function analyze(AnalyzerInterface $analyzer): mixed; public function analyze(AnalyzerInterface $analyzer): mixed;
/**
* Determine if current image is animated
*
* @return bool
*/
public function isAnimated(): bool; public function isAnimated(): bool;
/**
* Return loop count of animated image
*
* @return int
*/
public function loops(): int; public function loops(): int;
/**
* Return exif data of current image
*
* @return mixed
*/
public function exif(?string $query = null): mixed; public function exif(?string $query = null): mixed;
/**
* Return image resolution/density
*
* @return ResolutionInterface
*/
public function resolution(): ResolutionInterface; public function resolution(): ResolutionInterface;
/**
* Get the colorspace of the image
*
* @return ColorspaceInterface
*/
public function colorspace(): ColorspaceInterface; public function colorspace(): ColorspaceInterface;
/**
* Return color of pixel at given position on given frame position
*
* @param int $x
* @param int $y
* @param int $frame_key
* @return ColorInterface
*/
public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface; 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
*
* @param int $x
* @param int $y
* @return CollectionInterface
*/
public function pickColors(int $x, int $y): CollectionInterface; public function pickColors(int $x, int $y): CollectionInterface;
/**
* Retrieve ICC color profile of image
*
* @return ProfileInterface
*/
public function profile(): ProfileInterface; public function profile(): ProfileInterface;
/**
* Sharpen the current image with given strength
*
* @param int $amount
* @return ImageInterface
*/
public function sharpen(int $amount = 10): ImageInterface; public function sharpen(int $amount = 10): ImageInterface;
/**
* Turn image into a greyscale version
*
* @return ImageInterface
*/
public function greyscale(): ImageInterface; public function greyscale(): ImageInterface;
/**
* Apply pixelation filter effect on current image
*
* @param int $size
* @return ImageInterface
*/
public function pixelate(int $size): ImageInterface; public function pixelate(int $size): ImageInterface;
/**
* Rotate current image by given angle
*
* @param float $angle
* @param string $background
* @return ImageInterface
*/
public function rotate(float $angle, mixed $background = 'ffffff'): ImageInterface; public function rotate(float $angle, mixed $background = 'ffffff'): ImageInterface;
/**
* Draw text on image
*
* @param string $text
* @param int $x
* @param int $y
* @param callable|FontInterface $font
* @return ImageInterface
*/
public function text(string $text, int $x, int $y, callable|FontInterface $font): ImageInterface; public function text(string $text, int $x, int $y, callable|FontInterface $font): ImageInterface;
} }

View File

@@ -7,6 +7,11 @@ use Intervention\Image\Interfaces\ModifierInterface;
abstract class AbstractModifier implements ModifierInterface abstract class AbstractModifier implements ModifierInterface
{ {
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface public function apply(ImageInterface $image): ImageInterface
{ {
return $image->modify($this); return $image->modify($this);