repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 7 values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Traits/CanBuildFilePointer.php | src/Traits/CanBuildFilePointer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\RuntimeException;
trait CanBuildFilePointer
{
/**
* Transform the provided data into a pointer with the data as its content
*
* @param resource|string|null $data
* @throws RuntimeException
* @return resource|false
*/
public function buildFilePointer(mixed $data = null)
{
switch (true) {
case is_string($data):
$pointer = fopen('php://temp', 'r+');
fwrite($pointer, $data);
break;
case is_resource($data) && get_resource_type($data) === 'stream':
$pointer = $data;
break;
case is_null($data):
$pointer = fopen('php://temp', 'r+');
break;
default:
throw new RuntimeException('Unable to build file pointer.');
}
rewind($pointer);
return $pointer;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Traits/CanBeDriverSpecialized.php | src/Traits/CanBeDriverSpecialized.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Traits;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\SpecializableInterface;
use ReflectionClass;
trait CanBeDriverSpecialized
{
/**
* The driver with which the instance may be specialized
*/
protected DriverInterface $driver;
/**
* {@inheritdoc}
*
* @see SpecializableInterface::specializable()
*/
public function specializable(): array
{
$specializable = [];
$reflectionClass = new ReflectionClass($this::class);
if ($constructor = $reflectionClass->getConstructor()) {
foreach ($constructor->getParameters() as $parameter) {
$specializable[$parameter->getName()] = $this->{$parameter->getName()};
}
}
return $specializable;
}
/**
* {@inheritdoc}
*
* @see SpecializableInterface::driver()
*/
public function driver(): DriverInterface
{
return $this->driver;
}
/**
* {@inheritdoc}
*
* @see SpecializableInterface::setDriver()
*/
public function setDriver(DriverInterface $driver): SpecializableInterface
{
if (!$this->belongsToDriver($driver)) {
throw new DriverException(
"Class '" . $this::class . "' can not be used with " . $driver->id() . " driver."
);
}
$this->driver = $driver;
return $this;
}
/**
* Determine if the current object belongs to the given driver's namespace
*/
protected function belongsToDriver(object $driver): bool
{
$namespace = function (object $object): string {
return (new ReflectionClass($object))->getNamespaceName();
};
return str_starts_with($namespace($this), $namespace($driver));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Polygon.php | src/Geometry/Polygon.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use ArrayAccess;
use ArrayIterator;
use Countable;
use Traversable;
use IteratorAggregate;
use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
/**
* @implements IteratorAggregate<PointInterface>
* @implements ArrayAccess<int, PointInterface>
*/
class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
{
use HasBorder;
use HasBackgroundColor;
/**
* Create new polygon instance
*
* @param array<PointInterface> $points
* @return void
*/
public function __construct(
protected array $points = [],
protected PointInterface $pivot = new Point()
) {
//
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::position()
*/
public function position(): PointInterface
{
return $this->pivot;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setPosition()
*/
public function setPosition(PointInterface $position): self
{
$this->pivot = $position;
return $this;
}
/**
* Implement iteration through all points of polygon
*
* @return Traversable<PointInterface>
*/
public function getIterator(): Traversable
{
return new ArrayIterator($this->points);
}
/**
* Return current pivot point
*/
public function pivot(): PointInterface
{
return $this->pivot;
}
/**
* Change pivot point to given point
*/
public function setPivot(PointInterface $pivot): self
{
$this->pivot = $pivot;
return $this;
}
/**
* Return first point of polygon
*/
public function first(): ?PointInterface
{
if ($point = reset($this->points)) {
return $point;
}
return null;
}
/**
* Return last point of polygon
*/
public function last(): ?PointInterface
{
if ($point = end($this->points)) {
return $point;
}
return null;
}
/**
* Return polygon's point count
*/
public function count(): int
{
return count($this->points);
}
/**
* Determine if point exists at given offset
*/
public function offsetExists(mixed $offset): bool
{
return array_key_exists($offset, $this->points);
}
/**
* Return point at given offset
*/
public function offsetGet(mixed $offset): mixed
{
return $this->points[$offset];
}
/**
* Set point at given offset
*/
public function offsetSet(mixed $offset, mixed $value): void
{
$this->points[$offset] = $value;
}
/**
* Unset offset at given offset
*/
public function offsetUnset(mixed $offset): void
{
unset($this->points[$offset]);
}
/**
* Add given point to polygon
*/
public function addPoint(PointInterface $point): self
{
$this->points[] = $point;
return $this;
}
/**
* Calculate total horizontal span of polygon
*/
public function width(): int
{
return abs($this->mostLeftPoint()->x() - $this->mostRightPoint()->x());
}
/**
* Calculate total vertical span of polygon
*/
public function height(): int
{
return abs($this->mostBottomPoint()->y() - $this->mostTopPoint()->y());
}
/**
* Return most left point of all points in polygon
*/
public function mostLeftPoint(): PointInterface
{
$points = $this->points;
usort($points, function (PointInterface $a, PointInterface $b): int {
if ($a->x() === $b->x()) {
return 0;
}
return $a->x() < $b->x() ? -1 : 1;
});
return $points[0];
}
/**
* Return most right point in polygon
*/
public function mostRightPoint(): PointInterface
{
$points = $this->points;
usort($points, function (PointInterface $a, PointInterface $b): int {
if ($a->x() === $b->x()) {
return 0;
}
return $a->x() > $b->x() ? -1 : 1;
});
return $points[0];
}
/**
* Return most top point in polygon
*/
public function mostTopPoint(): PointInterface
{
$points = $this->points;
usort($points, function (PointInterface $a, PointInterface $b): int {
if ($a->y() === $b->y()) {
return 0;
}
return $a->y() > $b->y() ? -1 : 1;
});
return $points[0];
}
/**
* Return most bottom point in polygon
*/
public function mostBottomPoint(): PointInterface
{
$points = $this->points;
usort($points, function (PointInterface $a, PointInterface $b): int {
if ($a->y() === $b->y()) {
return 0;
}
return $a->y() < $b->y() ? -1 : 1;
});
return $points[0];
}
/**
* Return point in absolute center of the polygon
*/
public function centerPoint(): PointInterface
{
return new Point(
$this->mostRightPoint()->x() - (intval(round($this->width() / 2))),
$this->mostTopPoint()->y() - (intval(round($this->height() / 2)))
);
}
/**
* Align all points of polygon horizontally to given position around pivot point
*/
public function align(string $position): self
{
switch (strtolower($position)) {
case 'center':
case 'middle':
$diff = $this->centerPoint()->x() - $this->pivot()->x();
break;
case 'right':
$diff = $this->mostRightPoint()->x() - $this->pivot()->x();
break;
default:
case 'left':
$diff = $this->mostLeftPoint()->x() - $this->pivot()->x();
break;
}
foreach ($this->points as $point) {
$point->setX(
intval($point->x() - $diff)
);
}
return $this;
}
/**
* Align all points of polygon vertically to given position around pivot point
*/
public function valign(string $position): self
{
switch (strtolower($position)) {
case 'center':
case 'middle':
$diff = $this->centerPoint()->y() - $this->pivot()->y();
break;
case 'top':
$diff = $this->mostTopPoint()->y() - $this->pivot()->y() - $this->height();
break;
default:
case 'bottom':
$diff = $this->mostBottomPoint()->y() - $this->pivot()->y() + $this->height();
break;
}
foreach ($this->points as $point) {
$point->setY(
intval($point->y() - $diff),
);
}
return $this;
}
/**
* Rotate points of polygon around pivot point with given angle
*/
public function rotate(float $angle): self
{
$sin = sin(deg2rad($angle));
$cos = cos(deg2rad($angle));
foreach ($this->points as $point) {
// translate point to pivot
$point->setX(
intval($point->x() - $this->pivot()->x()),
);
$point->setY(
intval($point->y() - $this->pivot()->y()),
);
// rotate point
$x = $point->x() * $cos - $point->y() * $sin;
$y = $point->x() * $sin + $point->y() * $cos;
// translate point back
$point->setX(
intval($x + $this->pivot()->x()),
);
$point->setY(
intval($y + $this->pivot()->y()),
);
}
return $this;
}
/**
* Move all points by given amount on the x-axis
*/
public function movePointsX(int $amount): self
{
foreach ($this->points as $point) {
$point->moveX($amount);
}
return $this;
}
/**
* Move all points by given amount on the y-axis
*/
public function movePointsY(int $amount): self
{
foreach ($this->points as $point) {
$point->moveY($amount);
}
return $this;
}
/**
* Return array of all x/y values of all points of polygon
*
* @return array<int>
*/
public function toArray(): array
{
$coordinates = [];
foreach ($this->points as $point) {
$coordinates[] = $point->x();
$coordinates[] = $point->y();
}
return $coordinates;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Rectangle.php | src/Geometry/Rectangle.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Geometry\Tools\RectangleResizer;
use Intervention\Image\Interfaces\PointInterface;
use Intervention\Image\Interfaces\SizeInterface;
class Rectangle extends Polygon implements SizeInterface
{
/**
* Create new rectangle instance
*
* @return void
*/
public function __construct(
int $width,
int $height,
protected PointInterface $pivot = new Point()
) {
$this->addPoint(new Point($this->pivot->x(), $this->pivot->y()));
$this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y()));
$this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y() - $height));
$this->addPoint(new Point($this->pivot->x(), $this->pivot->y() - $height));
}
/**
* Set size of rectangle
*/
public function setSize(int $width, int $height): self
{
return $this->setWidth($width)->setHeight($height);
}
/**
* Set width of rectangle
*/
public function setWidth(int $width): self
{
$this[1]->setX($this[0]->x() + $width);
$this[2]->setX($this[3]->x() + $width);
return $this;
}
/**
* Set height of rectangle
*/
public function setHeight(int $height): self
{
$this[2]->setY($this[1]->y() + $height);
$this[3]->setY($this[0]->y() + $height);
return $this;
}
/**
* Return pivot point of rectangle
*/
public function pivot(): PointInterface
{
return $this->pivot;
}
/**
* Set pivot point of rectangle
*/
public function setPivot(PointInterface $pivot): self
{
$this->pivot = $pivot;
return $this;
}
/**
* Move pivot to the given position in the rectangle and adjust the new
* position by given offset values.
*/
public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0): self
{
switch (strtolower($position)) {
case 'top':
case 'top-center':
case 'top-middle':
case 'center-top':
case 'middle-top':
$x = intval(round($this->width() / 2)) + $offset_x;
$y = $offset_y;
break;
case 'top-right':
case 'right-top':
$x = $this->width() - $offset_x;
$y = $offset_y;
break;
case 'left':
case 'left-center':
case 'left-middle':
case 'center-left':
case 'middle-left':
$x = $offset_x;
$y = intval(round($this->height() / 2)) + $offset_y;
break;
case 'right':
case 'right-center':
case 'right-middle':
case 'center-right':
case 'middle-right':
$x = $this->width() - $offset_x;
$y = intval(round($this->height() / 2)) + $offset_y;
break;
case 'bottom-left':
case 'left-bottom':
$x = $offset_x;
$y = $this->height() - $offset_y;
break;
case 'bottom':
case 'bottom-center':
case 'bottom-middle':
case 'center-bottom':
case 'middle-bottom':
$x = intval(round($this->width() / 2)) + $offset_x;
$y = $this->height() - $offset_y;
break;
case 'bottom-right':
case 'right-bottom':
$x = $this->width() - $offset_x;
$y = $this->height() - $offset_y;
break;
case 'center':
case 'middle':
case 'center-center':
case 'middle-middle':
$x = intval(round($this->width() / 2)) + $offset_x;
$y = intval(round($this->height() / 2)) + $offset_y;
break;
default:
case 'top-left':
case 'left-top':
$x = $offset_x;
$y = $offset_y;
break;
}
$this->pivot->setPosition($x, $y);
return $this;
}
/**
* Align pivot relative to given size at given position
*/
public function alignPivotTo(SizeInterface $size, string $position): self
{
$reference = new self($size->width(), $size->height());
$reference->movePivot($position);
$this->movePivot($position)->setPivot(
$reference->relativePositionTo($this)
);
return $this;
}
/**
* Return relative position to given rectangle
*/
public function relativePositionTo(SizeInterface $rectangle): PointInterface
{
return new Point(
$this->pivot()->x() - $rectangle->pivot()->x(),
$this->pivot()->y() - $rectangle->pivot()->y()
);
}
/**
* Return aspect ration of rectangle
*/
public function aspectRatio(): float
{
return $this->width() / $this->height();
}
/**
* Determine if rectangle fits into given rectangle
*/
public function fitsInto(SizeInterface $size): bool
{
if ($this->width() > $size->width()) {
return false;
}
if ($this->height() > $size->height()) {
return false;
}
return true;
}
/**
* Determine if rectangle has landscape format
*/
public function isLandscape(): bool
{
return $this->width() > $this->height();
}
/**
* Determine if rectangle has landscape format
*/
public function isPortrait(): bool
{
return $this->width() < $this->height();
}
/**
* Return most top left point of rectangle
*/
public function topLeftPoint(): PointInterface
{
return $this->points[0];
}
/**
* Return bottom right point of rectangle
*/
public function bottomRightPoint(): PointInterface
{
return $this->points[2];
}
/**
* @see SizeInterface::resize()
*
* @throws GeometryException
*/
public function resize(?int $width = null, ?int $height = null): SizeInterface
{
return $this->resizer($width, $height)->resize($this);
}
/**
* @see SizeInterface::resizeDown()
*
* @throws GeometryException
*/
public function resizeDown(?int $width = null, ?int $height = null): SizeInterface
{
return $this->resizer($width, $height)->resizeDown($this);
}
/**
* @see SizeInterface::scale()
*
* @throws GeometryException
*/
public function scale(?int $width = null, ?int $height = null): SizeInterface
{
return $this->resizer($width, $height)->scale($this);
}
/**
* @see SizeInterface::scaleDown()
*
* @throws GeometryException
*/
public function scaleDown(?int $width = null, ?int $height = null): SizeInterface
{
return $this->resizer($width, $height)->scaleDown($this);
}
/**
* @see SizeInterface::cover()
*
* @throws GeometryException
*/
public function cover(int $width, int $height): SizeInterface
{
return $this->resizer($width, $height)->cover($this);
}
/**
* @see SizeInterface::contain()
*
* @throws GeometryException
*/
public function contain(int $width, int $height): SizeInterface
{
return $this->resizer($width, $height)->contain($this);
}
/**
* @see SizeInterface::containMax()
*
* @throws GeometryException
*/
public function containMax(int $width, int $height): SizeInterface
{
return $this->resizer($width, $height)->containDown($this);
}
/**
* Create resizer instance with given target size
*
* @throws GeometryException
*/
protected function resizer(?int $width = null, ?int $height = null): RectangleResizer
{
return new RectangleResizer($width, $height);
}
/**
* Show debug info for the current rectangle
*
* @return array<string, int|object>
*/
public function __debugInfo(): array
{
return [
'width' => $this->width(),
'height' => $this->height(),
'pivot' => $this->pivot,
];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Line.php | src/Geometry/Line.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
class Line implements DrawableInterface
{
use HasBorder;
use HasBackgroundColor;
/**
* Create new line instance
*
* @return void
*/
public function __construct(
protected PointInterface $start,
protected PointInterface $end,
protected int $width = 1
) {
//
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::position()
*/
public function position(): PointInterface
{
return $this->start;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setPosition()
*/
public function setPosition(PointInterface $position): DrawableInterface
{
$this->start = $position;
return $this;
}
/**
* Return line width
*/
public function width(): int
{
return $this->width;
}
/**
* Set line width
*/
public function setWidth(int $width): self
{
$this->width = $width;
return $this;
}
/**
* Get starting point of line
*/
public function start(): PointInterface
{
return $this->start;
}
/**
* get end point of line
*/
public function end(): PointInterface
{
return $this->end;
}
/**
* Set starting point of line
*/
public function setStart(PointInterface $start): self
{
$this->start = $start;
return $this;
}
/**
* Set starting point of line by coordinates
*/
public function from(int $x, int $y): self
{
$this->start()->setX($x);
$this->start()->setY($y);
return $this;
}
/**
* Set end point of line by coordinates
*/
public function to(int $x, int $y): self
{
$this->end()->setX($x);
$this->end()->setY($y);
return $this;
}
/**
* Set end point of line
*/
public function setEnd(PointInterface $end): self
{
$this->end = $end;
return $this;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Pixel.php | src/Geometry/Pixel.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use Intervention\Image\Interfaces\ColorInterface;
class Pixel extends Point
{
/**
* Create new pixel instance
*
* @return void
*/
public function __construct(
protected ColorInterface $background,
protected int $x,
protected int $y
) {
//
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setBackgroundColor()
*/
public function setBackgroundColor(ColorInterface $background): self
{
$this->background = $background;
return $this;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::backgroundColor()
*/
public function backgroundColor(): ColorInterface
{
return $this->background;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Bezier.php | src/Geometry/Bezier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use ArrayAccess;
use ArrayIterator;
use Countable;
use Traversable;
use IteratorAggregate;
use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
/**
* @implements IteratorAggregate<PointInterface>
* @implements ArrayAccess<int, PointInterface>
*/
class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
{
use HasBorder;
use HasBackgroundColor;
/**
* Create new bezier instance
*
* @param array<PointInterface> $points
* @return void
*/
public function __construct(
protected array $points = [],
protected PointInterface $pivot = new Point()
) {
//
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::position()
*/
public function position(): PointInterface
{
return $this->pivot;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setPosition()
*/
public function setPosition(PointInterface $position): DrawableInterface
{
$this->pivot = $position;
return $this;
}
/**
* Implement iteration through all points of bezier
*
* @return Traversable<PointInterface>
*/
public function getIterator(): Traversable
{
return new ArrayIterator($this->points);
}
/**
* Return current pivot point
*/
public function pivot(): PointInterface
{
return $this->pivot;
}
/**
* Change pivot point to given point
*/
public function setPivot(PointInterface $pivot): self
{
$this->pivot = $pivot;
return $this;
}
/**
* Return first control point of bezier
*/
public function first(): ?PointInterface
{
if ($point = reset($this->points)) {
return $point;
}
return null;
}
/**
* Return second control point of bezier
*/
public function second(): ?PointInterface
{
if (array_key_exists(1, $this->points)) {
return $this->points[1];
}
return null;
}
/**
* Return third control point of bezier
*/
public function third(): ?PointInterface
{
if (array_key_exists(2, $this->points)) {
return $this->points[2];
}
return null;
}
/**
* Return last control point of bezier
*/
public function last(): ?PointInterface
{
if ($point = end($this->points)) {
return $point;
}
return null;
}
/**
* Return bezier's point count
*/
public function count(): int
{
return count($this->points);
}
/**
* Determine if point exists at given offset
*/
public function offsetExists(mixed $offset): bool
{
return array_key_exists($offset, $this->points);
}
/**
* Return point at given offset
*/
public function offsetGet(mixed $offset): mixed
{
return $this->points[$offset];
}
/**
* Set point at given offset
*/
public function offsetSet(mixed $offset, mixed $value): void
{
$this->points[$offset] = $value;
}
/**
* Unset offset at given offset
*/
public function offsetUnset(mixed $offset): void
{
unset($this->points[$offset]);
}
/**
* Add given point to bezier
*/
public function addPoint(PointInterface $point): self
{
$this->points[] = $point;
return $this;
}
/**
* Return array of all x/y values of all points of bezier
*
* @return array<int>
*/
public function toArray(): array
{
$coordinates = [];
foreach ($this->points as $point) {
$coordinates[] = $point->x();
$coordinates[] = $point->y();
}
return $coordinates;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Point.php | src/Geometry/Point.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use ArrayIterator;
use Intervention\Image\Interfaces\PointInterface;
use IteratorAggregate;
use Traversable;
/**
* @implements IteratorAggregate<int>
*/
class Point implements PointInterface, IteratorAggregate
{
/**
* Create new point instance
*
* @return void
*/
public function __construct(
protected int $x = 0,
protected int $y = 0
) {
//
}
/**
* {@inheritdoc}
*
* @see IteratorAggregate::getIterator()
*/
public function getIterator(): Traversable
{
return new ArrayIterator([$this->x, $this->y]);
}
/**
* {@inheritdoc}
*
* @see PointInterface::setX()
*/
public function setX(int $x): self
{
$this->x = $x;
return $this;
}
/**
* {@inheritdoc}
*
* @see PointInterface::x()
*/
public function x(): int
{
return $this->x;
}
/**
* {@inheritdoc}
*
* @see PointInterface::setY()
*/
public function setY(int $y): self
{
$this->y = $y;
return $this;
}
/**
* {@inheritdoc}
*
* @see PointInterface::y()
*/
public function y(): int
{
return $this->y;
}
/**
* {@inheritdoc}
*
* @see PointInterface::moveX()
*/
public function moveX(int $value): self
{
$this->x += $value;
return $this;
}
/**
* {@inheritdoc}
*
* @see PointInterface::moveY()
*/
public function moveY(int $value): self
{
$this->y += $value;
return $this;
}
/**
* {@inheritdoc}
*
* @see PointInterface::move()
*/
public function move(int $x, int $y): self
{
return $this->moveX($x)->moveY($y);
}
/**
* {@inheritdoc}
*
* @see PointInterface::setPosition()
*/
public function setPosition(int $x, int $y): self
{
$this->setX($x);
$this->setY($y);
return $this;
}
/**
* {@inheritdoc}
*
* @see PointInterface::rotate()
*/
public function rotate(float $angle, PointInterface $pivot): self
{
$sin = round(sin(deg2rad($angle)), 6);
$cos = round(cos(deg2rad($angle)), 6);
return $this->setPosition(
intval($cos * ($this->x() - $pivot->x()) - $sin * ($this->y() - $pivot->y()) + $pivot->x()),
intval($sin * ($this->x() - $pivot->x()) + $cos * ($this->y() - $pivot->y()) + $pivot->y())
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Ellipse.php | src/Geometry/Ellipse.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
class Ellipse implements DrawableInterface
{
use HasBorder;
use HasBackgroundColor;
/**
* Create new Ellipse
*
* @return void
*/
public function __construct(
protected int $width,
protected int $height,
protected PointInterface $pivot = new Point()
) {
//
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::position()
*/
public function position(): PointInterface
{
return $this->pivot;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setPosition()
*/
public function setPosition(PointInterface $position): self
{
$this->pivot = $position;
return $this;
}
/**
* Return pivot point of Ellipse
*/
public function pivot(): PointInterface
{
return $this->pivot;
}
/**
* Set size of Ellipse
*/
public function setSize(int $width, int $height): self
{
return $this->setWidth($width)->setHeight($height);
}
/**
* Set width of Ellipse
*/
public function setWidth(int $width): self
{
$this->width = $width;
return $this;
}
/**
* Set height of Ellipse
*/
public function setHeight(int $height): self
{
$this->height = $height;
return $this;
}
/**
* Get width of Ellipse
*/
public function width(): int
{
return $this->width;
}
/**
* Get height of Ellipse
*/
public function height(): int
{
return $this->height;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Circle.php | src/Geometry/Circle.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry;
use Intervention\Image\Interfaces\PointInterface;
class Circle extends Ellipse
{
/**
* Create new Circle instance
*
* @return void
*/
public function __construct(
int $diameter,
PointInterface $pivot = new Point()
) {
parent::__construct($diameter, $diameter, $pivot);
}
/**
* Set diameter of circle
*/
public function setDiameter(int $diameter): self
{
$this->setWidth($diameter);
$this->setHeight($diameter);
return $this;
}
/**
* Get diameter of circle
*/
public function diameter(): int
{
return $this->width();
}
/**
* Set radius of circle
*/
public function setRadius(int $radius): self
{
return $this->setDiameter(intval($radius * 2));
}
/**
* Get radius of circle
*/
public function radius(): int
{
return intval(round($this->diameter() / 2));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Traits/HasBackgroundColor.php | src/Geometry/Traits/HasBackgroundColor.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Traits;
trait HasBackgroundColor
{
protected mixed $backgroundColor = null;
/**
* {@inheritdoc}
*
* @see DrawableInterface::setBackgroundColor()
*/
public function setBackgroundColor(mixed $color): self
{
$this->backgroundColor = $color;
return $this;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::backgroundColor()
*/
public function backgroundColor(): mixed
{
return $this->backgroundColor;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::hasBackgroundColor()
*/
public function hasBackgroundColor(): bool
{
return !empty($this->backgroundColor);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Traits/HasBorder.php | src/Geometry/Traits/HasBorder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Traits;
trait HasBorder
{
protected mixed $borderColor = null;
protected int $borderSize = 0;
/**
* {@inheritdoc}
*
* @see DrawableInterface::setBorder()
*/
public function setBorder(mixed $color, int $size = 1): self
{
return $this->setBorderSize($size)->setBorderColor($color);
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setBorderSize()
*/
public function setBorderSize(int $size): self
{
$this->borderSize = $size;
return $this;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::borderSize()
*/
public function borderSize(): int
{
return $this->borderSize;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setBorderColor()
*/
public function setBorderColor(mixed $color): self
{
$this->borderColor = $color;
return $this;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::borderColor()
*/
public function borderColor(): mixed
{
return $this->borderColor;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::hasBorder()
*/
public function hasBorder(): bool
{
return $this->borderSize > 0 && !is_null($this->borderColor);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Factories/EllipseFactory.php | src/Geometry/Factories/EllipseFactory.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Ellipse;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
class EllipseFactory implements DrawableFactoryInterface
{
protected Ellipse $ellipse;
/**
* Create new factory instance
*
* @return void
*/
public function __construct(
protected PointInterface $pivot = new Point(),
null|Closure|Ellipse $init = null,
) {
$this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0);
$this->ellipse->setPosition($pivot);
if (is_callable($init)) {
$init($this);
}
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::init()
*/
public static function init(null|Closure|DrawableInterface $init = null): self
{
return new self(init: $init);
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::create()
*/
public function create(): DrawableInterface
{
return $this->ellipse;
}
/**
* Set the size of the ellipse to be produced
*/
public function size(int $width, int $height): self
{
$this->ellipse->setSize($width, $height);
return $this;
}
/**
* Set the width of the ellipse to be produced
*/
public function width(int $width): self
{
$this->ellipse->setWidth($width);
return $this;
}
/**
* Set the height of the ellipse to be produced
*/
public function height(int $height): self
{
$this->ellipse->setHeight($height);
return $this;
}
/**
* Set the background color of the ellipse to be produced
*/
public function background(mixed $color): self
{
$this->ellipse->setBackgroundColor($color);
return $this;
}
/**
* Set the border color & border size of the ellipse to be produced
*/
public function border(mixed $color, int $size = 1): self
{
$this->ellipse->setBorder($color, $size);
return $this;
}
/**
* Produce the ellipse
*/
public function __invoke(): Ellipse
{
return $this->ellipse;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Factories/RectangleFactory.php | src/Geometry/Factories/RectangleFactory.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
class RectangleFactory implements DrawableFactoryInterface
{
protected Rectangle $rectangle;
/**
* Create new instance
*
* @return void
*/
public function __construct(
protected PointInterface $pivot = new Point(),
null|Closure|Rectangle $init = null,
) {
$this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot);
$this->rectangle->setPosition($pivot);
if (is_callable($init)) {
$init($this);
}
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::init()
*/
public static function init(null|Closure|DrawableInterface $init = null): self
{
return new self(init: $init);
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::create()
*/
public function create(): DrawableInterface
{
return $this->rectangle;
}
/**
* Set the size of the rectangle to be produced
*/
public function size(int $width, int $height): self
{
$this->rectangle->setSize($width, $height);
return $this;
}
/**
* Set the width of the rectangle to be produced
*/
public function width(int $width): self
{
$this->rectangle->setWidth($width);
return $this;
}
/**
* Set the height of the rectangle to be produced
*/
public function height(int $height): self
{
$this->rectangle->setHeight($height);
return $this;
}
/**
* Set the background color of the rectangle to be produced
*/
public function background(mixed $color): self
{
$this->rectangle->setBackgroundColor($color);
return $this;
}
/**
* Set the border color & border size of the rectangle to be produced
*/
public function border(mixed $color, int $size = 1): self
{
$this->rectangle->setBorder($color, $size);
return $this;
}
/**
* Produce the rectangle
*/
public function __invoke(): Rectangle
{
return $this->rectangle;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Factories/BezierFactory.php | src/Geometry/Factories/BezierFactory.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Bezier;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
class BezierFactory implements DrawableFactoryInterface
{
protected Bezier $bezier;
/**
* Create new factory instance
*
* @return void
*/
public function __construct(null|Closure|Bezier $init = null)
{
$this->bezier = is_a($init, Bezier::class) ? $init : new Bezier([]);
if (is_callable($init)) {
$init($this);
}
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::init()
*/
public static function init(null|Closure|DrawableInterface $init = null): self
{
return new self($init);
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::create()
*/
public function create(): DrawableInterface
{
return $this->bezier;
}
/**
* Add a point to the bezier to be produced
*/
public function point(int $x, int $y): self
{
$this->bezier->addPoint(new Point($x, $y));
return $this;
}
/**
* Set the background color of the bezier to be produced
*/
public function background(mixed $color): self
{
$this->bezier->setBackgroundColor($color);
return $this;
}
/**
* Set the border color & border size of the bezier to be produced
*/
public function border(mixed $color, int $size = 1): self
{
$this->bezier->setBorder($color, $size);
return $this;
}
/**
* Produce the bezier
*/
public function __invoke(): Bezier
{
return $this->bezier;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Factories/PolygonFactory.php | src/Geometry/Factories/PolygonFactory.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Polygon;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
class PolygonFactory implements DrawableFactoryInterface
{
protected Polygon $polygon;
/**
* Create new factory instance
*
* @return void
*/
public function __construct(null|Closure|Polygon $init = null)
{
$this->polygon = is_a($init, Polygon::class) ? $init : new Polygon([]);
if (is_callable($init)) {
$init($this);
}
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::init()
*/
public static function init(null|Closure|DrawableInterface $init = null): self
{
return new self($init);
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::create()
*/
public function create(): DrawableInterface
{
return $this->polygon;
}
/**
* Add a point to the polygon to be produced
*/
public function point(int $x, int $y): self
{
$this->polygon->addPoint(new Point($x, $y));
return $this;
}
/**
* Set the background color of the polygon to be produced
*/
public function background(mixed $color): self
{
$this->polygon->setBackgroundColor($color);
return $this;
}
/**
* Set the border color & border size of the polygon to be produced
*/
public function border(mixed $color, int $size = 1): self
{
$this->polygon->setBorder($color, $size);
return $this;
}
/**
* Produce the polygon
*/
public function __invoke(): Polygon
{
return $this->polygon;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Factories/CircleFactory.php | src/Geometry/Factories/CircleFactory.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Circle;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
use Intervention\Image\Interfaces\PointInterface;
class CircleFactory implements DrawableFactoryInterface
{
protected Circle $circle;
/**
* Create new factory instance
*
* @return void
*/
public function __construct(
protected PointInterface $pivot = new Point(),
null|Closure|Circle $init = null,
) {
$this->circle = is_a($init, Circle::class) ? $init : new Circle(0);
$this->circle->setPosition($pivot);
if (is_callable($init)) {
$init($this);
}
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::init()
*/
public static function init(null|Closure|DrawableInterface $init = null): self
{
return new self(init: $init);
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::create()
*/
public function create(): DrawableInterface
{
return $this->circle;
}
/**
* Set the radius of the circle to be produced
*/
public function radius(int $radius): self
{
$this->circle->setSize($radius * 2, $radius * 2);
return $this;
}
/**
* Set the diameter of the circle to be produced
*/
public function diameter(int $diameter): self
{
$this->circle->setSize($diameter, $diameter);
return $this;
}
/**
* Set the background color of the circle to be produced
*/
public function background(mixed $color): self
{
$this->circle->setBackgroundColor($color);
return $this;
}
/**
* Set the border color & border size of the ellipse to be produced
*/
public function border(mixed $color, int $size = 1): self
{
$this->circle->setBorder($color, $size);
return $this;
}
/**
* Produce the circle
*/
public function __invoke(): Circle
{
return $this->circle;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Factories/LineFactory.php | src/Geometry/Factories/LineFactory.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories;
use Closure;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Line;
use Intervention\Image\Interfaces\DrawableFactoryInterface;
use Intervention\Image\Interfaces\DrawableInterface;
class LineFactory implements DrawableFactoryInterface
{
protected Line $line;
/**
* Create the factory instance
*
* @return void
*/
public function __construct(null|Closure|Line $init = null)
{
$this->line = is_a($init, Line::class) ? $init : new Line(new Point(), new Point());
if (is_callable($init)) {
$init($this);
}
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::init()
*/
public static function init(null|Closure|DrawableInterface $init = null): self
{
return new self($init);
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::create()
*/
public function create(): DrawableInterface
{
return $this->line;
}
/**
* Set the color of the line to be produced
*/
public function color(mixed $color): self
{
$this->line->setBackgroundColor($color);
$this->line->setBorderColor($color);
return $this;
}
/**
* Set the (background) color of the line to be produced
*/
public function background(mixed $color): self
{
$this->line->setBackgroundColor($color);
$this->line->setBorderColor($color);
return $this;
}
/**
* Set the border size & border color of the line to be produced
*/
public function border(mixed $color, int $size = 1): self
{
$this->line->setBackgroundColor($color);
$this->line->setBorderColor($color);
$this->line->setWidth($size);
return $this;
}
/**
* Set the width of the line to be produced
*/
public function width(int $size): self
{
$this->line->setWidth($size);
return $this;
}
/**
* Set the coordinates of the starting point of the line to be produced
*/
public function from(int $x, int $y): self
{
$this->line->setStart(new Point($x, $y));
return $this;
}
/**
* Set the coordinates of the end point of the line to be produced
*/
public function to(int $x, int $y): self
{
$this->line->setEnd(new Point($x, $y));
return $this;
}
/**
* Produce the line
*/
public function __invoke(): Line
{
return $this->line;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Factories/Drawable.php | src/Geometry/Factories/Drawable.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Factories;
class Drawable
{
/**
* Creeate BezierFactory statically
*/
public static function bezier(): BezierFactory
{
return new BezierFactory();
}
/**
* Creeate CircleFactory statically
*/
public static function circle(): CircleFactory
{
return new CircleFactory();
}
/**
* Create EllipseFactory statically
*/
public static function ellipse(): EllipseFactory
{
return new EllipseFactory();
}
/**
* Creeate LineFactory statically
*/
public static function line(): LineFactory
{
return new LineFactory();
}
/**
* Creeate PolygonFactory statically
*/
public static function polygon(): PolygonFactory
{
return new PolygonFactory();
}
/**
* Creeate RectangleFactory statically
*/
public static function rectangle(): RectangleFactory
{
return new RectangleFactory();
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Geometry/Tools/RectangleResizer.php | src/Geometry/Tools/RectangleResizer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Geometry\Tools;
use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\SizeInterface;
class RectangleResizer
{
/**
* @throws GeometryException
* @return void
*/
public function __construct(
protected ?int $width = null,
protected ?int $height = null,
) {
if (is_int($width) && $width < 1) {
throw new GeometryException(
'The width you specify must be greater than or equal to 1.'
);
}
if (is_int($height) && $height < 1) {
throw new GeometryException(
'The height you specify must be greater than or equal to 1.'
);
}
}
/**
* Static factory method to create resizer with given target size
*
* @throws GeometryException
*/
public static function to(mixed ...$arguments): self
{
return new self(...$arguments);
}
/**
* Determine if resize has target width
*/
protected function hasTargetWidth(): bool
{
return is_int($this->width);
}
/**
* Return target width of resizer if available
*/
protected function getTargetWidth(): ?int
{
return $this->hasTargetWidth() ? $this->width : null;
}
/**
* Determine if resize has target height
*/
protected function hasTargetHeight(): bool
{
return is_int($this->height);
}
/**
* Return target width of resizer if available
*/
protected function getTargetHeight(): ?int
{
return $this->hasTargetHeight() ? $this->height : null;
}
/**
* Return target size object
*
* @throws GeometryException
*/
protected function getTargetSize(): SizeInterface
{
if (!$this->hasTargetWidth() || !$this->hasTargetHeight()) {
throw new GeometryException('Target size needs width and height.');
}
return new Rectangle($this->width, $this->height);
}
/**
* Set target width of resizer
*/
public function toWidth(int $width): self
{
$this->width = $width;
return $this;
}
/**
* Set target height of resizer
*/
public function toHeight(int $height): self
{
$this->height = $height;
return $this;
}
/**
* Set target size to given size object
*/
public function toSize(SizeInterface $size): self
{
$this->width = $size->width();
$this->height = $size->height();
return $this;
}
/**
* Get proportinal width
*/
protected function getProportionalWidth(SizeInterface $size): int
{
if (!$this->hasTargetHeight()) {
return $size->width();
}
return max([1, (int) round($this->height * $size->aspectRatio())]);
}
/**
* Get proportinal height
*/
protected function getProportionalHeight(SizeInterface $size): int
{
if (!$this->hasTargetWidth()) {
return $size->height();
}
return max([1, (int) round($this->width / $size->aspectRatio())]);
}
/**
* Resize given size to target size of the resizer
*/
public function resize(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
if ($width = $this->getTargetWidth()) {
$resized->setWidth($width);
}
if ($height = $this->getTargetHeight()) {
$resized->setHeight($height);
}
return $resized;
}
/**
* Resize given size to target size of the resizer but do not exceed original size
*/
public function resizeDown(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
if ($width = $this->getTargetWidth()) {
$resized->setWidth(
min($width, $size->width())
);
}
if ($height = $this->getTargetHeight()) {
$resized->setHeight(
min($height, $size->height())
);
}
return $resized;
}
/**
* Resize given size to target size proportinally
*/
public function scale(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
if ($this->hasTargetWidth() && $this->hasTargetHeight()) {
$resized->setWidth(min(
$this->getProportionalWidth($size),
$this->getTargetWidth()
));
$resized->setHeight(min(
$this->getProportionalHeight($size),
$this->getTargetHeight()
));
} elseif ($this->hasTargetWidth()) {
$resized->setWidth($this->getTargetWidth());
$resized->setHeight($this->getProportionalHeight($size));
} elseif ($this->hasTargetHeight()) {
$resized->setWidth($this->getProportionalWidth($size));
$resized->setHeight($this->getTargetHeight());
}
return $resized;
}
/**
* Resize given size to target size proportinally but do not exceed original size
*/
public function scaleDown(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
if ($this->hasTargetWidth() && $this->hasTargetHeight()) {
$resized->setWidth(min(
$this->getProportionalWidth($size),
$this->getTargetWidth(),
$size->width()
));
$resized->setHeight(min(
$this->getProportionalHeight($size),
$this->getTargetHeight(),
$size->height()
));
} elseif ($this->hasTargetWidth()) {
$resized->setWidth(min(
$this->getTargetWidth(),
$size->width()
));
$resized->setHeight(min(
$this->getProportionalHeight($size),
$size->height()
));
} elseif ($this->hasTargetHeight()) {
$resized->setWidth(min(
$this->getProportionalWidth($size),
$size->width()
));
$resized->setHeight(min(
$this->getTargetHeight(),
$size->height()
));
}
return $resized;
}
/**
* Scale given size to cover target size
*
* @param SizeInterface $size Size to be resized
* @throws GeometryException
*/
public function cover(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
// auto height
$resized->setWidth($this->getTargetWidth());
$resized->setHeight($this->getProportionalHeight($size));
if ($resized->fitsInto($this->getTargetSize())) {
// auto width
$resized->setWidth($this->getProportionalWidth($size));
$resized->setHeight($this->getTargetHeight());
}
return $resized;
}
/**
* Scale given size to contain target size
*
* @param SizeInterface $size Size to be resized
* @throws GeometryException
*/
public function contain(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
// auto height
$resized->setWidth($this->getTargetWidth());
$resized->setHeight($this->getProportionalHeight($size));
if (!$resized->fitsInto($this->getTargetSize())) {
// auto width
$resized->setWidth($this->getProportionalWidth($size));
$resized->setHeight($this->getTargetHeight());
}
return $resized;
}
/**
* Scale given size to contain target size but prevent upsizing
*
* @param SizeInterface $size Size to be resized
* @throws GeometryException
*/
public function containDown(SizeInterface $size): SizeInterface
{
$resized = new Rectangle($size->width(), $size->height());
// auto height
$resized->setWidth(
min($size->width(), $this->getTargetWidth())
);
$resized->setHeight(
min($size->height(), $this->getProportionalHeight($size))
);
if (!$resized->fitsInto($this->getTargetSize())) {
// auto width
$resized->setWidth(
min($size->width(), $this->getProportionalWidth($size))
);
$resized->setHeight(
min($size->height(), $this->getTargetHeight())
);
}
return $resized;
}
/**
* Crop target size out of given size at given position (i.e. move the pivot point)
*/
public function crop(SizeInterface $size, string $position = 'top-left'): SizeInterface
{
return $this->resize($size)->alignPivotTo(
$size->movePivot($position),
$position
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/DataUriImageDecoder.php | src/Decoders/DataUriImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class DataUriImageDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/FilePointerImageDecoder.php | src/Decoders/FilePointerImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class FilePointerImageDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/BinaryImageDecoder.php | src/Decoders/BinaryImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class BinaryImageDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/FilePathImageDecoder.php | src/Decoders/FilePathImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class FilePathImageDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/SplFileInfoImageDecoder.php | src/Decoders/SplFileInfoImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class SplFileInfoImageDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/EncodedImageObjectDecoder.php | src/Decoders/EncodedImageObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class EncodedImageObjectDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/Base64ImageDecoder.php | src/Decoders/Base64ImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class Base64ImageDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/NativeObjectDecoder.php | src/Decoders/NativeObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
class NativeObjectDecoder extends SpecializableDecoder
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/ImageObjectDecoder.php | src/Decoders/ImageObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\AbstractDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ColorInterface;
class ImageObjectDecoder extends AbstractDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_a($input, ImageInterface::class)) {
throw new DecoderException('Unable to decode input');
}
return $input;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Decoders/ColorObjectDecoder.php | src/Decoders/ColorObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Decoders;
use Intervention\Image\Drivers\AbstractDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class ColorObjectDecoder extends AbstractDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_a($input, ColorInterface::class)) {
throw new DecoderException('Unable to decode input');
}
return $input;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Analyzers/ColorspaceAnalyzer.php | src/Analyzers/ColorspaceAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Analyzers;
use Intervention\Image\Drivers\SpecializableAnalyzer;
class ColorspaceAnalyzer extends SpecializableAnalyzer
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Analyzers/HeightAnalyzer.php | src/Analyzers/HeightAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Analyzers;
use Intervention\Image\Drivers\SpecializableAnalyzer;
class HeightAnalyzer extends SpecializableAnalyzer
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Analyzers/PixelColorsAnalyzer.php | src/Analyzers/PixelColorsAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Analyzers;
use Intervention\Image\Drivers\SpecializableAnalyzer;
class PixelColorsAnalyzer extends SpecializableAnalyzer
{
public function __construct(
public int $x,
public int $y
) {
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Analyzers/WidthAnalyzer.php | src/Analyzers/WidthAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Analyzers;
use Intervention\Image\Drivers\SpecializableAnalyzer;
class WidthAnalyzer extends SpecializableAnalyzer
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Analyzers/ResolutionAnalyzer.php | src/Analyzers/ResolutionAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Analyzers;
use Intervention\Image\Drivers\SpecializableAnalyzer;
class ResolutionAnalyzer extends SpecializableAnalyzer
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Analyzers/PixelColorAnalyzer.php | src/Analyzers/PixelColorAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Analyzers;
use Intervention\Image\Drivers\SpecializableAnalyzer;
class PixelColorAnalyzer extends SpecializableAnalyzer
{
public function __construct(
public int $x,
public int $y,
public int $frame_key = 0
) {
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Analyzers/ProfileAnalyzer.php | src/Analyzers/ProfileAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Analyzers;
use Intervention\Image\Drivers\SpecializableAnalyzer;
class ProfileAnalyzer extends SpecializableAnalyzer
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/BlendTransparencyModifier.php | src/Modifiers/BlendTransparencyModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Colors\Rgb\Channels\Blue;
use Intervention\Image\Colors\Rgb\Channels\Green;
use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DriverInterface;
class BlendTransparencyModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public mixed $color = null)
{
//
}
/**
* Decode blending color of current modifier with given driver. Possible
* (semi-)transparent alpha channel values are made opaque.
*
* @throws RuntimeException
* @throws ColorException
*/
protected function blendingColor(DriverInterface $driver): ColorInterface
{
// decode blending color
$color = $driver->handleInput(
$this->color ?: $driver->config()->blendingColor
);
// replace alpha channel value with opaque value
if ($color->isTransparent()) {
return new Color(
$color->channel(Red::class)->value(),
$color->channel(Green::class)->value(),
$color->channel(Blue::class)->value(),
);
}
return $color;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ResizeCanvasRelativeModifier.php | src/Modifiers/ResizeCanvasRelativeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
class ResizeCanvasRelativeModifier extends ResizeCanvasModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/DrawPixelModifier.php | src/Modifiers/DrawPixelModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Interfaces\PointInterface;
class DrawPixelModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public PointInterface $position,
public mixed $color
) {
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/TextModifier.php | src/Modifiers/TextModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Interfaces\PointInterface;
class TextModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public string $text,
public PointInterface $position,
public FontInterface $font
) {
//
}
/**
* Decode text color
*
* The text outline effect is drawn with a trick by plotting additional text
* under the actual text with an offset in the color of the outline effect.
* For this reason, no colors with transparency can be used for the text
* color or the color of the stroke effect, as this would be superimposed.
*
* @throws RuntimeException
* @throws ColorException
*/
protected function textColor(): ColorInterface
{
$color = $this->driver()->handleInput($this->font->color());
if ($this->font->hasStrokeEffect() && $color->isTransparent()) {
throw new ColorException(
'The text color must be fully opaque when using the stroke effect.'
);
}
return $color;
}
/**
* Decode outline stroke color
*
* @throws RuntimeException
* @throws ColorException
*/
protected function strokeColor(): ColorInterface
{
$color = $this->driver()->handleInput($this->font->strokeColor());
if ($color->isTransparent()) {
throw new ColorException(
'The stroke color must be fully opaque.'
);
}
return $color;
}
/**
* Return array of offset points to draw text stroke effect below the actual text
*
* @return array<PointInterface>
*/
protected function strokeOffsets(FontInterface $font): array
{
$offsets = [];
if ($font->strokeWidth() <= 0) {
return $offsets;
}
for ($x = $font->strokeWidth() * -1; $x <= $font->strokeWidth(); $x++) {
for ($y = $font->strokeWidth() * -1; $y <= $font->strokeWidth(); $y++) {
$offsets[] = new Point($x, $y);
}
}
return $offsets;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ResizeModifier.php | src/Modifiers/ResizeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class ResizeModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public ?int $width = null, public ?int $height = null)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/DrawBezierModifier.php | src/Modifiers/DrawBezierModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Geometry\Bezier;
use Intervention\Image\Interfaces\DrawableInterface;
class DrawBezierModifier extends AbstractDrawModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public Bezier $drawable)
{
//
}
/**
* Return object to be drawn
*/
public function drawable(): DrawableInterface
{
return $this->drawable;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/RotateModifier.php | src/Modifiers/RotateModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class RotateModifier extends SpecializableModifier
{
public function __construct(public float $angle, public mixed $background)
{
//
}
/**
* Restrict rotations beyond 360 degrees
* because the end result is the same
*/
public function rotationAngle(): float
{
return fmod($this->angle, 360);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/PadModifier.php | src/Modifiers/PadModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class PadModifier extends ContainModifier
{
public function getCropSize(ImageInterface $image): SizeInterface
{
return $image->size()
->containMax(
$this->width,
$this->height
)
->alignPivotTo(
$this->getResizeSize($image),
$this->position
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/CropModifier.php | src/Modifiers/CropModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class CropModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public int $width,
public int $height,
public int $offset_x = 0,
public int $offset_y = 0,
public mixed $background = 'ffffff',
public string $position = 'top-left'
) {
//
}
/**
* @throws RuntimeException
*/
public function crop(ImageInterface $image): SizeInterface
{
$crop = new Rectangle($this->width, $this->height);
$crop->align($this->position);
return $crop->alignPivotTo(
$image->size(),
$this->position
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/FillModifier.php | src/Modifiers/FillModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Interfaces\PointInterface;
class FillModifier extends SpecializableModifier
{
public function __construct(
public mixed $color,
public ?PointInterface $position = null
) {
//
}
public function hasPosition(): bool
{
return $this->position instanceof PointInterface;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ColorizeModifier.php | src/Modifiers/ColorizeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class ColorizeModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public int $red = 0,
public int $green = 0,
public int $blue = 0
) {
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ColorspaceModifier.php | src/Modifiers/ColorspaceModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Interfaces\ColorspaceInterface;
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\NotSupportedException;
class ColorspaceModifier extends SpecializableModifier
{
public function __construct(public string|ColorspaceInterface $target)
{
//
}
/**
* @throws NotSupportedException
*/
public function targetColorspace(): ColorspaceInterface
{
if (is_object($this->target)) {
return $this->target;
}
if (in_array($this->target, ['rgb', 'RGB', RgbColorspace::class])) {
return new RgbColorspace();
}
if (in_array($this->target, ['cmyk', 'CMYK', CmykColorspace::class])) {
return new CmykColorspace();
}
throw new NotSupportedException('Given colorspace is not supported.');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/FlopModifier.php | src/Modifiers/FlopModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class FlopModifier extends SpecializableModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/PixelateModifier.php | src/Modifiers/PixelateModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class PixelateModifier extends SpecializableModifier
{
public function __construct(public int $size)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/TrimModifier.php | src/Modifiers/TrimModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class TrimModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public int $tolerance = 0)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/InvertModifier.php | src/Modifiers/InvertModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class InvertModifier extends SpecializableModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/DrawRectangleModifier.php | src/Modifiers/DrawRectangleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\DrawableInterface;
class DrawRectangleModifier extends AbstractDrawModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public Rectangle $drawable)
{
//
}
/**
* Return object to be drawn
*/
public function drawable(): DrawableInterface
{
return $this->drawable;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/AbstractDrawModifier.php | src/Modifiers/AbstractDrawModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DrawableInterface;
use RuntimeException;
abstract class AbstractDrawModifier extends SpecializableModifier
{
/**
* Return the drawable object which will be rendered by the modifier
*/
abstract public function drawable(): DrawableInterface;
/**
* @throws RuntimeException
*/
public function backgroundColor(): ColorInterface
{
try {
$color = $this->driver()->handleInput($this->drawable()->backgroundColor());
} catch (DecoderException) {
return $this->driver()->handleInput('transparent');
}
return $color;
}
/**
* @throws RuntimeException
*/
public function borderColor(): ColorInterface
{
try {
$color = $this->driver()->handleInput($this->drawable()->borderColor());
} catch (DecoderException) {
return $this->driver()->handleInput('transparent');
}
return $color;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/AlignRotationModifier.php | src/Modifiers/AlignRotationModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class AlignRotationModifier extends SpecializableModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/DrawPolygonModifier.php | src/Modifiers/DrawPolygonModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Geometry\Polygon;
use Intervention\Image\Interfaces\DrawableInterface;
class DrawPolygonModifier extends AbstractDrawModifier
{
public function __construct(public Polygon $drawable)
{
//
}
public function drawable(): DrawableInterface
{
return $this->drawable;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ScaleModifier.php | src/Modifiers/ScaleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
class ScaleModifier extends ResizeModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ContainModifier.php | src/Modifiers/ContainModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ContainModifier extends SpecializableModifier
{
public function __construct(
public int $width,
public int $height,
public mixed $background = 'ffffff',
public string $position = 'center'
) {
//
}
/**
* @throws RuntimeException
*/
public function getCropSize(ImageInterface $image): SizeInterface
{
return $image->size()
->contain(
$this->width,
$this->height
)
->alignPivotTo(
$this->getResizeSize($image),
$this->position
);
}
public function getResizeSize(ImageInterface $image): SizeInterface
{
return new Rectangle($this->width, $this->height);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/BrightnessModifier.php | src/Modifiers/BrightnessModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class BrightnessModifier extends SpecializableModifier
{
public function __construct(public int $level)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/DrawEllipseModifier.php | src/Modifiers/DrawEllipseModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Geometry\Ellipse;
use Intervention\Image\Interfaces\DrawableInterface;
class DrawEllipseModifier extends AbstractDrawModifier
{
public function __construct(public Ellipse $drawable)
{
//
}
public function drawable(): DrawableInterface
{
return $this->drawable;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/GammaModifier.php | src/Modifiers/GammaModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class GammaModifier extends SpecializableModifier
{
public function __construct(public float $gamma)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/CoverModifier.php | src/Modifiers/CoverModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class CoverModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public int $width,
public int $height,
public string $position = 'center'
) {
//
}
/**
* @throws RuntimeException
*/
public function getCropSize(ImageInterface $image): SizeInterface
{
$imagesize = $image->size();
$crop = new Rectangle($this->width, $this->height);
return $crop->contain(
$imagesize->width(),
$imagesize->height()
)->alignPivotTo($imagesize, $this->position);
}
/**
* @throws RuntimeException
*/
public function getResizeSize(SizeInterface $size): SizeInterface
{
return $size->resize($this->width, $this->height);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ProfileModifier.php | src/Modifiers/ProfileModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Interfaces\ProfileInterface;
class ProfileModifier extends SpecializableModifier
{
public function __construct(public ProfileInterface $profile)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/SliceAnimationModifier.php | src/Modifiers/SliceAnimationModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class SliceAnimationModifier extends SpecializableModifier
{
public function __construct(public int $offset = 0, public ?int $length = null)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ScaleDownModifier.php | src/Modifiers/ScaleDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
class ScaleDownModifier extends ScaleModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/FlipModifier.php | src/Modifiers/FlipModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class FlipModifier extends SpecializableModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ProfileRemovalModifier.php | src/Modifiers/ProfileRemovalModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class ProfileRemovalModifier extends SpecializableModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/GreyscaleModifier.php | src/Modifiers/GreyscaleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class GreyscaleModifier extends SpecializableModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ResolutionModifier.php | src/Modifiers/ResolutionModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class ResolutionModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public float $x, public float $y)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ResizeDownModifier.php | src/Modifiers/ResizeDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
class ResizeDownModifier extends ResizeModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/RemoveAnimationModifier.php | src/Modifiers/RemoveAnimationModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
class RemoveAnimationModifier extends SpecializableModifier
{
public function __construct(public int|string $position = 0)
{
//
}
/**
* @throws RuntimeException
*/
protected function selectedFrame(ImageInterface $image): FrameInterface
{
return $image->core()->frame($this->normalizePosition($image));
}
/**
* Return the position of the selected frame as integer
*
* @throws InputException
*/
protected function normalizePosition(ImageInterface $image): int
{
if (is_int($this->position)) {
return $this->position;
}
if (is_numeric($this->position)) {
return (int) $this->position;
}
// calculate position from percentage value
if (preg_match("/^(?P<percent>[0-9]{1,3})%$/", $this->position, $matches) != 1) {
throw new InputException(
'Position must be either integer or a percent value as string.'
);
}
$total = count($image);
$position = intval(round($total / 100 * intval($matches['percent'])));
return $position == $total ? $position - 1 : $position;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/QuantizeColorsModifier.php | src/Modifiers/QuantizeColorsModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class QuantizeColorsModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public int $limit,
public mixed $background = 'ffffff'
) {
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/PlaceModifier.php | src/Modifiers/PlaceModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\PointInterface;
class PlaceModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public mixed $element,
public string $position = 'top-left',
public int $offset_x = 0,
public int $offset_y = 0,
public int $opacity = 100
) {
//
}
/**
* @throws RuntimeException
*/
public function getPosition(ImageInterface $image, ImageInterface $watermark): PointInterface
{
$image_size = $image->size()->movePivot(
$this->position,
$this->offset_x,
$this->offset_y
);
$watermark_size = $watermark->size()->movePivot(
$this->position
);
return $image_size->relativePositionTo($watermark_size);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/BlurModifier.php | src/Modifiers/BlurModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class BlurModifier extends SpecializableModifier
{
public function __construct(public int $amount)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/SharpenModifier.php | src/Modifiers/SharpenModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class SharpenModifier extends SpecializableModifier
{
public function __construct(public int $amount)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ResizeCanvasModifier.php | src/Modifiers/ResizeCanvasModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ResizeCanvasModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(
public ?int $width = null,
public ?int $height = null,
public mixed $background = 'ffffff',
public string $position = 'center'
) {
//
}
/**
* Build the crop size to be used for the ResizeCanvas process
*
* @throws RuntimeException
*/
protected function cropSize(ImageInterface $image, bool $relative = false): SizeInterface
{
$size = match ($relative) {
true => new Rectangle(
is_null($this->width) ? $image->width() : $image->width() + $this->width,
is_null($this->height) ? $image->height() : $image->height() + $this->height,
),
default => new Rectangle(
is_null($this->width) ? $image->width() : $this->width,
is_null($this->height) ? $image->height() : $this->height,
),
};
return $size->alignPivotTo($image->size(), $this->position);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/ContrastModifier.php | src/Modifiers/ContrastModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
class ContrastModifier extends SpecializableModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public int $level)
{
//
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/CoverDownModifier.php | src/Modifiers/CoverDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
class CoverDownModifier extends CoverModifier
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Modifiers/DrawLineModifier.php | src/Modifiers/DrawLineModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Geometry\Line;
use Intervention\Image\Interfaces\DrawableInterface;
class DrawLineModifier extends AbstractDrawModifier
{
/**
* Create new modifier object
*
* @return void
*/
public function __construct(public Line $drawable)
{
//
}
/**
* Return object to be drawn
*/
public function drawable(): DrawableInterface
{
return $this->drawable;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Typography/Font.php | src/Typography/Font.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Typography;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Interfaces\FontInterface;
class Font implements FontInterface
{
protected float $size = 12;
protected float $angle = 0;
protected mixed $color = '000000';
protected mixed $strokeColor = 'ffffff';
protected int $strokeWidth = 0;
protected ?string $filename = null;
protected string $alignment = 'left';
protected string $valignment = 'bottom';
protected float $lineHeight = 1.25;
protected ?int $wrapWidth = null;
public function __construct(?string $filename = null)
{
$this->filename = $filename;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setSize()
*/
public function setSize(float $size): FontInterface
{
$this->size = $size;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::size()
*/
public function size(): float
{
return $this->size;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setAngle()
*/
public function setAngle(float $angle): FontInterface
{
$this->angle = $angle;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::angle()
*/
public function angle(): float
{
return $this->angle;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setFilename()
*
* @throws FontException
*/
public function setFilename(string $filename): FontInterface
{
if (!file_exists($filename)) {
throw new FontException('Font file ' . $filename . ' does not exist.');
}
$this->filename = $filename;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::filename()
*/
public function filename(): ?string
{
return $this->filename;
}
/**
* {@inheritdoc}
*
* @see FontInterface::hasFilename()
*/
public function hasFilename(): bool
{
return !is_null($this->filename) && is_file($this->filename);
}
/**
* {@inheritdoc}
*
* @see FontInterface::setColor()
*/
public function setColor(mixed $color): FontInterface
{
$this->color = $color;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::color()
*/
public function color(): mixed
{
return $this->color;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setStrokeColor()
*/
public function setStrokeColor(mixed $color): FontInterface
{
$this->strokeColor = $color;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::strokeColor()
*/
public function strokeColor(): mixed
{
return $this->strokeColor;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setStrokeWidth()
*/
public function setStrokeWidth(int $width): FontInterface
{
if (!in_array($width, range(0, 10))) {
throw new FontException(
'The stroke width must be in the range from 0 to 10.'
);
}
$this->strokeWidth = $width;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::strokeWidth()
*/
public function strokeWidth(): int
{
return $this->strokeWidth;
}
/**
* {@inheritdoc}
*
* @see FontInterface::hasStrokeEffect()
*/
public function hasStrokeEffect(): bool
{
return $this->strokeWidth > 0;
}
/**
* {@inheritdoc}
*
* @see FontInterface::alignment()
*/
public function alignment(): string
{
return $this->alignment;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setAlignment()
*/
public function setAlignment(string $value): FontInterface
{
$this->alignment = $value;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::valignment()
*/
public function valignment(): string
{
return $this->valignment;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setValignment()
*/
public function setValignment(string $value): FontInterface
{
$this->valignment = $value;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setLineHeight()
*/
public function setLineHeight(float $height): FontInterface
{
$this->lineHeight = $height;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::lineHeight()
*/
public function lineHeight(): float
{
return $this->lineHeight;
}
/**
* {@inheritdoc}
*
* @see FontInterface::setWrapWidth()
*/
public function setWrapWidth(?int $width): FontInterface
{
$this->wrapWidth = $width;
return $this;
}
/**
* {@inheritdoc}
*
* @see FontInterface::wrapWidth()
*/
public function wrapWidth(): ?int
{
return $this->wrapWidth;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Typography/Line.php | src/Typography/Line.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Typography;
use ArrayIterator;
use Countable;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\PointInterface;
use IteratorAggregate;
use Stringable;
use Traversable;
/**
* @implements IteratorAggregate<string>
*/
class Line implements IteratorAggregate, Countable, Stringable
{
/**
* Segments (usually individual words including punctuation marks) of the line
*
* @var array<string>
*/
protected array $segments = [];
/**
* Create new text line object with given text & position
*
* @return void
*/
public function __construct(
?string $text = null,
protected PointInterface $position = new Point()
) {
if (is_string($text)) {
$this->segments = $this->wordsSeperatedBySpaces($text) ? explode(" ", $text) : mb_str_split($text);
}
}
/**
* Add word to current line
*/
public function add(string $word): self
{
$this->segments[] = $word;
return $this;
}
/**
* Returns Iterator
*
* @return Traversable<string>
*/
public function getIterator(): Traversable
{
return new ArrayIterator($this->segments);
}
/**
* Get Position of line
*/
public function position(): PointInterface
{
return $this->position;
}
/**
* Set position of current line
*/
public function setPosition(PointInterface $point): self
{
$this->position = $point;
return $this;
}
/**
* Count segments (individual words including punctuation marks) of line
*/
public function count(): int
{
return count($this->segments);
}
/**
* Count characters of line
*/
public function length(): int
{
return mb_strlen((string) $this);
}
/**
* Dermine if words are sperarated by spaces in the written language of the given text
*/
private function wordsSeperatedBySpaces(string $text): bool
{
return 1 !== preg_match(
'/[' .
'\x{4E00}-\x{9FFF}' . // CJK Unified Ideographs (chinese)
'\x{3400}-\x{4DBF}' . // CJK Unified Ideographs Extension A (chinese)
'\x{3040}-\x{309F}' . // hiragana (japanese)
'\x{30A0}-\x{30FF}' . // katakana (japanese)
'\x{0E00}-\x{0E7F}' . // thai
']/u',
$text
);
}
/**
* Cast line to string
*/
public function __toString(): string
{
$string = implode("", $this->segments);
if ($this->wordsSeperatedBySpaces($string)) {
return implode(" ", $this->segments);
}
return $string;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Typography/FontFactory.php | src/Typography/FontFactory.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Typography;
use Closure;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Interfaces\FontInterface;
class FontFactory
{
protected FontInterface $font;
/**
* Create new instance
*
* @param Closure|FontInterface $init
* @throws FontException
* @return void
*/
public function __construct(callable|Closure|FontInterface $init)
{
$this->font = is_a($init, FontInterface::class) ? $init : new Font();
if (is_callable($init)) {
$init($this);
}
}
/**
* Set the filename of the font to be built
*/
public function filename(string $value): self
{
$this->font->setFilename($value);
return $this;
}
/**
* {@inheritdoc}
*
* @see self::filename()
*/
public function file(string $value): self
{
return $this->filename($value);
}
/**
* Set outline stroke effect for the font to be built
*
* @throws FontException
*/
public function stroke(mixed $color, int $width = 1): self
{
$this->font->setStrokeWidth($width);
$this->font->setStrokeColor($color);
return $this;
}
/**
* Set color for the font to be built
*/
public function color(mixed $value): self
{
$this->font->setColor($value);
return $this;
}
/**
* Set the size for the font to be built
*/
public function size(float $value): self
{
$this->font->setSize($value);
return $this;
}
/**
* Set the horizontal alignment of the font to be built
*/
public function align(string $value): self
{
$this->font->setAlignment($value);
return $this;
}
/**
* Set the vertical alignment of the font to be built
*/
public function valign(string $value): self
{
$this->font->setValignment($value);
return $this;
}
/**
* Set the line height of the font to be built
*/
public function lineHeight(float $value): self
{
$this->font->setLineHeight($value);
return $this;
}
/**
* Set the rotation angle of the font to be built
*/
public function angle(float $value): self
{
$this->font->setAngle($value);
return $this;
}
/**
* Set the maximum width of the text block to be built
*/
public function wrap(int $width): self
{
$this->font->setWrapWidth($width);
return $this;
}
/**
* Build font
*/
public function __invoke(): FontInterface
{
return $this->font;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Typography/TextBlock.php | src/Typography/TextBlock.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Typography;
use Intervention\Image\Collection;
class TextBlock extends Collection
{
/**
* Create new text block object
*
* @return void
*/
public function __construct(string $text)
{
foreach (explode("\n", $text) as $line) {
$this->push(new Line($line));
}
}
/**
* Return array of lines in text block
*
* @return array<Line>
*/
public function lines(): array
{
return $this->items;
}
/**
* Set lines of the text block
*
* @param array<Line> $lines
*/
public function setLines(array $lines): self
{
$this->items = $lines;
return $this;
}
/**
* Get line by given key
*/
public function line(mixed $key): ?Line
{
if (!array_key_exists($key, $this->lines())) {
return null;
}
return $this->lines()[$key];
}
/**
* Return line with most characters of text block
*/
public function longestLine(): Line
{
$lines = $this->lines();
usort($lines, function (Line $a, Line $b): int {
if ($a->length() === $b->length()) {
return 0;
}
return $a->length() > $b->length() ? -1 : 1;
});
return $lines[0];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/BaseTestCase.php | tests/BaseTestCase.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests;
use Intervention\Image\Colors\Rgb\Channels\Alpha;
use Intervention\Image\Colors\Rgb\Channels\Blue;
use Intervention\Image\Colors\Rgb\Channels\Green;
use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Colors\Rgb\Color as RgbColor;
use Intervention\Image\EncodedImage;
use Intervention\Image\Interfaces\ColorInterface;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use PHPUnit\Framework\ExpectationFailedException;
abstract class BaseTestCase extends MockeryTestCase
{
public static function getTestResourcePath(string $filename = 'test.jpg'): string
{
return sprintf('%s/resources/%s', __DIR__, $filename);
}
public static function getTestResourceData(string $filename = 'test.jpg'): string
{
return file_get_contents(self::getTestResourcePath($filename));
}
public static function getTestResourcePointer(string $filename = 'test.jpg'): mixed
{
$pointer = fopen('php://temp', 'rw');
fwrite($pointer, self::getTestResourceData($filename));
rewind($pointer);
return $pointer;
}
/**
* Assert that given color equals the given color channel values in the given optional tolerance
*
* @throws ExpectationFailedException
*/
protected function assertColor(int $r, int $g, int $b, int $a, ColorInterface $color, int $tolerance = 0): void
{
// build errorMessage
$errorMessage = function (int $r, int $g, $b, int $a, ColorInterface $color): string {
$color = 'rgba(' . implode(', ', [
$color->channel(Red::class)->value(),
$color->channel(Green::class)->value(),
$color->channel(Blue::class)->value(),
$color->channel(Alpha::class)->value(),
]) . ')';
return implode(' ', [
'Failed asserting that color',
$color,
'equals',
'rgba(' . $r . ', ' . $g . ', ' . $b . ', ' . $a . ')'
]);
};
// build color channel value range
$range = function (int $base, int $tolerance): array {
return range(max($base - $tolerance, 0), min($base + $tolerance, 255));
};
$this->assertContains(
$color->channel(Red::class)->value(),
$range($r, $tolerance),
$errorMessage($r, $g, $b, $a, $color)
);
$this->assertContains(
$color->channel(Green::class)->value(),
$range($g, $tolerance),
$errorMessage($r, $g, $b, $a, $color)
);
$this->assertContains(
$color->channel(Blue::class)->value(),
$range($b, $tolerance),
$errorMessage($r, $g, $b, $a, $color)
);
$this->assertContains(
$color->channel(Alpha::class)->value(),
$range($a, $tolerance),
$errorMessage($r, $g, $b, $a, $color)
);
}
protected function assertTransparency(ColorInterface $color): void
{
$this->assertInstanceOf(RgbColor::class, $color);
$channel = $color->channel(Alpha::class);
$this->assertEquals(0, $channel->value(), 'Detected color ' . $color . ' is not completely transparent.');
}
protected function assertMediaType(string|array $allowed, string|EncodedImage $input): void
{
$pointer = fopen('php://temp', 'rw');
fwrite($pointer, (string) $input);
rewind($pointer);
$detected = mime_content_type($pointer);
fclose($pointer);
$allowed = is_string($allowed) ? [$allowed] : $allowed;
$this->assertTrue(
in_array($detected, $allowed),
'Detected media type "' . $detected . '" is not: ' . implode(', ', $allowed),
);
}
protected function assertMediaTypeBitmap(string|EncodedImage $input): void
{
$this->assertMediaType([
'image/x-ms-bmp',
'image/bmp',
'bmp',
'ms-bmp',
'x-bitmap',
'x-bmp',
'x-ms-bmp',
'x-win-bitmap',
'x-windows-bmp',
'x-xbitmap',
'image/ms-bmp',
'image/x-bitmap',
'image/x-bmp',
'image/x-ms-bmp',
'image/x-win-bitmap',
'image/x-windows-bmp',
'image/x-xbitmap',
], $input);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/ImagickTestCase.php | tests/ImagickTestCase.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests;
use Imagick;
use ImagickException;
use ImagickPixel;
use Intervention\Image\Decoders\FilePathImageDecoder;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Image;
abstract class ImagickTestCase extends BaseTestCase
{
public static function readTestImage(string $filename = 'test.jpg'): Image
{
return (new Driver())->specialize(new FilePathImageDecoder())->decode(
static::getTestResourcePath($filename)
);
}
/**
* Create test image with red (#ff0000) background
*
* @throws ImagickException
*/
public static function createTestImage(int $width, int $height): Image
{
$background = new ImagickPixel('rgb(255, 0, 0)');
$imagick = new Imagick();
$imagick->newImage($width, $height, $background, 'png');
$imagick->setType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setColorspace(Imagick::COLORSPACE_SRGB);
$imagick->setImageResolution(96, 96);
$imagick->setImageBackgroundColor($background);
return new Image(
new Driver(),
new Core($imagick)
);
}
public static function createTestAnimation(): Image
{
$imagick = new Imagick();
$imagick->setFormat('gif');
for ($i = 0; $i < 3; $i++) {
$frame = new Imagick();
$frame->newImage(3, 2, new ImagickPixel('rgb(255, 0, 0)'), 'gif');
$frame->setImageDelay(10);
$imagick->addImage($frame);
}
return new Image(
new Driver(),
new Core($imagick)
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/GdTestCase.php | tests/GdTestCase.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests;
use Intervention\Image\Decoders\FilePathImageDecoder;
use Intervention\Image\Drivers\Gd\Core;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Drivers\Gd\Frame;
use Intervention\Image\Image;
abstract class GdTestCase extends BaseTestCase
{
public static function readTestImage(string $filename = 'test.jpg'): Image
{
return (new Driver())->specialize(new FilePathImageDecoder())->decode(
static::getTestResourcePath($filename)
);
}
public static function createTestImage(int $width, int $height): Image
{
$gd = imagecreatetruecolor($width, $height);
imagefill($gd, 0, 0, imagecolorallocate($gd, 255, 0, 0));
return new Image(
new Driver(),
new Core([
new Frame($gd)
])
);
}
public static function createTestAnimation(): Image
{
$gd1 = imagecreatetruecolor(3, 2);
imagefill($gd1, 0, 0, imagecolorallocate($gd1, 255, 0, 0));
$gd2 = imagecreatetruecolor(3, 2);
imagefill($gd2, 0, 0, imagecolorallocate($gd1, 0, 255, 0));
$gd3 = imagecreatetruecolor(3, 2);
imagefill($gd3, 0, 0, imagecolorallocate($gd1, 0, 0, 255));
return new Image(
new Driver(),
new Core([
new Frame($gd1),
new Frame($gd2),
new Frame($gd3),
])
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Traits/CanInspectPngFormat.php | tests/Traits/CanInspectPngFormat.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Traits;
use Intervention\Image\EncodedImage;
use Intervention\Image\Traits\CanBuildFilePointer;
trait CanInspectPngFormat
{
use CanBuildFilePointer;
/**
* Checks if the given image data is interlaced encoded PNG format
*/
private function isInterlacedPng(EncodedImage $image): bool
{
$f = $image->toFilePointer();
$contents = fread($f, 32);
fclose($f);
return ord($contents[28]) != 0;
}
/**
* Try to detect PNG color type from given binary data
*/
private function pngColorType(EncodedImage $image): string
{
$data = $image->toString();
if (substr($data, 1, 3) !== 'PNG') {
return 'unkown';
}
$pos = strpos($data, 'IHDR');
$type = substr($data, $pos + 13, 1);
return match (unpack('C', $type)[1]) {
0 => 'grayscale',
2 => 'truecolor',
3 => 'indexed',
4 => 'grayscale-alpha',
6 => 'truecolor-alpha',
default => 'unknown',
};
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Traits/CanDetectProgressiveJpeg.php | tests/Traits/CanDetectProgressiveJpeg.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Traits;
use Intervention\Image\EncodedImage;
use Intervention\Image\Traits\CanBuildFilePointer;
trait CanDetectProgressiveJpeg
{
use CanBuildFilePointer;
/**
* Checks if the given image data is progressive encoded Jpeg format
*
* @param EncodedImage $imagedata
*/
private function isProgressiveJpeg(EncodedImage $image): bool
{
$f = $image->toFilePointer();
while (!feof($f)) {
if (unpack('C', fread($f, 1))[1] !== 0xff) {
return false;
}
$blockType = unpack('C', fread($f, 1))[1];
switch (true) {
case $blockType == 0xd8:
case $blockType >= 0xd0 && $blockType <= 0xd7:
break;
case $blockType == 0xc0:
fclose($f);
return false;
case $blockType == 0xc2:
fclose($f);
return true;
case $blockType == 0xd9:
break 2;
default:
$blockSize = unpack('n', fread($f, 2))[1];
fseek($f, $blockSize - 2, SEEK_CUR);
break;
}
}
fclose($f);
return false;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Feature/Gd/ConvertPngGif.php | tests/Feature/Gd/ConvertPngGif.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Feature\Gd;
use Intervention\Image\ImageManager;
use Intervention\Image\Tests\GdTestCase;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
#[RequiresPhpExtension('gd')]
class ConvertPngGif extends GdTestCase
{
public function testConversionKeepsTransparency(): void
{
$converted = ImageManager::gd()
->read(
$this->readTestImage('circle.png')->toGif()
);
$this->assertTransparency($converted->pickColor(0, 0));
$this->assertColor(4, 2, 4, 255, $converted->pickColor(25, 25), 4);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Feature/Imagick/ConvertPngGif.php | tests/Feature/Imagick/ConvertPngGif.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Feature\Imagick;
use Intervention\Image\ImageManager;
use Intervention\Image\Tests\ImagickTestCase;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
#[RequiresPhpExtension('imagick')]
class ConvertPngGif extends ImagickTestCase
{
public function testConversionKeepsTransparency(): void
{
$converted = ImageManager::imagick()
->read(
$this->readTestImage('circle.png')->toGif()
);
$this->assertTransparency($converted->pickColor(0, 0));
$this->assertColor(4, 2, 4, 255, $converted->pickColor(25, 25), 4);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Feature/Imagick/CropResizePngTest.php | tests/Feature/Imagick/CropResizePngTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Feature\Imagick;
use Intervention\Image\Tests\ImagickTestCase;
class CropResizePngTest extends ImagickTestCase
{
public function testCropResizePng(): void
{
$image = $this->readTestImage('tile.png');
$image->crop(100, 100);
$image->resize(200, 200);
$this->assertTransparency($image->pickColor(7, 22));
$this->assertTransparency($image->pickColor(22, 7));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/CollectionTest.php | tests/Unit/CollectionTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use PHPUnit\Framework\Attributes\CoversClass;
use Intervention\Image\Collection;
use Intervention\Image\Tests\BaseTestCase;
#[CoversClass(Collection::class)]
final class CollectionTest extends BaseTestCase
{
public function testConstructor(): void
{
$collection = new Collection(['foo', 'bar', 'baz']);
$this->assertInstanceOf(Collection::class, $collection);
$collection = Collection::create(['foo', 'bar', 'baz']);
$this->assertInstanceOf(Collection::class, $collection);
}
public function testIterator(): void
{
$collection = new Collection(['foo', 'bar', 'baz']);
foreach ($collection as $key => $item) {
switch ($key) {
case 0:
$this->assertEquals('foo', $item);
break;
case 1:
$this->assertEquals('bar', $item);
break;
case 2:
$this->assertEquals('baz', $item);
break;
}
}
}
public function testCount(): void
{
$collection = new Collection(['foo', 'bar', 'baz']);
$this->assertEquals(3, $collection->count());
$this->assertEquals(3, count($collection));
}
public function testFilter(): void
{
$collection = new Collection(['foo', 'bar', 'baz']);
$this->assertEquals(3, $collection->count());
$collection = $collection->filter(function ($text): bool {
return substr($text, 0, 1) == 'b';
});
$this->assertEquals(2, $collection->count());
}
public function testFirstLast(): void
{
$collection = new Collection(['foo', 'bar', 'baz']);
$this->assertEquals('foo', $collection->first());
$this->assertEquals('baz', $collection->last());
$collection = new Collection();
$this->assertNull($collection->first());
$this->assertNull($collection->last());
}
public function testPush(): void
{
$collection = new Collection(['foo', 'bar', 'baz']);
$this->assertEquals(3, $collection->count());
$result = $collection->push('test');
$this->assertEquals(4, $collection->count());
$this->assertInstanceOf(Collection::class, $result);
}
public function testToArray(): void
{
$collection = new Collection(['foo', 'bar', 'baz']);
$this->assertEquals(['foo', 'bar', 'baz'], $collection->toArray());
}
public function testMap(): void
{
$collection = new Collection(['FOO', 'BAR', 'BAZ']);
$mapped = $collection->map(function ($item) {
return strtolower($item);
});
$this->assertInstanceOf(Collection::class, $collection);
$this->assertInstanceOf(Collection::class, $mapped);
$this->assertEquals(['FOO', 'BAR', 'BAZ'], $collection->toArray());
$this->assertEquals(['foo', 'bar', 'baz'], $mapped->toArray());
}
public function testGet(): void
{
// phpcs:ignore SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed
$collection = new Collection([
'first',
'second',
['testx' => 'x'],
'foo' => 'foo_value',
'bar' => 'bar_value',
'baz' => [
'test1' => '1',
'test2' => '2',
'test3' => [
'example' => 'value'
]
]
]);
$this->assertEquals('first', $collection->get(0));
$this->assertEquals('second', $collection->get(1));
$this->assertEquals('first', $collection->get('0'));
$this->assertEquals('second', $collection->get('1'));
$this->assertEquals('x', $collection->get('2.testx'));
$this->assertEquals('foo_value', $collection->get('foo'));
$this->assertEquals('bar_value', $collection->get('bar'));
$this->assertEquals('1', $collection->get('baz.test1'));
$this->assertEquals('2', $collection->get('baz.test2'));
$this->assertEquals('value', $collection->get('baz.test3.example'));
$this->assertEquals('value', $collection->get('baz.test3.example', 'default'));
$this->assertEquals('default', $collection->get('baz.test3.no', 'default'));
$this->assertEquals(['example' => 'value'], $collection->get('baz.test3'));
}
public function testGetAtPosition(): void
{
// phpcs:ignore SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed
$collection = new Collection([1, 2, 'foo' => 'bar']);
$this->assertEquals(1, $collection->getAtPosition(0));
$this->assertEquals(2, $collection->getAtPosition(1));
$this->assertEquals('bar', $collection->getAtPosition(2));
$this->assertNull($collection->getAtPosition(3));
$this->assertEquals('default', $collection->getAtPosition(3, 'default'));
}
public function testGetAtPositionEmpty(): void
{
$collection = new Collection();
$this->assertNull($collection->getAtPosition());
$this->assertEquals('default', $collection->getAtPosition(3, 'default'));
}
public function testEmpty(): void
{
$collection = new Collection([1, 2, 3]);
$this->assertEquals(3, $collection->count());
$result = $collection->empty();
$this->assertEquals(0, $collection->count());
$this->assertEquals(0, $result->count());
}
public function testSlice(): void
{
$collection = new Collection(['a', 'b', 'c', 'd', 'e', 'f']);
$this->assertEquals(6, $collection->count());
$result = $collection->slice(0, 3);
$this->assertEquals(['a', 'b', 'c'], $collection->toArray());
$this->assertEquals(['a', 'b', 'c'], $result->toArray());
$this->assertEquals('a', $result->get(0));
$this->assertEquals('b', $result->get(1));
$this->assertEquals('c', $result->get(2));
$result = $collection->slice(2, 1);
$this->assertEquals(['c'], $collection->toArray());
$this->assertEquals(['c'], $result->toArray());
$this->assertEquals('c', $result->get(0));
}
public function testSliceOutOfBounds(): void
{
$collection = new Collection(['a', 'b', 'c']);
$result = $collection->slice(6);
$this->assertEquals(0, $result->count());
$this->assertEquals([], $result->toArray());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/FileTest.php | tests/Unit/FileTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use PHPUnit\Framework\Attributes\CoversClass;
use Intervention\Image\File;
use Intervention\Image\Tests\BaseTestCase;
#[CoversClass(File::class)]
final class FileTest extends BaseTestCase
{
public function testConstructor(): void
{
$file = new File();
$this->assertInstanceOf(File::class, $file);
$file = new File('foo');
$this->assertInstanceOf(File::class, $file);
}
public function testConstructorFromString(): void
{
$file = new File('foo');
$this->assertInstanceOf(File::class, $file);
}
public function testConstructorFromResource(): void
{
$file = new File(fopen('php://temp', 'r'));
$this->assertInstanceOf(File::class, $file);
}
public function testFromPath(): void
{
$file = File::fromPath($this->getTestResourcePath());
$this->assertInstanceOf(File::class, $file);
$this->assertTrue($file->size() > 0);
}
public function testSave(): void
{
$file = new File('foo');
$filenames = [
__DIR__ . '/01_file_' . strval(hrtime(true)) . '.test',
__DIR__ . '/02_file_' . strval(hrtime(true)) . '.test',
];
foreach ($filenames as $name) {
$file->save($name);
}
foreach ($filenames as $name) {
$this->assertFileExists($name);
$this->assertEquals('foo', file_get_contents($name));
unlink($name);
}
}
public function testToString(): void
{
$file = new File('foo');
$string = $file->toString();
$this->assertEquals('foo', $string);
$this->assertEquals('foo', $string);
}
public function testToFilePointer(): void
{
$file = new File('foo');
$fp = $file->toFilePointer();
$this->assertIsResource($fp);
}
public function testSize(): void
{
$file = new File();
$this->assertEquals(0, $file->size());
$file = new File('foo');
$this->assertEquals(3, $file->size());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/MediaTypeTest.php | tests/Unit/MediaTypeTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use Generator;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\FileExtension;
use Intervention\Image\Format;
use Intervention\Image\MediaType;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
#[CoversClass(MediaType::class)]
final class MediaTypeTest extends BaseTestCase
{
public function testCreate(): void
{
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create(MediaType::IMAGE_JPEG));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create(Format::JPEG));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create(FileExtension::JPG));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create('jpg'));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create('jpeg'));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create('image/jpeg'));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create('JPG'));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create('JPEG'));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::create('IMAGE/JPEG'));
}
public function testCreateUnknown(): void
{
$this->expectException(NotSupportedException::class);
MediaType::create('foo');
}
public function testTryCreate(): void
{
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::tryCreate(MediaType::IMAGE_JPEG));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::tryCreate(Format::JPEG));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::tryCreate(FileExtension::JPG));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::tryCreate('jpg'));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::tryCreate('jpeg'));
$this->assertEquals(MediaType::IMAGE_JPEG, MediaType::tryCreate('image/jpeg'));
$this->assertNull(Format::tryCreate('no-format'));
}
public function testFormatJpeg(): void
{
$mime = MediaType::IMAGE_JPEG;
$this->assertEquals(Format::JPEG, $mime->format());
$mime = MediaType::IMAGE_PJPEG;
$this->assertEquals(Format::JPEG, $mime->format());
$mime = MediaType::IMAGE_JPG;
$this->assertEquals(Format::JPEG, $mime->format());
$mime = MediaType::IMAGE_X_JPEG;
$this->assertEquals(Format::JPEG, $mime->format());
}
public function testFormatWebp(): void
{
$mime = MediaType::IMAGE_WEBP;
$this->assertEquals(Format::WEBP, $mime->format());
$mime = MediaType::IMAGE_X_WEBP;
$this->assertEquals(Format::WEBP, $mime->format());
}
public function testFormatGif(): void
{
$mime = MediaType::IMAGE_GIF;
$this->assertEquals(Format::GIF, $mime->format());
}
public function testFormatPng(): void
{
$mime = MediaType::IMAGE_PNG;
$this->assertEquals(Format::PNG, $mime->format());
$mime = MediaType::IMAGE_X_PNG;
$this->assertEquals(Format::PNG, $mime->format());
}
public function testFormatAvif(): void
{
$mime = MediaType::IMAGE_AVIF;
$this->assertEquals(Format::AVIF, $mime->format());
$mime = MediaType::IMAGE_X_AVIF;
$this->assertEquals(Format::AVIF, $mime->format());
}
public function testFormatBmp(): void
{
$mime = MediaType::IMAGE_BMP;
$this->assertEquals(Format::BMP, $mime->format());
$mime = MediaType::IMAGE_X_BMP;
$this->assertEquals(Format::BMP, $mime->format());
$mime = MediaType::IMAGE_X_BITMAP;
$this->assertEquals(Format::BMP, $mime->format());
$mime = MediaType::IMAGE_X_WIN_BITMAP;
$this->assertEquals(Format::BMP, $mime->format());
$mime = MediaType::IMAGE_X_WINDOWS_BMP;
$this->assertEquals(Format::BMP, $mime->format());
$mime = MediaType::IMAGE_X_BMP3;
$this->assertEquals(Format::BMP, $mime->format());
}
public function testFormatTiff(): void
{
$mime = MediaType::IMAGE_TIFF;
$this->assertEquals(Format::TIFF, $mime->format());
}
public function testFormatJpeg2000(): void
{
$mime = MediaType::IMAGE_JPM;
$this->assertEquals(Format::JP2, $mime->format());
$mime = MediaType::IMAGE_JPX;
$this->assertEquals(Format::JP2, $mime->format());
$mime = MediaType::IMAGE_JP2;
$this->assertEquals(Format::JP2, $mime->format());
}
public function testFormatHeic(): void
{
$mime = MediaType::IMAGE_HEIC;
$this->assertEquals(Format::HEIC, $mime->format());
$mime = MediaType::IMAGE_X_HEIC;
$this->assertEquals(Format::HEIC, $mime->format());
$mime = MediaType::IMAGE_HEIF;
$this->assertEquals(Format::HEIC, $mime->format());
}
#[DataProvider('fileExtensionsDataProvider')]
public function testFileExtensions(
MediaType $mediaType,
int $fileExtensionCount,
FileExtension $fileExtension
): void {
$this->assertCount($fileExtensionCount, $mediaType->fileExtensions());
$this->assertEquals($fileExtension, $mediaType->fileExtension());
}
public static function fileExtensionsDataProvider(): Generator
{
yield [MediaType::IMAGE_JPEG, 2, FileExtension::JPG];
yield [MediaType::IMAGE_JPG, 2, FileExtension::JPG];
yield [MediaType::IMAGE_PJPEG, 2, FileExtension::JPG];
yield [MediaType::IMAGE_X_JPEG, 2, FileExtension::JPG];
yield [MediaType::IMAGE_WEBP, 1, FileExtension::WEBP];
yield [MediaType::IMAGE_X_WEBP, 1, FileExtension::WEBP];
yield [MediaType::IMAGE_GIF, 1, FileExtension::GIF];
yield [MediaType::IMAGE_PNG, 1, FileExtension::PNG];
yield [MediaType::IMAGE_X_PNG, 1, FileExtension::PNG];
yield [MediaType::IMAGE_AVIF, 1, FileExtension::AVIF];
yield [MediaType::IMAGE_X_AVIF, 1, FileExtension::AVIF];
yield [MediaType::IMAGE_BMP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_MS_BMP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_X_BITMAP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_X_BMP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_X_MS_BMP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_X_WINDOWS_BMP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_X_WIN_BITMAP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_X_XBITMAP, 1, FileExtension::BMP];
yield [MediaType::IMAGE_X_BMP3, 1, FileExtension::BMP];
yield [MediaType::IMAGE_TIFF, 2, FileExtension::TIF];
yield [MediaType::IMAGE_JP2, 9, FileExtension::JP2];
yield [MediaType::IMAGE_JPX, 9, FileExtension::JP2];
yield [MediaType::IMAGE_JPM, 9, FileExtension::JP2];
yield [MediaType::IMAGE_HEIC, 2, FileExtension::HEIC];
yield [MediaType::IMAGE_X_HEIC, 2, FileExtension::HEIC];
yield [MediaType::IMAGE_HEIF, 2, FileExtension::HEIC];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/ModifierStackTest.php | tests/Unit/ModifierStackTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use PHPUnit\Framework\Attributes\CoversClass;
use Intervention\Image\Modifiers\GreyscaleModifier;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\ModifierStack;
use Intervention\Image\Tests\BaseTestCase;
use Mockery;
#[CoversClass(ModifierStack::class)]
final class ModifierStackTest extends BaseTestCase
{
public function testConstructor(): void
{
$stack = new ModifierStack([]);
$this->assertInstanceOf(ModifierStack::class, $stack);
}
public function testPush(): void
{
$stack = new ModifierStack([]);
$result = $stack->push(new GreyscaleModifier());
$this->assertInstanceOf(ModifierStack::class, $result);
}
public function testApply(): void
{
$image = Mockery::mock(ImageInterface::class);
$modifier1 = Mockery::mock(ModifierInterface::class)->makePartial();
$modifier1->shouldReceive('apply')->once()->with($image);
$modifier2 = Mockery::mock(ModifierInterface::class)->makePartial();
$modifier2->shouldReceive('apply')->once()->with($image);
$stack = new ModifierStack([$modifier1, $modifier2]);
$result = $stack->apply($image);
$this->assertInstanceOf(ImageInterface::class, $result);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/FileExtensionTest.php | tests/Unit/FileExtensionTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use Generator;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\FileExtension;
use Intervention\Image\Format;
use Intervention\Image\MediaType;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
#[CoversClass(FileExtension::class)]
final class FileExtensionTest extends BaseTestCase
{
public function testCreate(): void
{
$this->assertEquals(FileExtension::JPG, FileExtension::create(MediaType::IMAGE_JPEG));
$this->assertEquals(FileExtension::JPG, FileExtension::create(Format::JPEG));
$this->assertEquals(FileExtension::JPG, FileExtension::create(FileExtension::JPG));
$this->assertEquals(FileExtension::JPG, FileExtension::create('jpg'));
$this->assertEquals(FileExtension::JPEG, FileExtension::create('jpeg'));
$this->assertEquals(FileExtension::JPG, FileExtension::create('image/jpeg'));
$this->assertEquals(FileExtension::JPG, FileExtension::create('JPG'));
$this->assertEquals(FileExtension::JPEG, FileExtension::create('JPEG'));
$this->assertEquals(FileExtension::JPG, FileExtension::create('IMAGE/JPEG'));
}
public function testCreateUnknown(): void
{
$this->expectException(NotSupportedException::class);
FileExtension::create('foo');
}
public function testTryCreate(): void
{
$this->assertEquals(FileExtension::JPG, FileExtension::tryCreate(MediaType::IMAGE_JPEG));
$this->assertEquals(FileExtension::JPG, FileExtension::tryCreate(Format::JPEG));
$this->assertEquals(FileExtension::JPG, FileExtension::tryCreate(FileExtension::JPG));
$this->assertEquals(FileExtension::JPG, FileExtension::tryCreate('jpg'));
$this->assertEquals(FileExtension::JPEG, FileExtension::tryCreate('jpeg'));
$this->assertEquals(FileExtension::JPG, FileExtension::tryCreate('image/jpeg'));
$this->assertNull(FileExtension::tryCreate('no-format'));
}
public function testFormatJpeg(): void
{
$ext = FileExtension::JPEG;
$this->assertEquals(Format::JPEG, $ext->format());
$ext = FileExtension::JPG;
$this->assertEquals(Format::JPEG, $ext->format());
}
public function testFormatWebp(): void
{
$ext = FileExtension::WEBP;
$this->assertEquals(Format::WEBP, $ext->format());
}
public function testFormatGif(): void
{
$ext = FileExtension::GIF;
$this->assertEquals(Format::GIF, $ext->format());
}
public function testFormatPng(): void
{
$ext = FileExtension::PNG;
$this->assertEquals(Format::PNG, $ext->format());
}
public function testFormatAvif(): void
{
$ext = FileExtension::AVIF;
$this->assertEquals(Format::AVIF, $ext->format());
}
public function testFormatBmp(): void
{
$ext = FileExtension::BMP;
$this->assertEquals(Format::BMP, $ext->format());
}
public function testFormatTiff(): void
{
$ext = FileExtension::TIFF;
$this->assertEquals(Format::TIFF, $ext->format());
$ext = FileExtension::TIF;
$this->assertEquals(Format::TIFF, $ext->format());
}
public function testFormatJpeg2000(): void
{
$ext = FileExtension::JP2;
$this->assertEquals(Format::JP2, $ext->format());
$ext = FileExtension::J2K;
$this->assertEquals(Format::JP2, $ext->format());
$ext = FileExtension::J2C;
$this->assertEquals(Format::JP2, $ext->format());
$ext = FileExtension::JPG2;
$this->assertEquals(Format::JP2, $ext->format());
$ext = FileExtension::JP2K;
$this->assertEquals(Format::JP2, $ext->format());
}
public function testFormatHeic(): void
{
$ext = FileExtension::HEIC;
$this->assertEquals(Format::HEIC, $ext->format());
$ext = FileExtension::HEIF;
$this->assertEquals(Format::HEIC, $ext->format());
}
#[DataProvider('mediaTypesDataProvider')]
public function testMediatypes(FileExtension $extension, int $mediaTypeCount, MediaType $mediaType): void
{
$this->assertCount($mediaTypeCount, $extension->mediaTypes());
$this->assertEquals($mediaType, $extension->mediaType());
}
public static function mediaTypesDataProvider(): Generator
{
yield [FileExtension::JPEG, 4, MediaType::IMAGE_JPEG];
yield [FileExtension::WEBP, 2, MediaType::IMAGE_WEBP];
yield [FileExtension::GIF, 1, MediaType::IMAGE_GIF];
yield [FileExtension::PNG, 2, MediaType::IMAGE_PNG];
yield [FileExtension::AVIF, 2, MediaType::IMAGE_AVIF];
yield [FileExtension::BMP, 9, MediaType::IMAGE_BMP];
yield [FileExtension::TIFF, 1, MediaType::IMAGE_TIFF];
yield [FileExtension::TIF, 1, MediaType::IMAGE_TIFF];
yield [FileExtension::JP2, 4, MediaType::IMAGE_JP2];
yield [FileExtension::HEIC, 3, MediaType::IMAGE_HEIC];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/ImageManagerTestImagick.php | tests/Unit/ImageManagerTestImagick.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Decoders\BinaryImageDecoder;
use Intervention\Image\Decoders\FilePathImageDecoder;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Tests\BaseTestCase;
#[CoversClass(ImageManager::class)]
#[RequiresPhpExtension('imagick')]
final class ImageManagerTestImagick extends BaseTestCase
{
public function testConstructor(): void
{
$manager = new ImageManager(new Driver());
$this->assertInstanceOf(ImageManager::class, $manager);
$manager = new ImageManager(Driver::class);
$this->assertInstanceOf(ImageManager::class, $manager);
}
public function testWithDriver(): void
{
$manager = ImageManager::withDriver(new Driver());
$this->assertInstanceOf(ImageManager::class, $manager);
$manager = ImageManager::withDriver(Driver::class);
$this->assertInstanceOf(ImageManager::class, $manager);
}
public function testDriver(): void
{
$driver = new Driver();
$manager = ImageManager::withDriver($driver);
$this->assertEquals($driver, $manager->driver());
}
public function testDriverStatic(): void
{
$manager = ImageManager::imagick();
$this->assertInstanceOf(ImageManager::class, $manager);
}
public function testCreate(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->create(5, 4);
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testAnimate(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->animate(function ($animation): void {
$animation->add($this->getTestResourcePath('red.gif'), .25);
});
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testRead(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('red.gif'));
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testReadWithDecoderClassname(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('red.gif'), FilePathImageDecoder::class);
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testReadWithDecoderInstance(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('red.gif'), new FilePathImageDecoder());
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testReadWithDecoderClassnameArray(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('red.gif'), [FilePathImageDecoder::class]);
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testReadWithDecoderInstanceArray(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('red.gif'), [new FilePathImageDecoder()]);
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testReadWithDecoderInstanceArrayMultiple(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('red.gif'), [
new BinaryImageDecoder(),
new FilePathImageDecoder(),
]);
$this->assertInstanceOf(ImageInterface::class, $image);
}
public function testReadWithRotationAdjustment(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('orientation.jpg'));
$this->assertColor(1, 0, 254, 255, $image->pickColor(3, 3));
}
public function testReadWithoutRotationAdjustment(): void
{
$manager = new ImageManager(Driver::class, autoOrientation: false);
$image = $manager->read($this->getTestResourcePath('orientation.jpg'));
$this->assertColor(250, 2, 3, 255, $image->pickColor(3, 3));
}
public function testReadAnimation(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('animation.gif'));
$this->assertTrue($image->isAnimated());
}
public function testReadAnimationDiscarded(): void
{
$manager = new ImageManager(Driver::class, decodeAnimation: false);
$image = $manager->read($this->getTestResourcePath('animation.gif'));
$this->assertFalse($image->isAnimated());
}
public function testApplyBlendingColor(): void
{
$manager = new ImageManager(Driver::class);
$image = $manager->read($this->getTestResourcePath('blocks.png'));
$result = $image->blendTransparency();
$this->assertColor(255, 255, 255, 255, $image->pickColor(530, 0));
$this->assertColor(255, 255, 255, 255, $result->pickColor(530, 0));
}
public function testApplyBlendingColorConfigured(): void
{
$manager = new ImageManager(Driver::class, blendingColor: 'ff5500');
$image = $manager->read($this->getTestResourcePath('blocks.png'));
$result = $image->blendTransparency();
$this->assertColor(255, 85, 0, 255, $image->pickColor(530, 0));
$this->assertColor(255, 85, 0, 255, $result->pickColor(530, 0));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/OriginTest.php | tests/Unit/OriginTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use Intervention\Image\Origin;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(Origin::class)]
final class OriginTest extends BaseTestCase
{
public function testFilePath(): void
{
$origin = new Origin('image/jpeg', $this->getTestResourcePath('example.jpg'));
$this->assertEquals($this->getTestResourcePath('example.jpg'), $origin->filePath());
}
public function testFileExtension(): void
{
$origin = new Origin('image/jpeg', $this->getTestResourcePath('example.jpg'));
$this->assertEquals('jpg', $origin->fileExtension());
$origin = new Origin('image/jpeg');
$this->assertEquals('', $origin->fileExtension());
}
public function testSetGetMediaType(): void
{
$origin = new Origin();
$this->assertEquals('application/octet-stream', $origin->mediaType());
$origin = new Origin('image/gif');
$this->assertEquals('image/gif', $origin->mediaType());
$this->assertEquals('image/gif', $origin->mimetype());
$result = $origin->setMediaType('image/jpeg');
$this->assertEquals('image/jpeg', $origin->mediaType());
$this->assertEquals('image/jpeg', $result->mediaType());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/tests/Unit/InputHandlerTest.php | tests/Unit/InputHandlerTest.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use Generator;
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
#[RequiresPhpExtension('gd')]
#[RequiresPhpExtension('imagick')]
#[CoversClass(InputHandler::class)]
class InputHandlerTest extends BaseTestCase
{
#[DataProvider('inputProvider')]
public function testHandleDefaultDecoders(string $driver, mixed $input, string $outputClassname): void
{
$handler = new InputHandler(driver: new $driver());
if ($outputClassname === ImageInterface::class || $outputClassname === ColorInterface::class) {
$this->assertInstanceOf($outputClassname, $handler->handle($input));
} else {
$this->expectException($outputClassname);
$handler->handle($input);
}
}
public static function inputProvider(): Generator
{
$base = [
[null, DecoderException::class],
['', DecoderException::class],
['fff', ColorInterface::class],
['rgba(0, 0, 0, 0)', ColorInterface::class],
['cmyk(0, 0, 0, 0)', ColorInterface::class],
['hsv(0, 0, 0)', ColorInterface::class],
['hsl(0, 0, 0)', ColorInterface::class],
['transparent', ColorInterface::class],
['steelblue', ColorInterface::class],
[self::getTestResourcePath(), ImageInterface::class],
[file_get_contents(self::getTestResourcePath()), ImageInterface::class],
];
$drivers = [GdDriver::class, ImagickDriver::class];
foreach ($drivers as $driver) {
foreach ($base as $line) {
array_unshift($line, $driver); // prepend driver
yield $line;
}
}
}
public function testResolveWithoutDriver(): void
{
$handler = new InputHandler([new HexColorDecoder()]);
$result = $handler->handle('fff');
$this->assertInstanceOf(ColorInterface::class, $result);
$handler = new InputHandler([HexColorDecoder::class]);
$result = $handler->handle('fff');
$this->assertInstanceOf(ColorInterface::class, $result);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.