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/Colors/Hsl/Color.php | src/Colors/Hsl/Color.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Hsl;
use Intervention\Image\Colors\AbstractColor;
use Intervention\Image\Colors\Hsl\Channels\Hue;
use Intervention\Image\Colors\Hsl\Channels\Luminance;
use Intervention\Image\Colors\Hsl\Channels\Saturation;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\ColorChannelInterface;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
class Color extends AbstractColor
{
/**
* Create new color object
*
* @return void
*/
public function __construct(int $h, int $s, int $l)
{
/** @throws void */
$this->channels = [
new Hue($h),
new Saturation($s),
new Luminance($l),
];
}
/**
* {@inheritdoc}
*
* @see ColorInterface::colorspace()
*/
public function colorspace(): ColorspaceInterface
{
return new Colorspace();
}
/**
* {@inheritdoc}
*
* @see ColorInterface::create()
*/
public static function create(mixed $input): ColorInterface
{
return InputHandler::withDecoders([
Decoders\StringColorDecoder::class,
])->handle($input);
}
/**
* Return the Hue channel
*/
public function hue(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Hue::class);
}
/**
* Return the Saturation channel
*/
public function saturation(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Saturation::class);
}
/**
* Return the Luminance channel
*/
public function luminance(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Luminance::class);
}
public function toHex(string $prefix = ''): string
{
return $this->convertTo(RgbColorspace::class)->toHex($prefix);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::toString()
*/
public function toString(): string
{
return sprintf(
'hsl(%d, %d%%, %d%%)',
$this->hue()->value(),
$this->saturation()->value(),
$this->luminance()->value()
);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isGreyscale()
*/
public function isGreyscale(): bool
{
return $this->saturation()->value() == 0;
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isTransparent()
*/
public function isTransparent(): bool
{
return false;
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsl/Channels/Saturation.php | src/Colors/Hsl/Channels/Saturation.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Hsl\Channels;
use Intervention\Image\Colors\AbstractColorChannel;
class Saturation extends AbstractColorChannel
{
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::min()
*/
public function min(): int
{
return 0;
}
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::max()
*/
public function max(): int
{
return 100;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsl/Channels/Luminance.php | src/Colors/Hsl/Channels/Luminance.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Hsl\Channels;
use Intervention\Image\Colors\AbstractColorChannel;
class Luminance extends AbstractColorChannel
{
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::min()
*/
public function min(): int
{
return 0;
}
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::max()
*/
public function max(): int
{
return 100;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsl/Channels/Hue.php | src/Colors/Hsl/Channels/Hue.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Hsl\Channels;
use Intervention\Image\Colors\AbstractColorChannel;
class Hue extends AbstractColorChannel
{
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::min()
*/
public function min(): int
{
return 0;
}
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::max()
*/
public function max(): int
{
return 360;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Hsl/Decoders/StringColorDecoder.php | src/Colors/Hsl/Decoders/StringColorDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Hsl\Decoders;
use Intervention\Image\Colors\Hsl\Color;
use Intervention\Image\Drivers\AbstractDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class StringColorDecoder extends AbstractDecoder implements DecoderInterface
{
/**
* Decode hsl color strings
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
$pattern = '/^hsl\((?P<h>[0-9\.]+), ?(?P<s>[0-9\.]+%?), ?(?P<l>[0-9\.]+%?)\)$/i';
if (preg_match($pattern, $input, $matches) != 1) {
throw new DecoderException('Unable to decode input');
}
$values = array_map(function (string $value): int {
return match (strpos($value, '%')) {
false => intval(trim($value)),
default => intval(trim(str_replace('%', '', $value))),
};
}, [$matches['h'], $matches['s'], $matches['l']]);
return new Color(...$values);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Colorspace.php | src/Colors/Rgb/Colorspace.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb;
use Intervention\Image\Colors\Hsv\Color as HsvColor;
use Intervention\Image\Colors\Hsl\Color as HslColor;
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ColorChannelInterface;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
class Colorspace implements ColorspaceInterface
{
/**
* Channel class names of colorspace
*
* @var array<string>
*/
public static array $channels = [
Channels\Red::class,
Channels\Green::class,
Channels\Blue::class,
Channels\Alpha::class
];
/**
* {@inheritdoc}
*
* @see ColorspaceInterface::colorFromNormalized()
*/
public function colorFromNormalized(array $normalized): ColorInterface
{
return new Color(...array_map(
fn($classname, float $value_normalized) => (new $classname(normalized: $value_normalized))->value(),
self::$channels,
$normalized,
));
}
/**
* @throws ColorException
*/
public function importColor(ColorInterface $color): ColorInterface
{
return match ($color::class) {
CmykColor::class => $this->importCmykColor($color),
HsvColor::class => $this->importHsvColor($color),
HslColor::class => $this->importHslColor($color),
default => $color,
};
}
/**
* @throws ColorException
*/
protected function importCmykColor(ColorInterface $color): ColorInterface
{
if (!($color instanceof CmykColor)) {
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
}
return new Color(
(int) (255 * (1 - $color->cyan()->normalize()) * (1 - $color->key()->normalize())),
(int) (255 * (1 - $color->magenta()->normalize()) * (1 - $color->key()->normalize())),
(int) (255 * (1 - $color->yellow()->normalize()) * (1 - $color->key()->normalize())),
);
}
/**
* @throws ColorException
*/
protected function importHsvColor(ColorInterface $color): ColorInterface
{
if (!($color instanceof HsvColor)) {
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
}
$chroma = $color->value()->normalize() * $color->saturation()->normalize();
$hue = $color->hue()->normalize() * 6;
$x = $chroma * (1 - abs(fmod($hue, 2) - 1));
// connect channel values
$values = match (true) {
$hue < 1 => [$chroma, $x, 0],
$hue < 2 => [$x, $chroma, 0],
$hue < 3 => [0, $chroma, $x],
$hue < 4 => [0, $x, $chroma],
$hue < 5 => [$x, 0, $chroma],
default => [$chroma, 0, $x],
};
// add to each value
$values = array_map(fn(float|int $value): float => $value + $color->value()->normalize() - $chroma, $values);
$values[] = 1; // append alpha channel value
return $this->colorFromNormalized($values);
}
/**
* @throws ColorException
*/
protected function importHslColor(ColorInterface $color): ColorInterface
{
if (!($color instanceof HslColor)) {
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
}
// normalized values of hsl channels
[$h, $s, $l] = array_map(
fn(ColorChannelInterface $channel): float => $channel->normalize(),
$color->channels()
);
$c = (1 - abs(2 * $l - 1)) * $s;
$x = $c * (1 - abs(fmod($h * 6, 2) - 1));
$m = $l - $c / 2;
$values = match (true) {
$h < 1 / 6 => [$c, $x, 0],
$h < 2 / 6 => [$x, $c, 0],
$h < 3 / 6 => [0, $c, $x],
$h < 4 / 6 => [0, $x, $c],
$h < 5 / 6 => [$x, 0, $c],
default => [$c, 0, $x],
};
$values = array_map(fn(float|int $value): float => $value + $m, $values);
$values[] = 1; // append alpha channel value
return $this->colorFromNormalized($values);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Color.php | src/Colors/Rgb/Color.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb;
use Intervention\Image\Colors\AbstractColor;
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\Channels\Alpha;
use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\ColorChannelInterface;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
class Color extends AbstractColor
{
/**
* Create new instance
*
* @return ColorInterface
*/
public function __construct(int $r, int $g, int $b, int $a = 255)
{
/** @throws void */
$this->channels = [
new Red($r),
new Green($g),
new Blue($b),
new Alpha($a),
];
}
/**
* {@inheritdoc}
*
* @see ColorInterface::colorspace()
*/
public function colorspace(): ColorspaceInterface
{
return new Colorspace();
}
/**
* {@inheritdoc}
*
* @see ColorInterface::create()
*/
public static function create(mixed $input): ColorInterface
{
return InputHandler::withDecoders([
Decoders\HexColorDecoder::class,
Decoders\StringColorDecoder::class,
Decoders\TransparentColorDecoder::class,
Decoders\HtmlColornameDecoder::class,
])->handle($input);
}
/**
* Return the RGB red color channel
*/
public function red(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Red::class);
}
/**
* Return the RGB green color channel
*/
public function green(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Green::class);
}
/**
* Return the RGB blue color channel
*/
public function blue(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Blue::class);
}
/**
* Return the colors alpha channel
*/
public function alpha(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Alpha::class);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::toHex()
*/
public function toHex(string $prefix = ''): string
{
if ($this->isTransparent()) {
return sprintf(
'%s%02x%02x%02x%02x',
$prefix,
$this->red()->value(),
$this->green()->value(),
$this->blue()->value(),
$this->alpha()->value()
);
}
return sprintf(
'%s%02x%02x%02x',
$prefix,
$this->red()->value(),
$this->green()->value(),
$this->blue()->value()
);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::toString()
*/
public function toString(): string
{
if ($this->isTransparent()) {
return sprintf(
'rgba(%d, %d, %d, %.1F)',
$this->red()->value(),
$this->green()->value(),
$this->blue()->value(),
$this->alpha()->normalize(),
);
}
return sprintf(
'rgb(%d, %d, %d)',
$this->red()->value(),
$this->green()->value(),
$this->blue()->value()
);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isGreyscale()
*/
public function isGreyscale(): bool
{
$values = [$this->red()->value(), $this->green()->value(), $this->blue()->value()];
return count(array_unique($values, SORT_REGULAR)) === 1;
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isTransparent()
*/
public function isTransparent(): bool
{
return $this->alpha()->value() < $this->alpha()->max();
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return $this->alpha()->value() == 0;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Channels/Blue.php | src/Colors/Rgb/Channels/Blue.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Channels;
class Blue extends Red
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Channels/Green.php | src/Colors/Rgb/Channels/Green.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Channels;
class Green extends Red
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Channels/Alpha.php | src/Colors/Rgb/Channels/Alpha.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Channels;
class Alpha extends Red
{
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::toString()
*/
public function toString(): string
{
return strval(round($this->normalize(), 6));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Channels/Red.php | src/Colors/Rgb/Channels/Red.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Channels;
use Intervention\Image\Colors\AbstractColorChannel;
class Red extends AbstractColorChannel
{
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::min()
*/
public function min(): int
{
return 0;
}
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::max()
*/
public function max(): int
{
return 255;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Decoders/StringColorDecoder.php | src/Colors/Rgb/Decoders/StringColorDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Decoders;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Drivers\AbstractDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class StringColorDecoder extends AbstractDecoder implements DecoderInterface
{
/**
* Decode rgb color strings
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
$pattern = '/^s?rgba?\((?P<r>[0-9\.]+%?), ?(?P<g>[0-9\.]+%?), ?(?P<b>[0-9\.]+%?)' .
'(?:, ?(?P<a>(?:1)|(?:1\.0*)|(?:0)|(?:0?\.\d+%?)|(?:\d{1,3}%)))?\)$/i';
if (preg_match($pattern, $input, $matches) != 1) {
throw new DecoderException('Unable to decode input');
}
// rgb values
$values = array_map(function (string $value): int {
return match (strpos($value, '%')) {
false => intval(trim($value)),
default => intval(round(floatval(trim(str_replace('%', '', $value))) / 100 * 255)),
};
}, [$matches['r'], $matches['g'], $matches['b']]);
// alpha value
if (array_key_exists('a', $matches)) {
$values[] = match (true) {
strpos($matches['a'], '%') => round(intval(trim(str_replace('%', '', $matches['a']))) / 2.55),
default => intval(round(floatval(trim($matches['a'])) * 255)),
};
}
return new Color(...$values);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Decoders/TransparentColorDecoder.php | src/Colors/Rgb/Decoders/TransparentColorDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ColorInterface;
class TransparentColorDecoder extends HexColorDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
if (strtolower($input) !== 'transparent') {
throw new DecoderException('Unable to decode input');
}
return parent::decode('#ffffff00');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Decoders/HexColorDecoder.php | src/Colors/Rgb/Decoders/HexColorDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Decoders;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Drivers\AbstractDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class HexColorDecoder extends AbstractDecoder implements DecoderInterface
{
/**
* Decode hexadecimal rgb colors with and without transparency
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
$pattern = '/^#?(?P<hex>[a-f\d]{3}(?:[a-f\d]?|(?:[a-f\d]{3}(?:[a-f\d]{2})?)?)\b)$/i';
if (preg_match($pattern, $input, $matches) != 1) {
throw new DecoderException('Unable to decode input');
}
$values = match (strlen($matches['hex'])) {
3, 4 => str_split($matches['hex']),
6, 8 => str_split($matches['hex'], 2),
default => throw new DecoderException('Unable to decode input'),
};
$values = array_map(function (string $value): float|int {
return match (strlen($value)) {
1 => hexdec($value . $value),
2 => hexdec($value),
default => throw new DecoderException('Unable to decode input'),
};
}, $values);
return new Color(...$values);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Rgb/Decoders/HtmlColornameDecoder.php | src/Colors/Rgb/Decoders/HtmlColornameDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Rgb\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class HtmlColornameDecoder extends HexColorDecoder implements DecoderInterface
{
/**
* Available color names and their corresponding hex codes
*
* @var array<string, string>
*/
protected static array $names = [
'lightsalmon' => '#ffa07a',
'salmon' => '#fa8072',
'darksalmon' => '#e9967a',
'lightcoral' => '#f08080',
'indianred' => '#cd5c5c',
'crimson' => '#dc143c',
'firebrick' => '#b22222',
'red' => '#ff0000',
'darkred' => '#8b0000',
'coral' => '#ff7f50',
'tomato' => '#ff6347',
'orangered' => '#ff4500',
'gold' => '#ffd700',
'orange' => '#ffa500',
'darkorange' => '#ff8c00',
'lightyellow' => '#ffffe0',
'lemonchiffon' => '#fffacd',
'lightgoldenrodyellow' => '#fafad2',
'papayawhip' => '#ffefd5',
'moccasin' => '#ffe4b5',
'peachpuff' => '#ffdab9',
'palegoldenrod' => '#eee8aa',
'khaki' => '#f0e68c',
'darkkhaki' => '#bdb76b',
'yellow' => '#ffff00',
'lawngreen' => '#7cfc00',
'chartreuse' => '#7fff00',
'limegreen' => '#32cd32',
'lime' => '#00ff00',
'forestgreen' => '#228b22',
'green' => '#008000',
'darkgreen' => '#006400',
'greenyellow' => '#adff2f',
'yellowgreen' => '#9acd32',
'springgreen' => '#00ff7f',
'mediumspringgreen' => '#00fa9a',
'lightgreen' => '#90ee90',
'palegreen' => '#98fb98',
'darkseagreen' => '#8fbc8f',
'mediumseagre' => 'en #3cb371',
'seagreen' => '#2e8b57',
'olive' => '#808000',
'darkolivegreen' => '#556b2f',
'olivedrab' => '#6b8e23',
'lightcyan' => '#e0ffff',
'cyan' => '#00ffff',
'aqua' => '#00ffff',
'aquamarine' => '#7fffd4',
'mediumaquamarine' => '#66cdaa',
'paleturquoise' => '#afeeee',
'turquoise' => '#40e0d0',
'mediumturquoise' => '#48d1cc',
'darkturquoise' => '#00ced1',
'lightseagreen' => '#20b2aa',
'cadetblue' => '#5f9ea0',
'darkcyan' => '#008b8b',
'teal' => '#008080',
'powderblue' => '#b0e0e6',
'lightblue' => '#add8e6',
'lightskyblue' => '#87cefa',
'skyblue' => '#87ceeb',
'deepskyblue' => '#00bfff',
'lightsteelblue' => '#b0c4de',
'dodgerblue' => '#1e90ff',
'cornflowerblue' => '#6495ed',
'steelblue' => '#4682b4',
'royalblue' => '#4169e1',
'blue' => '#0000ff',
'mediumblue' => '#0000cd',
'darkblue' => '#00008b',
'navy' => '#000080',
'midnightblue' => '#191970',
'mediumslateblue' => '#7b68ee',
'slateblue' => '#6a5acd',
'darkslateblue' => '#483d8b',
'lavender' => '#e6e6fa',
'thistle' => '#d8bfd8',
'plum' => '#dda0dd',
'violet' => '#ee82ee',
'orchid' => '#da70d6',
'fuchsia' => '#ff00ff',
'magenta' => '#ff00ff',
'mediumorchid' => '#ba55d3',
'mediumpurple' => '#9370db',
'blueviolet' => '#8a2be2',
'darkviolet' => '#9400d3',
'darkorchid' => '#9932cc',
'darkmagenta' => '#8b008b',
'purple' => '#800080',
'indigo' => '#4b0082',
'pink' => '#ffc0cb',
'lightpink' => '#ffb6c1',
'hotpink' => '#ff69b4',
'deeppink' => '#ff1493',
'palevioletred' => '#db7093',
'mediumvioletred' => '#c71585',
'white' => '#ffffff',
'snow' => '#fffafa',
'honeydew' => '#f0fff0',
'mintcream' => '#f5fffa',
'azure' => '#f0ffff',
'aliceblue' => '#f0f8ff',
'ghostwhite' => '#f8f8ff',
'whitesmoke' => '#f5f5f5',
'seashell' => '#fff5ee',
'beige' => '#f5f5dc',
'oldlace' => '#fdf5e6',
'floralwhite' => '#fffaf0',
'ivory' => '#fffff0',
'antiquewhite' => '#faebd7',
'linen' => '#faf0e6',
'lavenderblush' => '#fff0f5',
'mistyrose' => '#ffe4e1',
'gainsboro' => '#dcdcdc',
'lightgray' => '#d3d3d3',
'silver' => '#c0c0c0',
'darkgray' => '#a9a9a9',
'gray' => '#808080',
'dimgray' => '#696969',
'lightslategray' => '#778899',
'slategray' => '#708090',
'darkslategray' => '#2f4f4f',
'black' => '#000000',
'cornsilk' => '#fff8dc',
'blanchedalmond' => '#ffebcd',
'bisque' => '#ffe4c4',
'navajowhite' => '#ffdead',
'wheat' => '#f5deb3',
'burlywood' => '#deb887',
'tan' => '#d2b48c',
'rosybrown' => '#bc8f8f',
'sandybrown' => '#f4a460',
'goldenrod' => '#daa520',
'peru' => '#cd853f',
'chocolate' => '#d2691e',
'saddlebrown' => '#8b4513',
'sienna' => '#a0522d',
'brown' => '#a52a2a',
'maroon' => '#800000',
];
/**
* Decode html color names
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
if (!array_key_exists(strtolower($input), static::$names)) {
throw new DecoderException('Unable to decode input');
}
return parent::decode(static::$names[strtolower($input)]);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Cmyk/Colorspace.php | src/Colors/Cmyk/Colorspace.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Cmyk;
use Intervention\Image\Colors\Rgb\Color as RgbColor;
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
use Intervention\Image\Colors\Hsv\Color as HsvColor;
use Intervention\Image\Colors\Hsl\Color as HslColor;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
class Colorspace implements ColorspaceInterface
{
/**
* Channel class names of colorspace
*
* @var array<string>
*/
public static array $channels = [
Channels\Cyan::class,
Channels\Magenta::class,
Channels\Yellow::class,
Channels\Key::class
];
/**
* {@inheritdoc}
*
* @see ColorspaceInterface::createColor()
*/
public function colorFromNormalized(array $normalized): ColorInterface
{
return new Color(...array_map(
fn(string $classname, float $value_normalized) => (new $classname(normalized: $value_normalized))->value(),
self::$channels,
$normalized,
));
}
/**
* @throws ColorException
*/
public function importColor(ColorInterface $color): ColorInterface
{
return match ($color::class) {
RgbColor::class => $this->importRgbColor($color),
HsvColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
HslColor::class => $this->importRgbColor($color->convertTo(RgbColorspace::class)),
default => $color,
};
}
/**
* @throws ColorException
*/
protected function importRgbColor(ColorInterface $color): CmykColor
{
if (!($color instanceof RgbColor)) {
throw new ColorException('Unabled to import color of type ' . $color::class . '.');
}
$c = (255 - $color->red()->value()) / 255.0 * 100;
$m = (255 - $color->green()->value()) / 255.0 * 100;
$y = (255 - $color->blue()->value()) / 255.0 * 100;
$k = intval(round(min([$c, $m, $y])));
$c = intval(round($c - $k));
$m = intval(round($m - $k));
$y = intval(round($y - $k));
return new CmykColor($c, $m, $y, $k);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Cmyk/Color.php | src/Colors/Cmyk/Color.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Cmyk;
use Intervention\Image\Colors\AbstractColor;
use Intervention\Image\Colors\Cmyk\Channels\Cyan;
use Intervention\Image\Colors\Cmyk\Channels\Magenta;
use Intervention\Image\Colors\Cmyk\Channels\Yellow;
use Intervention\Image\Colors\Cmyk\Channels\Key;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\ColorChannelInterface;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
class Color extends AbstractColor
{
/**
* Create new instance
*
* @return void
*/
public function __construct(int $c, int $m, int $y, int $k)
{
/** @throws void */
$this->channels = [
new Cyan($c),
new Magenta($m),
new Yellow($y),
new Key($k),
];
}
/**
* {@inheritdoc}
*
* @see ColorInterface::create()
*/
public static function create(mixed $input): ColorInterface
{
return InputHandler::withDecoders([
Decoders\StringColorDecoder::class,
])->handle($input);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::colorspace()
*/
public function colorspace(): ColorspaceInterface
{
return new Colorspace();
}
/**
* {@inheritdoc}
*
* @see ColorInterface::toHex()
*/
public function toHex(string $prefix = ''): string
{
return $this->convertTo(RgbColorspace::class)->toHex($prefix);
}
/**
* Return the CMYK cyan channel
*/
public function cyan(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Cyan::class);
}
/**
* Return the CMYK magenta channel
*/
public function magenta(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Magenta::class);
}
/**
* Return the CMYK yellow channel
*/
public function yellow(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Yellow::class);
}
/**
* Return the CMYK key channel
*/
public function key(): ColorChannelInterface
{
/** @throws void */
return $this->channel(Key::class);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::toString()
*/
public function toString(): string
{
return sprintf(
'cmyk(%d%%, %d%%, %d%%, %d%%)',
$this->cyan()->value(),
$this->magenta()->value(),
$this->yellow()->value(),
$this->key()->value()
);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isGreyscale()
*/
public function isGreyscale(): bool
{
return 0 === array_sum([
$this->cyan()->value(),
$this->magenta()->value(),
$this->yellow()->value(),
]);
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isTransparent()
*/
public function isTransparent(): bool
{
return false;
}
/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Cmyk/Channels/Magenta.php | src/Colors/Cmyk/Channels/Magenta.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Cmyk\Channels;
class Magenta extends Cyan
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Cmyk/Channels/Yellow.php | src/Colors/Cmyk/Channels/Yellow.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Cmyk\Channels;
class Yellow extends Cyan
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Cmyk/Channels/Cyan.php | src/Colors/Cmyk/Channels/Cyan.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Cmyk\Channels;
use Intervention\Image\Colors\AbstractColorChannel;
class Cyan extends AbstractColorChannel
{
public function min(): int
{
return 0;
}
public function max(): int
{
return 100;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Cmyk/Channels/Key.php | src/Colors/Cmyk/Channels/Key.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Cmyk\Channels;
class Key extends Cyan
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Colors/Cmyk/Decoders/StringColorDecoder.php | src/Colors/Cmyk/Decoders/StringColorDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Colors\Cmyk\Decoders;
use Intervention\Image\Colors\Cmyk\Color;
use Intervention\Image\Drivers\AbstractDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class StringColorDecoder extends AbstractDecoder implements DecoderInterface
{
/**
* Decode CMYK color strings
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
$pattern = '/^cmyk\((?P<c>[0-9\.]+%?), ?(?P<m>[0-9\.]+%?), ?(?P<y>[0-9\.]+%?), ?(?P<k>[0-9\.]+%?)\)$/i';
if (preg_match($pattern, $input, $matches) != 1) {
throw new DecoderException('Unable to decode input');
}
$values = array_map(function (string $value): int {
return intval(round(floatval(trim(str_replace('%', '', $value)))));
}, [$matches['c'], $matches['m'], $matches['y'], $matches['k']]);
return new Color(...$values);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/EncodedImageInterface.php | src/Interfaces/EncodedImageInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface EncodedImageInterface extends FileInterface
{
/**
* Return Media (MIME) Type of encoded image
*/
public function mediaType(): string;
/**
* Alias of self::mediaType()
*/
public function mimetype(): string;
/**
* Transform encoded image data into an data uri string
*/
public function toDataUri(): string;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/DrawableFactoryInterface.php | src/Interfaces/DrawableFactoryInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Closure;
interface DrawableFactoryInterface
{
/**
* Create a new factory instance statically
*/
public static function init(null|Closure|DrawableInterface $init = null): self;
/**
* Create the end product of the factory
*/
public function create(): DrawableInterface;
/**
* Define the background color of the drawable object
*/
public function background(mixed $color): self;
/**
* Set the border size & color of the drawable object to be produced
*/
public function border(mixed $color, int $size = 1): self;
/**
* Create the end product by invoking the factory
*/
public function __invoke(): DrawableInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/SizeInterface.php | src/Interfaces/SizeInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\GeometryException;
interface SizeInterface
{
/**
* Get width
*/
public function width(): int;
/**
* Get height
*/
public function height(): int;
/**
* Get pivot point
*/
public function pivot(): PointInterface;
/**
* Set width
*/
public function setWidth(int $width): self;
/**
* Set height
*/
public function setHeight(int $height): self;
/**
* Set pivot point
*/
public function setPivot(PointInterface $pivot): self;
/**
* Calculate aspect ratio of the current size
*/
public function aspectRatio(): float;
/**
* Determine if current size fits into given size
*/
public function fitsInto(self $size): bool;
/**
* Determine if size is in landscape format
*/
public function isLandscape(): bool;
/**
* Determine if size is in portrait format
*/
public function isPortrait(): bool;
/**
* Move pivot to given position in size
*/
public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0): self;
/**
* Align pivot of current object to given position
*/
public function alignPivotTo(self $size, string $position): self;
/**
* Calculate the relative position to another Size
* based on the pivot point settings of both sizes.
*/
public function relativePositionTo(self $size): PointInterface;
/**
* @see ImageInterface::resize()
*
* @throws GeometryException
*/
public function resize(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::resizeDown()
*
* @throws GeometryException
*/
public function resizeDown(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::scale()
*
* @throws GeometryException
*/
public function scale(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::scaleDown()
*
* @throws GeometryException
*/
public function scaleDown(?int $width = null, ?int $height = null): self;
/**
* @see ImageInterface::cover()
*
* @throws GeometryException
*/
public function cover(int $width, int $height): self;
/**
* @see ImageInterface::contain()
*
* @throws GeometryException
*/
public function contain(int $width, int $height): self;
/**
* @throws GeometryException
*/
public function containMax(int $width, int $height): self;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/SpecializableInterface.php | src/Interfaces/SpecializableInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\DriverException;
interface SpecializableInterface
{
/**
* Return an array of constructor parameters, which is usually passed from
* the generic object to the specialized object
*
* @return array<string, mixed>
*/
public function specializable(): array;
/**
* Set the driver for which the object is specialized
*
* @throws DriverException
*/
public function setDriver(DriverInterface $driver): self;
/**
* Return the driver for which the object was specialized
*/
public function driver(): DriverInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ProfileInterface.php | src/Interfaces/ProfileInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface ProfileInterface
{
/**
* Cast color profile object to string
*/
public function __toString(): string;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/CollectionInterface.php | src/Interfaces/CollectionInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Traversable;
/**
* @extends Traversable<int|string, mixed>
*/
interface CollectionInterface extends Traversable
{
/**
* Determine if the collection has item at given key
*/
public function has(int|string $key): bool;
/**
* Add item to collection
*
* @return CollectionInterface<int|string, mixed>
*/
public function push(mixed $item): self;
/**
* Return item for given key or return default is key does not exist
*/
public function get(int|string $key, mixed $default = null): mixed;
/**
* Return item at given numeric position starting at 0
*/
public function getAtPosition(int $key = 0, mixed $default = null): mixed;
/**
* Return first item in collection
*/
public function first(): mixed;
/**
* Return last item in collection
*/
public function last(): mixed;
/**
* Return item count of collection
*/
public function count(): int;
/**
* Empty collection
*
* @return CollectionInterface<int|string, mixed>
*/
public function empty(): self;
/**
* Transform collection as array
*
* @return array<int|string, mixed>
*/
public function toArray(): array;
/**
* Extract items based on given values and discard the rest.
*
* @return CollectionInterface<int|string, mixed>
*/
public function slice(int $offset, ?int $length = 0): self;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/FileInterface.php | src/Interfaces/FileInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface FileInterface
{
/**
* Save data in given path in file system
*
* @throws RuntimeException
*/
public function save(string $filepath): void;
/**
* Create file pointer from encoded data
*
* @return resource
*/
public function toFilePointer();
/**
* Return size in bytes
*/
public function size(): int;
/**
* Turn encoded data into string
*/
public function toString(): string;
/**
* Cast encoded data into string
*/
public function __toString(): string;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/SpecializedInterface.php | src/Interfaces/SpecializedInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface SpecializedInterface
{
//
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/InputHandlerInterface.php | src/Interfaces/InputHandlerInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface InputHandlerInterface
{
/**
* Try to decode the given input with each decoder of the the handler chain
*
* @throws RuntimeException
*/
public function handle(mixed $input): ImageInterface|ColorInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/DecoderInterface.php | src/Interfaces/DecoderInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface DecoderInterface
{
/**
* Decode given input either to color or image
*
* @throws RuntimeException
*/
public function decode(mixed $input): ImageInterface|ColorInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/DriverInterface.php | src/Interfaces/DriverInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Config;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\FileExtension;
use Intervention\Image\Format;
use Intervention\Image\MediaType;
interface DriverInterface
{
/**
* Return drivers unique id
*/
public function id(): string;
/**
* Get driver configuration
*/
public function config(): Config;
/**
* Resolve given (generic) object into a specialized version for the current driver
*
* @throws NotSupportedException
* @throws DriverException
*/
public function specialize(
ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface $object
): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface;
/**
* Resolve array of classnames or objects into their specialized version for the current driver
*
* @param array<string|object> $objects
* @throws NotSupportedException
* @throws DriverException
* @return array<object>
*/
public function specializeMultiple(array $objects): array;
/**
* Create new image instance with the current driver in given dimensions
*
* @throws RuntimeException
*/
public function createImage(int $width, int $height): ImageInterface;
/**
* Create new animated image
*
* @throws RuntimeException
*/
public function createAnimation(callable $init): ImageInterface;
/**
* Handle given input by decoding it to ImageInterface or ColorInterface
*
* @param array<string|DecoderInterface> $decoders
* @throws RuntimeException
*/
public function handleInput(mixed $input, array $decoders = []): ImageInterface|ColorInterface;
/**
* Return color processor for the given colorspace
*/
public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface;
/**
* Return font processor of the current driver
*/
public function fontProcessor(): FontProcessorInterface;
/**
* Check whether all requirements for operating the driver are met and
* throw exception if the check fails.
*
* @throws DriverException
*/
public function checkHealth(): void;
/**
* Check if the current driver supports the given format and if the
* underlying PHP extension was built with support for the format.
*/
public function supports(string|Format|FileExtension|MediaType $identifier): bool;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ColorChannelInterface.php | src/Interfaces/ColorChannelInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
interface ColorChannelInterface
{
/**
* Create new instance by either value or normalized value
*
* @throws ColorException
*/
public function __construct(?int $value = null, ?float $normalized = null);
/**
* Return color channels integer value
*/
public function value(): int;
/**
* Return the channels value normalized to a float value form 0 to 1 by its range
*/
public function normalize(int $precision = 32): float;
/**
* Throw exception if the given value is not applicable for channel
* otherwise the value is returned unchanged.
*
* @throws ColorException
*/
public function validate(mixed $value): mixed;
/**
* Return the the minimal possible value of the color channel
*/
public function min(): int;
/*
* Return the the maximal possible value of the color channel
*
* @return int
*/
public function max(): int;
/**
* Cast color channel's value to string
*/
public function toString(): string;
/**
* Cast color channel's value to string
*/
public function __toString(): string;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ImageManagerInterface.php | src/Interfaces/ImageManagerInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface ImageManagerInterface
{
/**
* Create new image instance with given width & height
*
* @link https://image.intervention.io/v3/basics/instantiation#create-new-images
*
* @throws RuntimeException
*/
public function create(int $width, int $height): ImageInterface;
/**
* Create new image instance from given input which can be one of the following
*
* - Path in filesystem
* - File Pointer resource
* - SplFileInfo object
* - Raw binary image data
* - Base64 encoded image data
* - Data Uri
* - Intervention\Image\Image Instance
*
* To decode the raw input data, you can optionally specify a decoding strategy
* with the second parameter. This can be an array of class names or objects
* of decoders to be processed in sequence. In this case, the input must be
* decodedable with one of the decoders passed. It is also possible to pass
* a single object or class name of a decoder.
*
* All decoders that implement the `DecoderInterface::class` can be passed. Usually
* a selection of classes of the namespace `Intervention\Image\Decoders`
*
* If the second parameter is not set, an attempt to decode the input is made
* with all available decoders of the driver.
*
* @link https://image.intervention.io/v3/basics/instantiation#read-image-sources
*
* @param string|array<string|DecoderInterface>|DecoderInterface $decoders
* @throws RuntimeException
*/
public function read(mixed $input, string|array|DecoderInterface $decoders = []): ImageInterface;
/**
* Create new animated image by given callback
*
* @link https://image.intervention.io/v3/basics/instantiation#create-animations
*
* @throws RuntimeException
*/
public function animate(callable $init): ImageInterface;
/**
* Return currently used driver
*/
public function driver(): DriverInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ModifierInterface.php | src/Interfaces/ModifierInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface ModifierInterface
{
/**
* Apply modifications of the current modifier to the given image
*
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/FontInterface.php | src/Interfaces/FontInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\FontException;
interface FontInterface
{
/**
* Set color of font
*/
public function setColor(mixed $color): self;
/**
* Get color of font
*/
public function color(): mixed;
/**
* Set stroke color of font
*/
public function setStrokeColor(mixed $color): self;
/**
* Get stroke color of font
*/
public function strokeColor(): mixed;
/**
/**
* Set stroke width of font
*
* @throws FontException
*/
public function setStrokeWidth(int $width): self;
/**
* Get stroke width of font
*/
public function strokeWidth(): int;
/**
* Determine if the font is drawn with outline stroke effect
*/
public function hasStrokeEffect(): bool;
/**
* Set font size
*/
public function setSize(float $size): self;
/**
* Get font size
*/
public function size(): float;
/**
* Set rotation angle of font
*/
public function setAngle(float $angle): self;
/**
* Get rotation angle of font
*/
public function angle(): float;
/**
* Set font filename
*/
public function setFilename(string $filename): self;
/**
* Get font filename
*/
public function filename(): ?string;
/**
* Determine if font has a corresponding filename
*/
public function hasFilename(): bool;
/**
* Set horizontal alignment of font
*/
public function setAlignment(string $align): self;
/**
* Get horizontal alignment of font
*/
public function alignment(): string;
/**
* Set vertical alignment of font
*/
public function setValignment(string $align): self;
/**
* Get vertical alignment of font
*/
public function valignment(): string;
/**
* Set typographical line height
*/
public function setLineHeight(float $value): self;
/**
* Get line height of font
*/
public function lineHeight(): float;
/**
* Set the wrap width with which the text is rendered
*/
public function setWrapWidth(?int $width): self;
/**
* Get wrap width with which the text is rendered
*/
public function wrapWidth(): ?int;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ImageInterface.php | src/Interfaces/ImageInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Closure;
use Countable;
use Intervention\Image\Encoders\AutoEncoder;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\FileExtension;
use Intervention\Image\Geometry\Bezier;
use Intervention\Image\Geometry\Circle;
use Intervention\Image\Geometry\Ellipse;
use Intervention\Image\Geometry\Line;
use Intervention\Image\Geometry\Polygon;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\MediaType;
use Intervention\Image\Origin;
use IteratorAggregate;
/**
* @extends IteratorAggregate<FrameInterface>
*/
interface ImageInterface extends IteratorAggregate, Countable
{
/**
* Return driver of current image
*/
public function driver(): DriverInterface;
/**
* Return core of current image
*/
public function core(): CoreInterface;
/**
* Return the origin of the image
*/
public function origin(): Origin;
/**
* Set the origin of the image
*/
public function setOrigin(Origin $origin): self;
/**
* Return width of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#read-the-pixel-width
*
* @throws RuntimeException
*/
public function width(): int;
/**
* Return height of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#read-the-pixel-height
*
* @throws RuntimeException
*/
public function height(): int;
/**
* Return size of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#read-the-image-size-as-an-object
*
* @throws RuntimeException
*/
public function size(): SizeInterface;
/**
* Encode image with given encoder
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images
*
* @throws RuntimeException
*/
public function encode(EncoderInterface $encoder = new AutoEncoder()): EncodedImageInterface;
/**
* Save the image to the specified path in the file system. If no path is
* given, the image will be saved at its original location.
*
* @link https://image.intervention.io/v3/basics/image-output#encode--save-combined
*
* @throws RuntimeException
*/
public function save(?string $path = null, mixed ...$options): self;
/**
* Apply given modifier to current image
*
* @link https://image.intervention.io/v3/modifying-images/custom-modifiers
*
* @throws RuntimeException
*/
public function modify(ModifierInterface $modifier): self;
/**
* Analyzer current image with given analyzer
*
* @throws RuntimeException
*/
public function analyze(AnalyzerInterface $analyzer): mixed;
/**
* Determine if current image is animated
*
* @link https://image.intervention.io/v3/modifying-images/animations#check-the-current-image-instance-for-animation
*/
public function isAnimated(): bool;
/**
* Remove all frames but keep the one at the specified position
*
* It is possible to specify the position as integer or string values.
* With the former, the exact position passed is searched for, while
* string values must represent a percentage value between '0%' and '100%'
* and the respective frame position is only determined approximately.
*
* @link https://image.intervention.io/v3/modifying-images/animations#remove-animation
*
* @throws RuntimeException
*/
public function removeAnimation(int|string $position = 0): self;
/**
* Extract animation frames based on given values and discard the rest
*
* @link https://image.intervention.io/v3/modifying-images/animations#change-the-animation-iteration-count
*
* @throws RuntimeException
*/
public function sliceAnimation(int $offset = 0, ?int $length = null): self;
/**
* Return loop count of animated image
*
* @link https://image.intervention.io/v3/modifying-images/animations#read-the-animation-iteration-count
*/
public function loops(): int;
/**
* Set loop count of animated image
*
* @link https://image.intervention.io/v3/modifying-images/animations#change-the-animation-iteration-count
*/
public function setLoops(int $loops): self;
/**
* Return exif data of current image
*
* @link https://image.intervention.io/v3/basics/meta-information#exif-information
*/
public function exif(?string $query = null): mixed;
/**
* Set exif data for the image object
*/
public function setExif(CollectionInterface $exif): self;
/**
* Return image resolution/density
*
* @link https://image.intervention.io/v3/basics/meta-information#image-resolution
*
* @throws RuntimeException
*/
public function resolution(): ResolutionInterface;
/**
* Set image resolution
*
* @link https://image.intervention.io/v3/basics/meta-information#image-resolution
*
* @throws RuntimeException
*/
public function setResolution(float $x, float $y): self;
/**
* Get the colorspace of the image
*
* @link https://image.intervention.io/v3/basics/colors#read-the-image-colorspace
*
* @throws RuntimeException
*/
public function colorspace(): ColorspaceInterface;
/**
* Transform image to given colorspace
*
* @link https://image.intervention.io/v3/basics/colors#change-the-image-colorspace
*
* @throws RuntimeException
*/
public function setColorspace(string|ColorspaceInterface $colorspace): self;
/**
* Return color of pixel at given position on given frame position
*
* @link https://image.intervention.io/v3/basics/colors#color-information
*
* @throws RuntimeException
*/
public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface;
/**
* Return all colors of pixel at given position for all frames of image
*
* @link https://image.intervention.io/v3/basics/colors#color-information
*
* @throws RuntimeException
*/
public function pickColors(int $x, int $y): CollectionInterface;
/**
* Return color that is mixed with transparent areas when converting to a format which
* does not support transparency.
*
* @throws RuntimeException
*/
public function blendingColor(): ColorInterface;
/**
* Set blending color will have no effect unless image is converted into a format
* which does not support transparency.
*
* @throws RuntimeException
*/
public function setBlendingColor(mixed $color): self;
/**
* Replace transparent areas of the image with given color
*
* @throws RuntimeException
*/
public function blendTransparency(mixed $color = null): self;
/**
* Retrieve ICC color profile of image
*
* @link https://image.intervention.io/v3/basics/colors#color-profiles
*
* @throws RuntimeException
*/
public function profile(): ProfileInterface;
/**
* Set given icc color profile to image
*
* @link https://image.intervention.io/v3/basics/colors#color-profiles
*
* @throws RuntimeException
*/
public function setProfile(ProfileInterface $profile): self;
/**
* Remove ICC color profile from the current image
*
* @link https://image.intervention.io/v3/basics/colors#color-profiles
*
* @throws RuntimeException
*/
public function removeProfile(): self;
/**
* Apply color quantization to the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#reduce-colors
*
* @throws RuntimeException
*/
public function reduceColors(int $limit, mixed $background = 'transparent'): self;
/**
* Sharpen the current image with given strength
*
* @link https://image.intervention.io/v3/modifying-images/effects#sharpening-effect
*
* @throws RuntimeException
*/
public function sharpen(int $amount = 10): self;
/**
* Turn image into a greyscale version
*
* @link https://image.intervention.io/v3/modifying-images/effects#convert-image-to-a-greyscale-version
*
* @throws RuntimeException
*/
public function greyscale(): self;
/**
* Adjust brightness of the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#change-the-image-brightness
*
* @throws RuntimeException
*/
public function brightness(int $level): self;
/**
* Adjust color contrast of the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#change-the-image-contrast
*
* @throws RuntimeException
*/
public function contrast(int $level): self;
/**
* Apply gamma correction on the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#gamma-correction
*
* @throws RuntimeException
*/
public function gamma(float $gamma): self;
/**
* Adjust the intensity of the RGB color channels
*
* @link https://image.intervention.io/v3/modifying-images/effects#color-correction
*
* @throws RuntimeException
*/
public function colorize(int $red = 0, int $green = 0, int $blue = 0): self;
/**
* Mirror the current image vertically by swapping top and bottom
*
* @link https://image.intervention.io/v3/modifying-images/effects#mirror-image-vertically
*
* @throws RuntimeException
*/
public function flip(): self;
/**
* Mirror the current image horizontally by swapping left and right
*
* @link https://image.intervention.io/v3/modifying-images/effects#mirror-image-horizontally
*
* @throws RuntimeException
*/
public function flop(): self;
/**
* Blur current image by given strength
*
* @link https://image.intervention.io/v3/modifying-images/effects#blur-effect
*
* @throws RuntimeException
*/
public function blur(int $amount = 5): self;
/**
* Invert the colors of the current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#invert-colors
*
* @throws RuntimeException
*/
public function invert(): self;
/**
* Apply pixelation filter effect on current image
*
* @link https://image.intervention.io/v3/modifying-images/effects#pixelation-effect
*
* @throws RuntimeException
*/
public function pixelate(int $size): self;
/**
* Rotate current image by given angle
*
* @link https://image.intervention.io/v3/modifying-images/effects#image-rotation
*
* @param string $background
* @throws RuntimeException
*/
public function rotate(float $angle, mixed $background = 'ffffff'): self;
/**
* Rotate the image to be upright according to exif information
*
* @link https://image.intervention.io/v3/modifying-images/effects#image-orientation-according-to-exif-data
*
* @throws RuntimeException
*/
public function orient(): self;
/**
* Draw text on image
*
* @link https://image.intervention.io/v3/modifying-images/text-fonts
*
* @throws RuntimeException
*/
public function text(string $text, int $x, int $y, callable|Closure|FontInterface $font): self;
/**
* Resize image to the given width and/or height
*
* @link https://image.intervention.io/v3/modifying-images/resizing#simple-image-resizing
*
* @throws RuntimeException
*/
public function resize(?int $width = null, ?int $height = null): self;
/**
* Resize image to the given width and/or height without exceeding the original dimensions
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-without-exceeding-the-original-size
*
* @throws RuntimeException
*/
public function resizeDown(?int $width = null, ?int $height = null): self;
/**
* Resize image to the given width and/or height and keep the original aspect ratio
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-images-proportionally
*
* @throws RuntimeException
*/
public function scale(?int $width = null, ?int $height = null): self;
/**
* Resize image to the given width and/or height, keep the original aspect ratio
* and do not exceed the original image width or height
*
* @link https://image.intervention.io/v3/modifying-images/resizing#scale-images-but-do-not-exceed-the-original-size
*
* @throws RuntimeException
*/
public function scaleDown(?int $width = null, ?int $height = null): self;
/**
* Takes the specified width and height and scales them to the largest
* possible size that fits within the original size. This scaled size is
* then positioned on the original and cropped, before this result is resized
* to the desired size using the arguments
*
* @link https://image.intervention.io/v3/modifying-images/resizing#cropping--resizing-combined
*
* @throws RuntimeException
*/
public function cover(int $width, int $height, string $position = 'center'): self;
/**
* Same as cover() but do not exceed the original image size
*
* @link https://image.intervention.io/v3/modifying-images/resizing#fitted-resizing-without-exceeding-the-original-size
*
* @throws RuntimeException
*/
public function coverDown(int $width, int $height, string $position = 'center'): self;
/**
* Resize the boundaries of the current image to given width and height.
* An anchor position can be defined to determine where the original image
* is fixed. A background color can be passed to define the color of the
* new emerging areas.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-image-boundaries-without-resampling-the-original-image
*
* @throws RuntimeException
*/
public function resizeCanvas(
?int $width = null,
?int $height = null,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* Resize canvas in the same way as resizeCanvas() but takes relative values
* for the width and height, which will be added or subtracted to the
* original image size.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resize-image-boundaries-relative-to-the-original
*
* @throws RuntimeException
*/
public function resizeCanvasRelative(
?int $width = null,
?int $height = null,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* Padded resizing means that the original image is scaled until it fits the
* defined target size with unchanged aspect ratio. The original image is
* not scaled up but only down.
*
* Compared to the cover() method, this method does not create cropped areas,
* but possibly new empty areas on the sides of the result image. These are
* filled with the specified background color.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#resizing--padding-combined
*
* @param string $background
* @throws RuntimeException
*/
public function pad(
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* This method does the same as pad(), but the original image is also scaled
* up if the target size exceeds the original size.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#padded-resizing-with-upscaling
*
* @param string $background
* @throws RuntimeException
*/
public function contain(
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center'
): self;
/**
* Cut out a rectangular part of the current image with given width and
* height at a given position. Define optional x,y offset coordinates
* to move the cutout by the given amount of pixels.
*
* @link https://image.intervention.io/v3/modifying-images/resizing#cut-out-a-rectangular-part
*
* @throws RuntimeException
*/
public function crop(
int $width,
int $height,
int $offset_x = 0,
int $offset_y = 0,
mixed $background = 'ffffff',
string $position = 'top-left'
): self;
/**
* Trim the image by removing border areas of similar color within a the given tolerance
*
* @link https://image.intervention.io/v3/modifying-images/resizing#remove-border-areas-in-similar-color
*
* @throws RuntimeException
* @throws AnimationException
*/
public function trim(int $tolerance = 0): self;
/**
* Place another image into the current image instance
*
* @link https://image.intervention.io/v3/modifying-images/inserting#insert-images
*
* @throws RuntimeException
*/
public function place(
mixed $element,
string $position = 'top-left',
int $offset_x = 0,
int $offset_y = 0,
int $opacity = 100
): self;
/**
* Fill image with given color
*
* If an optional position is specified for the filling process ln the form
* of x and y coordinates, the process is executed as flood fill. This means
* that the color at the specified position is taken as a reference and all
* adjacent pixels are also filled with the filling color.
*
* If no coordinates are specified, the entire image area is filled.
*
* @link https://image.intervention.io/v3/modifying-images/drawing#fill-images-with-color
*
* @throws RuntimeException
*/
public function fill(mixed $color, ?int $x = null, ?int $y = null): self;
/**
* Draw a single pixel at given position defined by the coordinates x and y in a given color.
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-pixels
*
* @throws RuntimeException
*/
public function drawPixel(int $x, int $y, mixed $color): self;
/**
* Draw a rectangle on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-rectangle
*
* @throws RuntimeException
*/
public function drawRectangle(int $x, int $y, callable|Closure|Rectangle $init): self;
/**
* Draw ellipse on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-ellipses
*
* @throws RuntimeException
*/
public function drawEllipse(int $x, int $y, callable|Closure|Ellipse $init): self;
/**
* Draw circle on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-circle
*
* @throws RuntimeException
*/
public function drawCircle(int $x, int $y, callable|Closure|Circle $init): self;
/**
* Draw a polygon on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-polygon
*
* @throws RuntimeException
*/
public function drawPolygon(callable|Closure|Polygon $init): self;
/**
* Draw a line on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-a-line
*
* @throws RuntimeException
*/
public function drawLine(callable|Closure|Line $init): self;
/**
* Draw a bezier curve on the current image
*
* @link https://image.intervention.io/v3/modifying-images/drawing#draw-bezier-curves
*
* @throws RuntimeException
*/
public function drawBezier(callable|Closure|Bezier $init): self;
/**
* Encode image to given media (mime) type. If no type is given the image
* will be encoded to the format of the originally read image.
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images-by-media-mime-type
*
* @throws RuntimeException
*/
public function encodeByMediaType(null|string|MediaType $type = null, mixed ...$options): EncodedImageInterface;
/**
* Encode the image into the format represented by the given extension. If no
* extension is given the image will be encoded to the format of the
* originally read image.
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images-by-file-extension
*
* @throws RuntimeException
*/
public function encodeByExtension(
null|string|FileExtension $extension = null,
mixed ...$options
): EncodedImageInterface;
/**
* Encode the image into the format represented by the given extension of
* the given file path extension is given the image will be encoded to
* the format of the originally read image.
*
* @link https://image.intervention.io/v3/basics/image-output#encode-images-by-file-path
*
* @throws RuntimeException
*/
public function encodeByPath(?string $path = null, mixed ...$options): EncodedImageInterface;
/**
* Encode image to JPEG format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-jpeg-format
*
* @throws RuntimeException
*/
public function toJpeg(mixed ...$options): EncodedImageInterface;
/**
* Encode image to Jpeg2000 format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-jpeg-2000-format
*
* @throws RuntimeException
*/
public function toJpeg2000(mixed ...$options): EncodedImageInterface;
/**
* Encode image to Webp format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-webp-format
*
* @throws RuntimeException
*/
public function toWebp(mixed ...$options): EncodedImageInterface;
/**
* Encode image to PNG format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-png-format
*
* @throws RuntimeException
*/
public function toPng(mixed ...$options): EncodedImageInterface;
/**
* Encode image to GIF format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-gif-format
*
* @throws RuntimeException
*/
public function toGif(mixed ...$options): EncodedImageInterface;
/**
* Encode image to Bitmap format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-windows-bitmap-format
*
* @throws RuntimeException
*/
public function toBitmap(mixed ...$options): EncodedImageInterface;
/**
* Encode image to AVIF format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-av1-image-file-format-avif
*
* @throws RuntimeException
*/
public function toAvif(mixed ...$options): EncodedImageInterface;
/**
* Encode image to TIFF format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-tiff-format
*
* @throws RuntimeException
*/
public function toTiff(mixed ...$options): EncodedImageInterface;
/**
* Encode image to HEIC format
*
* @link https://image.intervention.io/v3/basics/image-output#encode-heic-format
*
* @throws RuntimeException
*/
public function toHeic(mixed ...$options): EncodedImageInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/FontProcessorInterface.php | src/Interfaces/FontProcessorInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Typography\TextBlock;
interface FontProcessorInterface
{
/**
* Calculate size of bounding box of given text in conjunction with the given font
*
* @throws FontException
*/
public function boxSize(string $text, FontInterface $font): SizeInterface;
/**
* Build TextBlock object from text string and align every line according
* to text modifier's font object and position.
*
* @throws FontException
*/
public function textBlock(string $text, FontInterface $font, PointInterface $position): TextBlock;
/**
* Calculate the actual font size to pass at the driver level
*/
public function nativeFontSize(FontInterface $font): float;
/**
* Calculate the typographical font size in pixels
*
* @throws FontException
*/
public function typographicalSize(FontInterface $font): int;
/**
* Calculates typographical cap height
*
* @throws FontException
*/
public function capHeight(FontInterface $font): int;
/**
* Calculates typographical leading size
*
* @throws FontException
*/
public function leading(FontInterface $font): int;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ColorInterface.php | src/Interfaces/ColorInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\RuntimeException;
interface ColorInterface
{
/**
* Static color factory method that takes any supported color format
* and returns a corresponding color object
*
* @throws RuntimeException
*/
public static function create(mixed $input): self;
/**
* Return colorspace of current color
*/
public function colorspace(): ColorspaceInterface;
/**
* Cast color object to string
*/
public function toString(): string;
/**
* Cast color object to array
*
* @return array<int>
*/
public function toArray(): array;
/**
* Cast color object to hex encoded web color
*/
public function toHex(string $prefix = ''): string;
/**
* Return array of all color channels
*
* @return array<ColorChannelInterface>
*/
public function channels(): array;
/**
* Return array of normalized color channel values
*
* @return array<float>
*/
public function normalize(): array;
/**
* Retrieve the color channel by its classname
*
* @throws ColorException
*/
public function channel(string $classname): ColorChannelInterface;
/**
* Convert color to given colorspace
*/
public function convertTo(string|ColorspaceInterface $colorspace): self;
/**
* Determine if the current color is gray
*/
public function isGreyscale(): bool;
/**
* Determine if the current color is (semi) transparent
*/
public function isTransparent(): bool;
/**
* Determine whether the current color is completely transparent
*/
public function isClear(): bool;
/**
* Cast color object to string
*/
public function __toString(): string;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/CoreInterface.php | src/Interfaces/CoreInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\AnimationException;
interface CoreInterface extends CollectionInterface
{
/**
* return driver's representation of the image core.
*
* @throws AnimationException
*/
public function native(): mixed;
/**
* Set driver's representation of the image core.
*
* @return CoreInterface<FrameInterface>
*/
public function setNative(mixed $native): self;
/**
* Count number of frames of animated image core
*/
public function count(): int;
/**
* Return frame of given position in an animated image
*
* @throws AnimationException
*/
public function frame(int $position): FrameInterface;
/**
* Add new frame to core
*
* @return CoreInterface<FrameInterface>
*/
public function add(FrameInterface $frame): self;
/**
* Return number of repetitions of an animated image
*/
public function loops(): int;
/**
* Set the number of repetitions for an animation. Where a
* value of 0 means infinite repetition.
*
* @return CoreInterface<FrameInterface>
*/
public function setLoops(int $loops): self;
/**
* Get first frame in core
*
* @throws AnimationException
*/
public function first(): FrameInterface;
/**
* Get last frame in core
*
* @throws AnimationException
*/
public function last(): FrameInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/FrameInterface.php | src/Interfaces/FrameInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface FrameInterface
{
/**
* Return image data of frame in driver specific format
*/
public function native(): mixed;
/**
* Set image data of drame in driver specific format
*/
public function setNative(mixed $native): self;
/**
* Transform frame into an image
*
* @throws RuntimeException
*/
public function toImage(DriverInterface $driver): ImageInterface;
/**
* Get image size of current frame
*/
public function size(): SizeInterface;
/**
* Return animation delay of current frame in seconds
*/
public function delay(): float;
/**
* Set animation frame delay in seoncds
*/
public function setDelay(float $delay): self;
/**
* Get disposal method of current frame
*/
public function dispose(): int;
/**
* Set disposal method of current frame
*/
public function setDispose(int $dispose): self;
/**
* Set pixel offset of current frame
*/
public function setOffset(int $left, int $top): self;
/**
* Get left offset in pixels
*/
public function offsetLeft(): int;
/**
* Set left pixel offset for current frame
*/
public function setOffsetLeft(int $offset): self;
/**
* Get top pixel offset of current frame
*/
public function offsetTop(): int;
/**
* Set top pixel offset of current frame
*/
public function setOffsetTop(int $offset): self;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ColorspaceInterface.php | src/Interfaces/ColorspaceInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface ColorspaceInterface
{
/**
* Convert given color to the format of the current colorspace
*/
public function importColor(ColorInterface $color): ColorInterface;
/**
* Create new color in colorspace from given normalized channel values
*
* @param array<float> $normalized
*/
public function colorFromNormalized(array $normalized): ColorInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/DrawableInterface.php | src/Interfaces/DrawableInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface DrawableInterface
{
/**
* Position of the drawable object
*/
public function position(): PointInterface;
/**
* Set position of the drawable object
*/
public function setPosition(PointInterface $position): self;
/**
* Set the background color of the drawable object
*/
public function setBackgroundColor(mixed $color): self;
/**
* Return background color of drawable object
*/
public function backgroundColor(): mixed;
/**
* Determine if a background color was set
*/
public function hasBackgroundColor(): bool;
/**
* Set border color & size of the drawable object
*/
public function setBorder(mixed $color, int $size = 1): self;
/**
* Set border size of the drawable object
*/
public function setBorderSize(int $size): self;
/**
* Set border color of the drawable object
*/
public function setBorderColor(mixed $color): self;
/**
* Get border size
*/
public function borderSize(): int;
/**
* Get border color of drawable object
*/
public function borderColor(): mixed;
/**
* Determine if the drawable object has a border
*/
public function hasBorder(): bool;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/EncoderInterface.php | src/Interfaces/EncoderInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface EncoderInterface
{
/**
* Encode given image
*
* @throws RuntimeException
*/
public function encode(ImageInterface $image): EncodedImageInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ResolutionInterface.php | src/Interfaces/ResolutionInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface ResolutionInterface
{
/**
* Return resolution of x-axis
*/
public function x(): float;
/**
* Set resolution on x-axis
*/
public function setX(float $x): self;
/**
* Return resolution on y-axis
*/
public function y(): float;
/**
* Set resolution on y-axis
*/
public function setY(float $y): self;
/**
* Convert the resolution to DPI
*/
public function perInch(): self;
/**
* Convert the resolution to DPCM
*/
public function perCm(): self;
/**
* Return string representation of unit
*/
public function unit(): string;
/**
* Transform object to string
*/
public function toString(): string;
/**
* Cast object to string
*/
public function __toString(): string;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/PointInterface.php | src/Interfaces/PointInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
interface PointInterface
{
/**
* Return x position
*/
public function x(): int;
/**
* Return y position
*/
public function y(): int;
/**
* Set x position
*/
public function setX(int $x): self;
/**
* Set y position
*/
public function setY(int $y): self;
/**
* Move X coordinate
*/
public function moveX(int $value): self;
/**
* Move Y coordinate
*/
public function moveY(int $value): self;
/**
* Move position of current point by given coordinates
*/
public function move(int $x, int $y): self;
/**
* Set position of point
*/
public function setPosition(int $x, int $y): self;
/**
* Rotate point counter clock wise around given pivot point
*/
public function rotate(float $angle, self $pivot): self;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/ColorProcessorInterface.php | src/Interfaces/ColorProcessorInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\ColorException;
interface ColorProcessorInterface
{
/**
* Turn given color in the driver's color implementation
*
* @throws ColorException
*/
public function colorToNative(ColorInterface $color): mixed;
/**
* Turn the given driver's definition of a color into a color object
*
* @throws ColorException
*/
public function nativeToColor(mixed $native): ColorInterface;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Interfaces/AnalyzerInterface.php | src/Interfaces/AnalyzerInterface.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\RuntimeException;
interface AnalyzerInterface
{
/**
* Analyze given image and return the retrieved data
*
* @throws RuntimeException
*/
public function analyze(ImageInterface $image): mixed;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/SpecializableAnalyzer.php | src/Drivers/SpecializableAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ImageInterface;
abstract class SpecializableAnalyzer extends Specializable implements AnalyzerInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return $image->analyze($this);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/SpecializableDecoder.php | src/Drivers/SpecializableDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializableInterface;
use Intervention\Image\Traits\CanBeDriverSpecialized;
abstract class SpecializableDecoder extends AbstractDecoder implements SpecializableInterface
{
use CanBeDriverSpecialized;
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
throw new DecoderException('Decoder must be specialized by the driver first.');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/SpecializableModifier.php | src/Drivers/SpecializableModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
abstract class SpecializableModifier extends Specializable implements ModifierInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
return $image->modify($this);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/AbstractEncoder.php | src/Drivers/AbstractEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\EncodedImage;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanBuildFilePointer;
abstract class AbstractEncoder implements EncoderInterface
{
use CanBuildFilePointer;
public const DEFAULT_QUALITY = 75;
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImageInterface
{
return $image->encode($this);
}
/**
* Build new file pointer, run callback with it and return result as encoded image
*
* @throws RuntimeException
*/
protected function createEncodedImage(callable $callback, ?string $mediaType = null): EncodedImage
{
$pointer = $this->buildFilePointer();
$callback($pointer);
return is_string($mediaType) ? new EncodedImage($pointer, $mediaType) : new EncodedImage($pointer);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/AbstractDecoder.php | src/Drivers/AbstractDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Exception;
use Intervention\Image\Collection;
use Intervention\Image\Interfaces\CollectionInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Traits\CanBuildFilePointer;
abstract class AbstractDecoder implements DecoderInterface
{
use CanBuildFilePointer;
/**
* Determine if the given input is GIF data format
*/
protected function isGifFormat(string $input): bool
{
return str_starts_with($input, 'GIF87a') || str_starts_with($input, 'GIF89a');
}
/**
* Determine if given input is a path to an existing regular file
*/
protected function isFile(mixed $input): bool
{
if (!is_string($input)) {
return false;
}
if (strlen($input) > PHP_MAXPATHLEN) {
return false;
}
try {
if (!@is_file($input)) {
return false;
}
} catch (Exception) {
return false;
}
return true;
}
/**
* Extract and return EXIF data from given input which can be binary image
* data or a file path.
*
* @return CollectionInterface<string, mixed>
*/
protected function extractExifData(string $path_or_data): CollectionInterface
{
if (!function_exists('exif_read_data')) {
return new Collection();
}
try {
$source = match (true) {
$this->isFile($path_or_data) => $path_or_data, // path
default => $this->buildFilePointer($path_or_data), // data
};
// extract exif data
$data = @exif_read_data($source, null, true);
if (is_resource($source)) {
fclose($source);
}
} catch (Exception) {
$data = [];
}
return new Collection(is_array($data) ? $data : []);
}
/**
* Determine if given input is base64 encoded data
*/
protected function isValidBase64(mixed $input): bool
{
if (!is_string($input)) {
return false;
}
return base64_encode(base64_decode($input)) === str_replace(["\n", "\r"], '', $input);
}
/**
* Parse data uri
*/
protected function parseDataUri(mixed $input): object
{
$pattern = "/^data:(?P<mediatype>\w+\/[-+.\w]+)?" .
"(?P<parameters>(;[-\w]+=[-\w]+)*)(?P<base64>;base64)?,(?P<data>.*)/";
$result = preg_match($pattern, (string) $input, $matches);
return new class ($matches, $result)
{
/**
* @param array<mixed> $matches
* @return void
*/
public function __construct(private array $matches, private int|false $result)
{
//
}
public function isValid(): bool
{
return (bool) $this->result;
}
public function mediaType(): ?string
{
if (isset($this->matches['mediatype']) && !empty($this->matches['mediatype'])) {
return $this->matches['mediatype'];
}
return null;
}
public function hasMediaType(): bool
{
return !empty($this->mediaType());
}
public function isBase64Encoded(): bool
{
return isset($this->matches['base64']) && $this->matches['base64'] === ';base64';
}
public function data(): ?string
{
if (isset($this->matches['data']) && !empty($this->matches['data'])) {
return $this->matches['data'];
}
return null;
}
};
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/AbstractFrame.php | src/Drivers/AbstractFrame.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Interfaces\FrameInterface;
abstract class AbstractFrame implements FrameInterface
{
/**
* Show debug info for the current image
*
* @return array<string, mixed>
*/
public function __debugInfo(): array
{
return [
'delay' => $this->delay(),
'left' => $this->offsetLeft(),
'top' => $this->offsetTop(),
'dispose' => $this->dispose(),
];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Specializable.php | src/Drivers/Specializable.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Interfaces\SpecializableInterface;
use Intervention\Image\Traits\CanBeDriverSpecialized;
abstract class Specializable implements SpecializableInterface
{
use CanBeDriverSpecialized;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/SpecializableEncoder.php | src/Drivers/SpecializableEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Interfaces\SpecializableInterface;
use Intervention\Image\Traits\CanBeDriverSpecialized;
abstract class SpecializableEncoder extends AbstractEncoder implements SpecializableInterface
{
use CanBeDriverSpecialized;
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/AbstractFontProcessor.php | src/Drivers/AbstractFontProcessor.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Interfaces\FontProcessorInterface;
use Intervention\Image\Interfaces\PointInterface;
use Intervention\Image\Typography\Line;
use Intervention\Image\Typography\TextBlock;
abstract class AbstractFontProcessor implements FontProcessorInterface
{
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::textBlock()
*/
public function textBlock(string $text, FontInterface $font, PointInterface $position): TextBlock
{
$lines = $this->wrapTextBlock(new TextBlock($text), $font);
$pivot = $this->buildPivot($lines, $font, $position);
$leading = $this->leading($font);
$blockWidth = $this->boxSize((string) $lines->longestLine(), $font)->width();
$x = $pivot->x();
$y = $font->hasFilename() ? $pivot->y() + $this->capHeight($font) : $pivot->y();
$xAdjustment = 0;
// adjust line positions according to alignment
foreach ($lines as $line) {
$lineBoxSize = $this->boxSize((string) $line, $font);
$lineWidth = $lineBoxSize->width() + $lineBoxSize->pivot()->x();
$xAdjustment = $font->alignment() === 'left' ? 0 : $blockWidth - $lineWidth;
$xAdjustment = $font->alignment() === 'right' ? intval(round($xAdjustment)) : $xAdjustment;
$xAdjustment = $font->alignment() === 'center' ? intval(round($xAdjustment / 2)) : $xAdjustment;
$position = new Point($x + $xAdjustment, $y);
$position->rotate($font->angle(), $pivot);
$line->setPosition($position);
$y += $leading;
}
return $lines;
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::nativeFontSize()
*/
public function nativeFontSize(FontInterface $font): float
{
return $font->size();
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::typographicalSize()
*/
public function typographicalSize(FontInterface $font): int
{
return $this->boxSize('Hy', $font)->height();
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::capHeight()
*/
public function capHeight(FontInterface $font): int
{
return $this->boxSize('T', $font)->height();
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::leading()
*/
public function leading(FontInterface $font): int
{
return intval(round($this->typographicalSize($font) * $font->lineHeight()));
}
/**
* Reformat a text block by wrapping each line before the given maximum width
*
* @throws FontException
*/
protected function wrapTextBlock(TextBlock $block, FontInterface $font): TextBlock
{
$newLines = [];
foreach ($block as $line) {
foreach ($this->wrapLine($line, $font) as $newLine) {
$newLines[] = $newLine;
}
}
return $block->setLines($newLines);
}
/**
* Check if a line exceeds the given maximum width and wrap it if necessary.
* The output will be an array of formatted lines that are all within the
* maximum width.
*
* @throws FontException
* @return array<Line>
*/
protected function wrapLine(Line $line, FontInterface $font): array
{
// no wrap width - no wrapping
if (is_null($font->wrapWidth())) {
return [$line];
}
$wrapped = [];
$formattedLine = new Line();
foreach ($line as $word) {
// calculate width of newly formatted line
$lineWidth = $this->boxSize(match ($formattedLine->count()) {
0 => $word,
default => $formattedLine . ' ' . $word,
}, $font)->width();
// decide if word fits on current line or a new line must be created
if ($line->count() === 1 || $lineWidth <= $font->wrapWidth()) {
$formattedLine->add($word);
} else {
if ($formattedLine->count() !== 0) {
$wrapped[] = $formattedLine;
}
$formattedLine = new Line($word);
}
}
$wrapped[] = $formattedLine;
return $wrapped;
}
/**
* Build pivot point of textblock according to the font settings and based on given position
*
* @throws FontException
*/
protected function buildPivot(TextBlock $block, FontInterface $font, PointInterface $position): PointInterface
{
// bounding box
$box = new Rectangle(
$this->boxSize((string) $block->longestLine(), $font)->width(),
$this->leading($font) * ($block->count() - 1) + $this->capHeight($font)
);
// set position
$box->setPivot($position);
// alignment
$box->align($font->alignment());
$box->valign($font->valignment());
$box->rotate($font->angle());
return $box->last();
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/AbstractDriver.php | src/Drivers/AbstractDriver.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers;
use Intervention\Image\Config;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\InputHandler;
use Intervention\Image\Interfaces\AnalyzerInterface;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\EncoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Interfaces\SpecializableInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use ReflectionClass;
abstract class AbstractDriver implements DriverInterface
{
/**
* Driver options
*/
protected Config $config;
/**
* @throws DriverException
* @return void
*/
public function __construct()
{
$this->config = new Config();
$this->checkHealth();
}
/**
* {@inheritdoc}
*
* @see DriverInterface::config()
*/
public function config(): Config
{
return $this->config;
}
/**
* {@inheritdoc}
*
* @see DriverInterface::handleInput()
*/
public function handleInput(mixed $input, array $decoders = []): ImageInterface|ColorInterface
{
return InputHandler::withDecoders($decoders, $this)->handle($input);
}
/**
* {@inheritdoc}
*
* @see DriverInterface::specialize()
*/
public function specialize(
ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface $object
): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface {
// return object directly if no specializing is possible
if (!($object instanceof SpecializableInterface)) {
return $object;
}
// return directly and only attach driver if object is already specialized
if ($object instanceof SpecializedInterface) {
$object->setDriver($this);
return $object;
}
// resolve classname for specializable object
$specialized_classname = implode("\\", [
(new ReflectionClass($this))->getNamespaceName(), // driver's namespace
match (true) {
$object instanceof ModifierInterface => 'Modifiers',
$object instanceof AnalyzerInterface => 'Analyzers',
$object instanceof EncoderInterface => 'Encoders',
$object instanceof DecoderInterface => 'Decoders',
},
$object_shortname = (new ReflectionClass($object))->getShortName(),
]);
// fail if driver specialized classname does not exists
if (!class_exists($specialized_classname)) {
throw new NotSupportedException(
"Class '" . $object_shortname . "' is not supported by " . $this->id() . " driver."
);
}
// create a driver specialized object with the specializable properties of generic object
$specialized = new $specialized_classname(...$object->specializable());
// attach driver
return $specialized->setDriver($this);
}
/**
* {@inheritdoc}
*
* @see DriverInterface::specializeMultiple()
*
* @throws NotSupportedException
* @throws DriverException
*/
public function specializeMultiple(array $objects): array
{
return array_map(
function (string|object $object): ModifierInterface|AnalyzerInterface|EncoderInterface|DecoderInterface {
return $this->specialize(
match (true) {
is_string($object) => new $object(),
is_object($object) => $object,
}
);
},
$objects
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Frame.php | src/Drivers/Gd/Frame.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd;
use GdImage;
use Intervention\Image\Drivers\AbstractFrame;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class Frame extends AbstractFrame implements FrameInterface
{
/**
* Create new frame instance
*
* @return void
*/
public function __construct(
protected GdImage $native,
protected float $delay = 0,
protected int $dispose = 1,
protected int $offset_left = 0,
protected int $offset_top = 0
) {
//
}
/**
* {@inheritdoc}
*
* @see FrameInterface::toImage()
*/
public function toImage(DriverInterface $driver): ImageInterface
{
return new Image($driver, new Core([$this]));
}
/**
* {@inheritdoc}
*
* @see FrameInterface::setNative()
*/
public function setNative(mixed $native): FrameInterface
{
$this->native = $native;
return $this;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::native()
*/
public function native(): GdImage
{
return $this->native;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::size()
*/
public function size(): SizeInterface
{
return new Rectangle(imagesx($this->native), imagesy($this->native));
}
/**
* {@inheritdoc}
*
* @see FrameInterface::delay()
*/
public function delay(): float
{
return $this->delay;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::setDelay()
*/
public function setDelay(float $delay): FrameInterface
{
$this->delay = $delay;
return $this;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::dispose()
*/
public function dispose(): int
{
return $this->dispose;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::setDispose()
*
* @throws InputException
*/
public function setDispose(int $dispose): FrameInterface
{
if (!in_array($dispose, [0, 1, 2, 3])) {
throw new InputException('Value for argument $dispose must be 0, 1, 2 or 3.');
}
$this->dispose = $dispose;
return $this;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::setOffset()
*/
public function setOffset(int $left, int $top): FrameInterface
{
$this->offset_left = $left;
$this->offset_top = $top;
return $this;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::offsetLeft()
*/
public function offsetLeft(): int
{
return $this->offset_left;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::setOffsetLeft()
*/
public function setOffsetLeft(int $offset): FrameInterface
{
$this->offset_left = $offset;
return $this;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::offsetTop()
*/
public function offsetTop(): int
{
return $this->offset_top;
}
/**
* {@inheritdoc}
*
* @see FrameInterface::setOffsetTop()
*/
public function setOffsetTop(int $offset): FrameInterface
{
$this->offset_top = $offset;
return $this;
}
/**
* This workaround helps cloning GdImages which is currently not possible.
*
* @throws ColorException
*/
public function __clone(): void
{
$this->native = Cloner::clone($this->native);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Core.php | src/Drivers/Gd/Core.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd;
use Intervention\Image\Collection;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Interfaces\CoreInterface;
use Intervention\Image\Interfaces\FrameInterface;
class Core extends Collection implements CoreInterface
{
protected int $loops = 0;
/**
* {@inheritdoc}
*
* @see CoreInterface::add()
*/
public function add(FrameInterface $frame): CoreInterface
{
$this->push($frame);
return $this;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::native()
*/
public function native(): mixed
{
return $this->first()->native();
}
/**
* {@inheritdoc}
*
* @see CoreInterface::setNative()
*/
public function setNative(mixed $native): self
{
$this->empty()->push(new Frame($native));
return $this;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::frame()
*/
public function frame(int $position): FrameInterface
{
$frame = $this->getAtPosition($position);
if (!($frame instanceof FrameInterface)) {
throw new AnimationException('Frame #' . $position . ' could not be found in the image.');
}
return $frame;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::loops()
*/
public function loops(): int
{
return $this->loops;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::setLoops()
*/
public function setLoops(int $loops): self
{
$this->loops = $loops;
return $this;
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::first()
*/
public function first(): FrameInterface
{
return parent::first();
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::last()
*/
public function last(): FrameInterface
{
return parent::last();
}
/**
* Clone instance
*/
public function __clone(): void
{
foreach ($this->items as $key => $frame) {
$this->items[$key] = clone $frame;
}
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/FontProcessor.php | src/Drivers/Gd/FontProcessor.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd;
use Intervention\Image\Drivers\AbstractFontProcessor;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Interfaces\SizeInterface;
class FontProcessor extends AbstractFontProcessor
{
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::boxSize()
*/
public function boxSize(string $text, FontInterface $font): SizeInterface
{
// if the font has no ttf file the box size is calculated
// with gd's internal font system: integer values from 1-5
if (!$font->hasFilename()) {
// calculate box size from gd font
$box = new Rectangle(0, 0);
$chars = mb_strlen($text);
if ($chars > 0) {
$box->setWidth(
$chars * $this->gdCharacterWidth((int) $font->filename())
);
$box->setHeight(
$this->gdCharacterHeight((int) $font->filename())
);
}
return $box;
}
// build full path to font file to make sure to pass absolute path to imageftbbox()
// because of issues with different GD version behaving differently when passing
// relative paths to imageftbbox()
$fontPath = realpath($font->filename());
if ($fontPath === false) {
throw new FontException('Font file ' . $font->filename() . ' does not exist.');
}
// calculate box size from ttf font file with angle 0
$box = imageftbbox(
size: $this->nativeFontSize($font),
angle: 0,
font_filename: $fontPath,
string: $text,
);
if ($box === false) {
throw new FontException('Unable to calculate box size of font ' . $font->filename() . '.');
}
// build size from points
return new Rectangle(
width: intval(abs($box[6] - $box[4])), // difference of upper-left-x and upper-right-x
height: intval(abs($box[7] - $box[1])), // difference if upper-left-y and lower-left-y
pivot: new Point($box[6], $box[7]), // position of upper-left corner
);
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::nativeFontSize()
*/
public function nativeFontSize(FontInterface $font): float
{
return floatval(round($font->size() * .76, 6));
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::leading()
*/
public function leading(FontInterface $font): int
{
return (int) round(parent::leading($font) * .8);
}
/**
* Return width of a single character
*/
protected function gdCharacterWidth(int $gdfont): int
{
return $gdfont + 4;
}
/**
* Return height of a single character
*/
protected function gdCharacterHeight(int $gdfont): int
{
return match ($gdfont) {
2, 3 => 14,
4, 5 => 16,
default => 8,
};
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Cloner.php | src/Drivers/Gd/Cloner.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd;
use GdImage;
use Intervention\Image\Colors\Rgb\Channels\Alpha;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\SizeInterface;
class Cloner
{
/**
* Create a clone of the given GdImage
*
* @throws ColorException
*/
public static function clone(GdImage $gd): GdImage
{
// create empty canvas with same size
$clone = static::cloneEmpty($gd);
// transfer actual image to clone
imagecopy($clone, $gd, 0, 0, 0, 0, imagesx($gd), imagesy($gd));
return $clone;
}
/**
* Create an "empty" clone of the given GdImage
*
* This only retains the basic data without transferring the actual image.
* It is optionally possible to change the size of the result and set a
* background color.
*
* @throws ColorException
*/
public static function cloneEmpty(
GdImage $gd,
?SizeInterface $size = null,
ColorInterface $background = new Color(255, 255, 255, 0)
): GdImage {
// define size
$size = $size ?: new Rectangle(imagesx($gd), imagesy($gd));
// create new gd image with same size or new given size
$clone = imagecreatetruecolor($size->width(), $size->height());
// copy resolution to clone
$resolution = imageresolution($gd);
if (is_array($resolution) && array_key_exists(0, $resolution) && array_key_exists(1, $resolution)) {
imageresolution($clone, $resolution[0], $resolution[1]);
}
// fill with background
$processor = new ColorProcessor();
imagefill($clone, 0, 0, $processor->colorToNative($background));
imagealphablending($clone, true);
imagesavealpha($clone, true);
// set background image as transparent if alpha channel value if color is below .5
// comes into effect when the end format only supports binary transparency (like GIF)
if ($background->channel(Alpha::class)->value() < 128) {
imagecolortransparent($clone, $processor->colorToNative($background));
}
return $clone;
}
/**
* Create a clone of an GdImage that is positioned on the specified background color.
* Possible transparent areas are mixed with this color.
*
* @throws ColorException
*/
public static function cloneBlended(GdImage $gd, ColorInterface $background): GdImage
{
// create empty canvas with same size
$clone = static::cloneEmpty($gd, background: $background);
// transfer actual image to clone
imagecopy($clone, $gd, 0, 0, 0, 0, imagesx($gd), imagesy($gd));
return $clone;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/ColorProcessor.php | src/Drivers/Gd/ColorProcessor.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd;
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;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorProcessorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
class ColorProcessor implements ColorProcessorInterface
{
/**
* Create new color processor object
*
* @return void
*/
public function __construct(protected ColorspaceInterface $colorspace = new Colorspace())
{
//
}
/**
* {@inheritdoc}
*
* @see ColorProcessorInterface::colorToNative()
*/
public function colorToNative(ColorInterface $color): int
{
// convert color to colorspace
$color = $color->convertTo($this->colorspace);
// gd only supports rgb so the channels can be accessed directly
$r = $color->channel(Red::class)->value();
$g = $color->channel(Green::class)->value();
$b = $color->channel(Blue::class)->value();
$a = $color->channel(Alpha::class)->value();
// convert alpha value to gd alpha
// ([opaque]255-0[transparent]) to ([opaque]0-127[transparent])
$a = (int) $this->convertRange($a, 0, 255, 127, 0);
return ($a << 24) + ($r << 16) + ($g << 8) + $b;
}
/**
* {@inheritdoc}
*
* @see ColorProcessorInterface::nativeToColor()
*/
public function nativeToColor(mixed $value): ColorInterface
{
if (!is_int($value) && !is_array($value)) {
throw new ColorException('GD driver can only decode colors in integer and array format.');
}
if (is_array($value)) {
// array conversion
if (!$this->isValidArrayColor($value)) {
throw new ColorException(
'GD driver can only decode array color format array{red: int, green: int, blue: int, alpha: int}.',
);
}
$r = $value['red'];
$g = $value['green'];
$b = $value['blue'];
$a = $value['alpha'];
} else {
// integer conversion
$a = ($value >> 24) & 0xFF;
$r = ($value >> 16) & 0xFF;
$g = ($value >> 8) & 0xFF;
$b = $value & 0xFF;
}
// convert gd apha integer to intervention alpha integer
// ([opaque]0-127[transparent]) to ([opaque]255-0[transparent])
$a = (int) static::convertRange($a, 127, 0, 0, 255);
return new Color($r, $g, $b, $a);
}
/**
* Convert input in range (min) to (max) to the corresponding value
* in target range (targetMin) to (targetMax).
*/
protected function convertRange(
float|int $input,
float|int $min,
float|int $max,
float|int $targetMin,
float|int $targetMax
): float|int {
return ceil(((($input - $min) * ($targetMax - $targetMin)) / ($max - $min)) + $targetMin);
}
/**
* Check if given array is valid color format
* array{red: int, green: int, blue: int, alpha: int}
* i.e. result of imagecolorsforindex()
*
* @param array<mixed> $color
*/
private function isValidArrayColor(array $color): bool
{
if (!array_key_exists('red', $color)) {
return false;
}
if (!array_key_exists('green', $color)) {
return false;
}
if (!array_key_exists('blue', $color)) {
return false;
}
if (!array_key_exists('alpha', $color)) {
return false;
}
if (!is_int($color['red'])) {
return false;
}
if (!is_int($color['green'])) {
return false;
}
if (!is_int($color['blue'])) {
return false;
}
if (!is_int($color['alpha'])) {
return false;
}
return true;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Driver.php | src/Drivers/Gd/Driver.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd;
use Intervention\Image\Drivers\AbstractDriver;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Format;
use Intervention\Image\FileExtension;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorProcessorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
use Intervention\Image\Interfaces\DriverInterface;
use Intervention\Image\Interfaces\FontProcessorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\MediaType;
class Driver extends AbstractDriver
{
/**
* {@inheritdoc}
*
* @see DriverInterface::id()
*/
public function id(): string
{
return 'GD';
}
/**
* {@inheritdoc}
*
* @see DriverInterface::checkHealth()
*
* @codeCoverageIgnore
*/
public function checkHealth(): void
{
if (!extension_loaded('gd') || !function_exists('gd_info')) {
throw new DriverException(
'GD PHP extension must be installed to use this driver.'
);
}
}
/**
* {@inheritdoc}
*
* @see DriverInterface::createImage()
*/
public function createImage(int $width, int $height): ImageInterface
{
// build new transparent GDImage
$data = imagecreatetruecolor($width, $height);
imagesavealpha($data, true);
$background = imagecolorallocatealpha($data, 255, 255, 255, 127);
imagealphablending($data, false);
imagefill($data, 0, 0, $background);
imagecolortransparent($data, $background);
return new Image(
$this,
new Core([
new Frame($data)
])
);
}
/**
* {@inheritdoc}
*
* @see DriverInterface::createAnimation()
*
* @throws RuntimeException
*/
public function createAnimation(callable $init): ImageInterface
{
$animation = new class ($this)
{
public function __construct(
protected DriverInterface $driver,
public Core $core = new Core()
) {
//
}
/**
* @throws RuntimeException
*/
public function add(mixed $source, float $delay = 1): self
{
$this->core->add(
$this->driver->handleInput($source)->core()->first()->setDelay($delay)
);
return $this;
}
/**
* @throws RuntimeException
*/
public function __invoke(): ImageInterface
{
return new Image(
$this->driver,
$this->core
);
}
};
$init($animation);
return call_user_func($animation);
}
/**
* {@inheritdoc}
*
* @see DriverInterface::colorProcessor()
*/
public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface
{
return new ColorProcessor($colorspace);
}
/**
* {@inheritdoc}
*
* @see DriverInterface::fontProcessor()
*/
public function fontProcessor(): FontProcessorInterface
{
return new FontProcessor();
}
/**
* {@inheritdoc}
*
* @see DriverInterface::supports()
*/
public function supports(string|Format|FileExtension|MediaType $identifier): bool
{
return match (Format::tryCreate($identifier)) {
Format::JPEG => boolval(imagetypes() & IMG_JPEG),
Format::WEBP => boolval(imagetypes() & IMG_WEBP),
Format::GIF => boolval(imagetypes() & IMG_GIF),
Format::PNG => boolval(imagetypes() & IMG_PNG),
Format::AVIF => boolval(imagetypes() & IMG_AVIF),
Format::BMP => boolval(imagetypes() & IMG_BMP),
default => false,
};
}
/**
* Return version of GD library
*/
public static function version(): string
{
return gd_info()['GD Version'];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Encoders/BmpEncoder.php | src/Drivers/Gd/Encoders/BmpEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Encoders;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\BmpEncoder as GenericBmpEncoder;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class BmpEncoder extends GenericBmpEncoder implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage
{
return $this->createEncodedImage(function ($pointer) use ($image): void {
imagebmp($image->core()->native(), $pointer, false);
}, 'image/bmp');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Encoders/PngEncoder.php | src/Drivers/Gd/Encoders/PngEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Encoders;
use GdImage;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\PngEncoder as GenericPngEncoder;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class PngEncoder extends GenericPngEncoder implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage
{
$output = $this->prepareOutput($image);
return $this->createEncodedImage(function ($pointer) use ($output): void {
imageinterlace($output, $this->interlaced);
imagepng($output, $pointer, -1);
}, 'image/png');
}
/**
* Prepare given image instance for PNG format output according to encoder settings
*
* @throws RuntimeException
* @throws ColorException
* @throws AnimationException
*/
private function prepareOutput(ImageInterface $image): GdImage
{
if ($this->indexed) {
$output = clone $image;
$output->reduceColors(255);
return $output->core()->native();
}
return Cloner::clone($image->core()->native());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Encoders/JpegEncoder.php | src/Drivers/Gd/Encoders/JpegEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Encoders;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Encoders\JpegEncoder as GenericJpegEncoder;
use Intervention\Image\EncodedImage;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class JpegEncoder extends GenericJpegEncoder implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage
{
$blendingColor = $this->driver()->handleInput(
$this->driver()->config()->blendingColor
);
$output = Cloner::cloneBlended(
$image->core()->native(),
background: $blendingColor
);
return $this->createEncodedImage(function ($pointer) use ($output): void {
imageinterlace($output, $this->progressive);
imagejpeg($output, $pointer, $this->quality);
}, 'image/jpeg');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Encoders/AvifEncoder.php | src/Drivers/Gd/Encoders/AvifEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Encoders;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\AvifEncoder as GenericAvifEncoder;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class AvifEncoder extends GenericAvifEncoder implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage
{
return $this->createEncodedImage(function ($pointer) use ($image): void {
imageavif($image->core()->native(), $pointer, $this->quality);
}, 'image/avif');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Encoders/GifEncoder.php | src/Drivers/Gd/Encoders/GifEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Encoders;
use Exception;
use Intervention\Gif\Builder as GifBuilder;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\GifEncoder as GenericGifEncoder;
use Intervention\Image\Exceptions\EncoderException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class GifEncoder extends GenericGifEncoder implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage
{
if ($image->isAnimated()) {
return $this->encodeAnimated($image);
}
$gd = Cloner::clone($image->core()->native());
return $this->createEncodedImage(function ($pointer) use ($gd): void {
imageinterlace($gd, $this->interlaced);
imagegif($gd, $pointer);
}, 'image/gif');
}
/**
* @throws RuntimeException
*/
protected function encodeAnimated(ImageInterface $image): EncodedImage
{
try {
$builder = GifBuilder::canvas(
$image->width(),
$image->height()
);
foreach ($image as $frame) {
$builder->addFrame(
source: $this->encode($frame->toImage($image->driver()))->toFilePointer(),
delay: $frame->delay(),
interlaced: $this->interlaced
);
}
$builder->setLoops($image->loops());
return new EncodedImage($builder->encode(), 'image/gif');
} catch (Exception $e) {
throw new EncoderException($e->getMessage(), $e->getCode(), $e);
}
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Encoders/WebpEncoder.php | src/Drivers/Gd/Encoders/WebpEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Encoders;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\WebpEncoder as GenericWebpEncoder;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class WebpEncoder extends GenericWebpEncoder implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage
{
$quality = $this->quality === 100 && defined('IMG_WEBP_LOSSLESS') ? IMG_WEBP_LOSSLESS : $this->quality;
return $this->createEncodedImage(function ($pointer) use ($image, $quality): void {
imagewebp($image->core()->native(), $pointer, $quality);
}, 'image/webp');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/DataUriImageDecoder.php | src/Drivers/Gd/Decoders/DataUriImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
$uri = $this->parseDataUri($input);
if (!$uri->isValid()) {
throw new DecoderException('Unable to decode input');
}
if ($uri->isBase64Encoded()) {
return parent::decode(base64_decode($uri->data()));
}
return parent::decode(urldecode($uri->data()));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/FilePointerImageDecoder.php | src/Drivers/Gd/Decoders/FilePointerImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class FilePointerImageDecoder extends BinaryImageDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_resource($input) || !in_array(get_resource_type($input), ['file', 'stream'])) {
throw new DecoderException('Unable to decode input');
}
$contents = '';
@rewind($input);
while (!feof($input)) {
$contents .= fread($input, 1024);
}
return parent::decode($contents);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/BinaryImageDecoder.php | src/Drivers/Gd/Decoders/BinaryImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Format;
use Intervention\Image\Modifiers\AlignRotationModifier;
class BinaryImageDecoder extends NativeObjectDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
return match ($this->isGifFormat($input)) {
true => $this->decodeGif($input),
default => $this->decodeBinary($input),
};
}
/**
* Decode image from given binary data
*
* @throws RuntimeException
*/
private function decodeBinary(string $input): ImageInterface
{
$gd = @imagecreatefromstring($input);
if ($gd === false) {
throw new DecoderException('Unable to decode input');
}
// create image instance
$image = parent::decode($gd);
// get media type
$mediaType = $this->getMediaTypeByBinary($input);
// extract & set exif data for appropriate formats
if (in_array($mediaType->format(), [Format::JPEG, Format::TIFF])) {
$image->setExif($this->extractExifData($input));
}
// set mediaType on origin
$image->origin()->setMediaType($mediaType);
// adjust image orientation
if ($this->driver()->config()->autoOrientation) {
$image->modify(new AlignRotationModifier());
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/FilePathImageDecoder.php | src/Drivers/Gd/Decoders/FilePathImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Format;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Modifiers\AlignRotationModifier;
class FilePathImageDecoder extends NativeObjectDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!$this->isFile($input)) {
throw new DecoderException('Unable to decode input');
}
// detect media (mime) type
$mediaType = $this->getMediaTypeByFilePath($input);
$image = match ($mediaType->format()) {
// gif files might be animated and therefore cannot
// be handled by the standard GD decoder.
Format::GIF => $this->decodeGif($input),
default => parent::decode(match ($mediaType->format()) {
Format::JPEG => @imagecreatefromjpeg($input),
Format::WEBP => @imagecreatefromwebp($input),
Format::PNG => @imagecreatefrompng($input),
Format::AVIF => @imagecreatefromavif($input),
Format::BMP => @imagecreatefrombmp($input),
default => throw new DecoderException('Unable to decode input'),
}),
};
// set file path & mediaType on origin
$image->origin()->setFilePath($input);
$image->origin()->setMediaType($mediaType);
// extract exif for the appropriate formats
if ($mediaType->format() === Format::JPEG) {
$image->setExif($this->extractExifData($input));
}
// adjust image orientation
if ($this->driver()->config()->autoOrientation) {
$image->modify(new AlignRotationModifier());
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php | src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use SplFileInfo;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class SplFileInfoImageDecoder extends FilePathImageDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_a($input, SplFileInfo::class)) {
throw new DecoderException('Unable to decode input');
}
return parent::decode($input->getRealPath());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php | src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\EncodedImage;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ColorInterface;
class EncodedImageObjectDecoder extends BinaryImageDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_a($input, EncodedImage::class)) {
throw new DecoderException('Unable to decode input');
}
return parent::decode($input->toString());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/Base64ImageDecoder.php | src/Drivers/Gd/Decoders/Base64ImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!$this->isValidBase64($input)) {
throw new DecoderException('Unable to decode input');
}
return parent::decode(base64_decode((string) $input));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/NativeObjectDecoder.php | src/Drivers/Gd/Decoders/NativeObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Exception;
use GdImage;
use Intervention\Gif\Decoder as GifDecoder;
use Intervention\Gif\Splitter as GifSplitter;
use Intervention\Image\Drivers\Gd\Core;
use Intervention\Image\Drivers\Gd\Frame;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class NativeObjectDecoder extends AbstractDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_object($input)) {
throw new DecoderException('Unable to decode input');
}
if (!($input instanceof GdImage)) {
throw new DecoderException('Unable to decode input');
}
if (!imageistruecolor($input)) {
imagepalettetotruecolor($input);
}
imagesavealpha($input, true);
// build image instance
return new Image(
$this->driver(),
new Core([
new Frame($input)
])
);
}
/**
* Decode image from given GIF source which can be either a file path or binary data
*
* Depending on the configuration, this is taken over by the native GD function
* or, if animations are required, by our own extended decoder.
*
* @throws RuntimeException
*/
protected function decodeGif(mixed $input): ImageInterface
{
// create non-animated image depending on config
if (!$this->driver()->config()->decodeAnimation) {
$native = match (true) {
$this->isGifFormat($input) => @imagecreatefromstring($input),
default => @imagecreatefromgif($input),
};
if ($native === false) {
throw new DecoderException('Unable to decode input.');
}
$image = self::decode($native);
$image->origin()->setMediaType('image/gif');
return $image;
}
try {
// create empty core
$core = new Core();
$gif = GifDecoder::decode($input);
$splitter = GifSplitter::create($gif)->split();
$delays = $splitter->getDelays();
// set loops on core
if ($loops = $gif->getMainApplicationExtension()?->getLoops()) {
$core->setLoops($loops);
}
// add GDImage instances to core
foreach ($splitter->coalesceToResources() as $key => $native) {
$core->push(
new Frame($native, $delays[$key] / 100)
);
}
} catch (Exception $e) {
throw new DecoderException($e->getMessage(), $e->getCode(), $e);
}
// create (possibly) animated image
$image = new Image($this->driver(), $core);
// set media type
$image->origin()->setMediaType('image/gif');
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Decoders/AbstractDecoder.php | src/Drivers/Gd/Decoders/AbstractDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\Drivers\SpecializableDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\MediaType;
use ValueError;
abstract class AbstractDecoder extends SpecializableDecoder implements SpecializedInterface
{
/**
* Return media (mime) type of the file at given file path
*
* @throws DecoderException
* @throws NotSupportedException
*/
protected function getMediaTypeByFilePath(string $filepath): MediaType
{
$info = @getimagesize($filepath);
if (!is_array($info)) {
throw new DecoderException('Unable to detect media (MIME) from data in file path.');
}
try {
return MediaType::from($info['mime']);
} catch (ValueError) {
throw new NotSupportedException('Unsupported media type (MIME) ' . $info['mime'] . '.');
}
}
/**
* Return media (mime) type of the given image data
*
* @throws DecoderException
* @throws NotSupportedException
*/
protected function getMediaTypeByBinary(string $data): MediaType
{
$info = @getimagesizefromstring($data);
if (!is_array($info)) {
throw new DecoderException('Unable to detect media (MIME) from binary data.');
}
try {
return MediaType::from($info['mime']);
} catch (ValueError) {
throw new NotSupportedException('Unsupported media type (MIME) ' . $info['mime'] . '.');
}
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Analyzers/ColorspaceAnalyzer.php | src/Drivers/Gd/Analyzers/ColorspaceAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Analyzers;
use Intervention\Image\Analyzers\ColorspaceAnalyzer as GenericColorspaceAnalyzer;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class ColorspaceAnalyzer extends GenericColorspaceAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return new Colorspace();
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Analyzers/HeightAnalyzer.php | src/Drivers/Gd/Analyzers/HeightAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Analyzers;
use Intervention\Image\Analyzers\HeightAnalyzer as GenericHeightAnalyzer;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class HeightAnalyzer extends GenericHeightAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return imagesy($image->core()->native());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Analyzers/PixelColorsAnalyzer.php | src/Drivers/Gd/Analyzers/PixelColorsAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Analyzers;
use Intervention\Image\Collection;
use Intervention\Image\Interfaces\ImageInterface;
class PixelColorsAnalyzer extends PixelColorAnalyzer
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
$colors = new Collection();
$colorspace = $image->colorspace();
foreach ($image as $frame) {
$colors->push(
parent::colorAt($colorspace, $frame->native())
);
}
return $colors;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Analyzers/WidthAnalyzer.php | src/Drivers/Gd/Analyzers/WidthAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Analyzers;
use Intervention\Image\Analyzers\WidthAnalyzer as GenericWidthAnalyzer;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class WidthAnalyzer extends GenericWidthAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return imagesx($image->core()->native());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Analyzers/ResolutionAnalyzer.php | src/Drivers/Gd/Analyzers/ResolutionAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Analyzers;
use Intervention\Image\Analyzers\ResolutionAnalyzer as GenericResolutionAnalyzer;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Resolution;
class ResolutionAnalyzer extends GenericResolutionAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return new Resolution(...imageresolution($image->core()->native()));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php | src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Analyzers;
use GdImage;
use Intervention\Image\Analyzers\PixelColorAnalyzer as GenericPixelColorAnalyzer;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class PixelColorAnalyzer extends GenericPixelColorAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return $this->colorAt(
$image->colorspace(),
$image->core()->frame($this->frame_key)->native()
);
}
/**
* @throws GeometryException
* @throws ColorException
*/
protected function colorAt(ColorspaceInterface $colorspace, GdImage $gd): ColorInterface
{
$index = @imagecolorat($gd, $this->x, $this->y);
if (!imageistruecolor($gd)) {
$index = imagecolorsforindex($gd, $index);
}
if ($index === false) {
throw new GeometryException(
'The specified position is not in the valid image area.'
);
}
return $this->driver()->colorProcessor($colorspace)->nativeToColor($index);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/BlendTransparencyModifier.php | src/Drivers/Gd/Modifiers/BlendTransparencyModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\BlendTransparencyModifier as GenericBlendTransparencyModifier;
class BlendTransparencyModifier extends GenericBlendTransparencyModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$blendingColor = $this->blendingColor($this->driver());
foreach ($image as $frame) {
// create new canvas with blending color as background
$modified = Cloner::cloneBlended(
$frame->native(),
background: $blendingColor
);
// set new gd image
$frame->setNative($modified);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifier.php | src/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ResizeCanvasRelativeModifier extends ResizeCanvasModifier
{
protected function cropSize(ImageInterface $image, bool $relative = false): SizeInterface
{
return parent::cropSize($image, true);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/DrawPixelModifier.php | src/Drivers/Gd/Modifiers/DrawPixelModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawPixelModifier as GenericDrawPixelModifier;
class DrawPixelModifier extends GenericDrawPixelModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->color)
);
foreach ($image as $frame) {
imagealphablending($frame->native(), true);
imagesetpixel(
$frame->native(),
$this->position->x(),
$this->position->y(),
$color
);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/TextModifier.php | src/Drivers/Gd/Modifiers/TextModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\TextModifier as GenericTextModifier;
class TextModifier extends GenericTextModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$fontProcessor = $this->driver()->fontProcessor();
$lines = $fontProcessor->textBlock($this->text, $this->font, $this->position);
// decode text colors
$textColor = $this->gdTextColor($image);
$strokeColor = $this->gdStrokeColor($image);
// build full path to font file to make sure to pass absolute path to imageftbbox()
// because of issues with different GD version behaving differently when passing
// relative paths to imagettftext()
$fontPath = $this->font->hasFilename() ? realpath($this->font->filename()) : false;
if ($this->font->hasFilename() && $fontPath === false) {
throw new FontException('Font file ' . $this->font->filename() . ' does not exist.');
}
foreach ($image as $frame) {
imagealphablending($frame->native(), true);
if ($this->font->hasFilename()) {
foreach ($lines as $line) {
foreach ($this->strokeOffsets($this->font) as $offset) {
imagettftext(
image: $frame->native(),
size: $fontProcessor->nativeFontSize($this->font),
angle: $this->font->angle() * -1,
x: $line->position()->x() + $offset->x(),
y: $line->position()->y() + $offset->y(),
color: $strokeColor,
font_filename: $fontPath,
text: (string) $line
);
}
imagettftext(
image: $frame->native(),
size: $fontProcessor->nativeFontSize($this->font),
angle: $this->font->angle() * -1,
x: $line->position()->x(),
y: $line->position()->y(),
color: $textColor,
font_filename: $fontPath,
text: (string) $line
);
}
} else {
foreach ($lines as $line) {
foreach ($this->strokeOffsets($this->font) as $offset) {
imagestring(
$frame->native(),
$this->gdFont(),
$line->position()->x() + $offset->x(),
$line->position()->y() + $offset->y(),
(string) $line,
$strokeColor
);
}
imagestring(
$frame->native(),
$this->gdFont(),
$line->position()->x(),
$line->position()->y(),
(string) $line,
$textColor
);
}
}
}
return $image;
}
/**
* Decode text color in GD compatible format
*
* @throws RuntimeException
* @throws ColorException
*/
protected function gdTextColor(ImageInterface $image): int
{
return $this
->driver()
->colorProcessor($image->colorspace())
->colorToNative(parent::textColor());
}
/**
* Decode color for stroke (outline) effect in GD compatible format
*
* @throws RuntimeException
* @throws ColorException
*/
protected function gdStrokeColor(ImageInterface $image): int
{
if (!$this->font->hasStrokeEffect()) {
return 0;
}
$color = parent::strokeColor();
if ($color->isTransparent()) {
throw new ColorException(
'The stroke color must be fully opaque.'
);
}
return $this
->driver()
->colorProcessor($image->colorspace())
->colorToNative($color);
}
/**
* Return GD's internal font size (if no ttf file is set)
*/
private function gdFont(): int
{
if (is_numeric($this->font->filename())) {
return intval($this->font->filename());
}
return 1;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/ResizeModifier.php | src/Drivers/Gd/Modifiers/ResizeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ResizeModifier as GenericResizeModifier;
class ResizeModifier extends GenericResizeModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$resizeTo = $this->getAdjustedSize($image);
foreach ($image as $frame) {
$this->resizeFrame($frame, $resizeTo);
}
return $image;
}
/**
* @throws ColorException
*/
private function resizeFrame(FrameInterface $frame, SizeInterface $resizeTo): void
{
// create empty canvas in target size
$modified = Cloner::cloneEmpty($frame->native(), $resizeTo);
// copy content from resource
imagecopyresampled(
$modified,
$frame->native(),
$resizeTo->pivot()->x(),
$resizeTo->pivot()->y(),
0,
0,
$resizeTo->width(),
$resizeTo->height(),
$frame->size()->width(),
$frame->size()->height()
);
// set new content as resource
$frame->setNative($modified);
}
/**
* Return the size the modifier will resize to
*
* @throws RuntimeException
* @throws GeometryException
*/
protected function getAdjustedSize(ImageInterface $image): SizeInterface
{
return $image->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/Drivers/Gd/Modifiers/DrawBezierModifier.php | src/Drivers/Gd/Modifiers/DrawBezierModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use RuntimeException;
use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawBezierModifier as GenericDrawBezierModifier;
class DrawBezierModifier extends GenericDrawBezierModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*
* @throws RuntimeException
* @throws GeometryException
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
if ($this->drawable->count() !== 3 && $this->drawable->count() !== 4) {
throw new GeometryException('You must specify either 3 or 4 points to create a bezier curve');
}
[$polygon, $polygon_border_segments] = $this->calculateBezierPoints();
if ($this->drawable->hasBackgroundColor() || $this->drawable->hasBorder()) {
imagealphablending($frame->native(), true);
imageantialias($frame->native(), true);
}
if ($this->drawable->hasBackgroundColor()) {
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
imagesetthickness($frame->native(), 0);
imagefilledpolygon(
$frame->native(),
$polygon,
$background_color
);
}
if ($this->drawable->hasBorder() && $this->drawable->borderSize() > 0) {
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
if ($this->drawable->borderSize() === 1) {
imagesetthickness($frame->native(), $this->drawable->borderSize());
$count = count($polygon);
for ($i = 0; $i < $count; $i += 2) {
if (array_key_exists($i + 2, $polygon) && array_key_exists($i + 3, $polygon)) {
imageline(
$frame->native(),
$polygon[$i],
$polygon[$i + 1],
$polygon[$i + 2],
$polygon[$i + 3],
$border_color
);
}
}
} else {
$polygon_border_segments_total = count($polygon_border_segments);
for ($i = 0; $i < $polygon_border_segments_total; $i += 1) {
imagefilledpolygon(
$frame->native(),
$polygon_border_segments[$i],
$border_color
);
}
}
}
}
return $image;
}
/**
* Calculate interpolation points for quadratic beziers using the Bernstein polynomial form
*
* @return array{'x': float, 'y': float}
*/
private function calculateQuadraticBezierInterpolationPoint(float $t = 0.05): array
{
$remainder = 1 - $t;
$control_point_1_multiplier = $remainder * $remainder;
$control_point_2_multiplier = $remainder * $t * 2;
$control_point_3_multiplier = $t * $t;
$x = (
$this->drawable->first()->x() * $control_point_1_multiplier +
$this->drawable->second()->x() * $control_point_2_multiplier +
$this->drawable->last()->x() * $control_point_3_multiplier
);
$y = (
$this->drawable->first()->y() * $control_point_1_multiplier +
$this->drawable->second()->y() * $control_point_2_multiplier +
$this->drawable->last()->y() * $control_point_3_multiplier
);
return ['x' => $x, 'y' => $y];
}
/**
* Calculate interpolation points for cubic beziers using the Bernstein polynomial form
*
* @return array{'x': float, 'y': float}
*/
private function calculateCubicBezierInterpolationPoint(float $t = 0.05): array
{
$remainder = 1 - $t;
$t_squared = $t * $t;
$remainder_squared = $remainder * $remainder;
$control_point_1_multiplier = $remainder_squared * $remainder;
$control_point_2_multiplier = $remainder_squared * $t * 3;
$control_point_3_multiplier = $t_squared * $remainder * 3;
$control_point_4_multiplier = $t_squared * $t;
$x = (
$this->drawable->first()->x() * $control_point_1_multiplier +
$this->drawable->second()->x() * $control_point_2_multiplier +
$this->drawable->third()->x() * $control_point_3_multiplier +
$this->drawable->last()->x() * $control_point_4_multiplier
);
$y = (
$this->drawable->first()->y() * $control_point_1_multiplier +
$this->drawable->second()->y() * $control_point_2_multiplier +
$this->drawable->third()->y() * $control_point_3_multiplier +
$this->drawable->last()->y() * $control_point_4_multiplier
);
return ['x' => $x, 'y' => $y];
}
/**
* Calculate the points needed to draw a quadratic or cubic bezier with optional border/stroke
*
* @throws GeometryException
* @return array{0: array<mixed>, 1: array<mixed>}
*/
private function calculateBezierPoints(): array
{
if ($this->drawable->count() !== 3 && $this->drawable->count() !== 4) {
throw new GeometryException('You must specify either 3 or 4 points to create a bezier curve');
}
$polygon = [];
$inner_polygon = [];
$outer_polygon = [];
$polygon_border_segments = [];
// define ratio t; equivalent to 5 percent distance along edge
$t = 0.05;
$polygon[] = $this->drawable->first()->x();
$polygon[] = $this->drawable->first()->y();
for ($i = $t; $i < 1; $i += $t) {
if ($this->drawable->count() === 3) {
$ip = $this->calculateQuadraticBezierInterpolationPoint($i);
} elseif ($this->drawable->count() === 4) {
$ip = $this->calculateCubicBezierInterpolationPoint($i);
}
$polygon[] = (int) $ip['x'];
$polygon[] = (int) $ip['y'];
}
$polygon[] = $this->drawable->last()->x();
$polygon[] = $this->drawable->last()->y();
if ($this->drawable->hasBorder() && $this->drawable->borderSize() > 1) {
// create the border/stroke effect by calculating two new curves with offset positions
// from the main polygon and then connecting the inner/outer curves to create separate
// 4-point polygon segments
$polygon_total_points = count($polygon);
$offset = ($this->drawable->borderSize() / 2);
for ($i = 0; $i < $polygon_total_points; $i += 2) {
if (array_key_exists($i + 2, $polygon) && array_key_exists($i + 3, $polygon)) {
$dx = $polygon[$i + 2] - $polygon[$i];
$dy = $polygon[$i + 3] - $polygon[$i + 1];
$dxy_sqrt = ($dx * $dx + $dy * $dy) ** 0.5;
// inner polygon
$scale = $offset / $dxy_sqrt;
$ox = -$dy * $scale;
$oy = $dx * $scale;
$inner_polygon[] = $ox + $polygon[$i];
$inner_polygon[] = $oy + $polygon[$i + 1];
$inner_polygon[] = $ox + $polygon[$i + 2];
$inner_polygon[] = $oy + $polygon[$i + 3];
// outer polygon
$scale = -$offset / $dxy_sqrt;
$ox = -$dy * $scale;
$oy = $dx * $scale;
$outer_polygon[] = $ox + $polygon[$i];
$outer_polygon[] = $oy + $polygon[$i + 1];
$outer_polygon[] = $ox + $polygon[$i + 2];
$outer_polygon[] = $oy + $polygon[$i + 3];
}
}
$inner_polygon_total_points = count($inner_polygon);
for ($i = 0; $i < $inner_polygon_total_points; $i += 2) {
if (array_key_exists($i + 2, $inner_polygon) && array_key_exists($i + 3, $inner_polygon)) {
$polygon_border_segments[] = [
$inner_polygon[$i],
$inner_polygon[$i + 1],
$outer_polygon[$i],
$outer_polygon[$i + 1],
$outer_polygon[$i + 2],
$outer_polygon[$i + 3],
$inner_polygon[$i + 2],
$inner_polygon[$i + 3],
];
}
}
}
return [$polygon, $polygon_border_segments];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/RotateModifier.php | src/Drivers/Gd/Modifiers/RotateModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\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\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\RotateModifier as GenericRotateModifier;
class RotateModifier extends GenericRotateModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$background = $this->driver()->handleInput($this->background);
foreach ($image as $frame) {
$this->modifyFrame($frame, $background);
}
return $image;
}
/**
* Apply rotation modification on given frame, given background
* color is used for newly create image areas
*
* @throws ColorException
*/
protected function modifyFrame(FrameInterface $frame, ColorInterface $background): void
{
// get transparent color from frame core
$transparent = match ($transparent = imagecolortransparent($frame->native())) {
-1 => imagecolorallocatealpha(
$frame->native(),
$background->channel(Red::class)->value(),
$background->channel(Green::class)->value(),
$background->channel(Blue::class)->value(),
127
),
default => $transparent,
};
// rotate original image against transparent background
$rotated = imagerotate(
$frame->native(),
$this->rotationAngle(),
$transparent
);
// create size from original after rotation
$container = (new Rectangle(
imagesx($rotated),
imagesy($rotated),
))->movePivot('center');
// create size from original and rotate points
$cutout = (new Rectangle(
imagesx($frame->native()),
imagesy($frame->native()),
$container->pivot()
))->align('center')
->valign('center')
->rotate($this->rotationAngle() * -1);
// create new gd image
$modified = Cloner::cloneEmpty($frame->native(), $container, $background);
// draw the cutout on new gd image to have a transparent
// background where the rotated image will be placed
imagealphablending($modified, false);
imagefilledpolygon(
$modified,
$cutout->toArray(),
imagecolortransparent($modified)
);
// place rotated image on new gd image
imagealphablending($modified, true);
imagecopy(
$modified,
$rotated,
0,
0,
0,
0,
imagesx($rotated),
imagesy($rotated)
);
$frame->setNative($modified);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/PadModifier.php | src/Drivers/Gd/Modifiers/PadModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\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/Drivers/Gd/Modifiers/CropModifier.php | src/Drivers/Gd/Modifiers/CropModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\CropModifier as GenericCropModifier;
class CropModifier extends GenericCropModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$originalSize = $image->size();
$crop = $this->crop($image);
$background = $this->driver()->handleInput($this->background);
foreach ($image as $frame) {
$this->cropFrame($frame, $originalSize, $crop, $background);
}
return $image;
}
/**
* @throws ColorException
*/
protected function cropFrame(
FrameInterface $frame,
SizeInterface $originalSize,
SizeInterface $resizeTo,
ColorInterface $background
): void {
// create new image with transparent background
$modified = Cloner::cloneEmpty($frame->native(), $resizeTo, $background);
// define offset
$offset_x = $resizeTo->pivot()->x() + $this->offset_x;
$offset_y = $resizeTo->pivot()->y() + $this->offset_y;
// define target width & height
$targetWidth = min($resizeTo->width(), $originalSize->width());
$targetHeight = min($resizeTo->height(), $originalSize->height());
$targetWidth = $targetWidth < $originalSize->width() ? $targetWidth + $offset_x : $targetWidth;
$targetHeight = $targetHeight < $originalSize->height() ? $targetHeight + $offset_y : $targetHeight;
// don't alpha blend for copy operation to keep transparent areas of original image
imagealphablending($modified, false);
// copy content from resource
imagecopyresampled(
$modified,
$frame->native(),
$offset_x * -1,
$offset_y * -1,
0,
0,
$targetWidth,
$targetHeight,
$targetWidth,
$targetHeight
);
// set new content as resource
$frame->setNative($modified);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/FillModifier.php | src/Drivers/Gd/Modifiers/FillModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\FillModifier as GenericFillModifier;
class FillModifier extends GenericFillModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->color($image);
foreach ($image as $frame) {
if ($this->hasPosition()) {
$this->floodFillWithColor($frame, $color);
} else {
$this->fillAllWithColor($frame, $color);
}
}
return $image;
}
/**
* @throws RuntimeException
*/
private function color(ImageInterface $image): int
{
return $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->color)
);
}
private function floodFillWithColor(FrameInterface $frame, int $color): void
{
imagefill(
$frame->native(),
$this->position->x(),
$this->position->y(),
$color
);
}
private function fillAllWithColor(FrameInterface $frame, int $color): void
{
imagealphablending($frame->native(), true);
imagefilledrectangle(
$frame->native(),
0,
0,
$frame->size()->width() - 1,
$frame->size()->height() - 1,
$color
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/ColorizeModifier.php | src/Drivers/Gd/Modifiers/ColorizeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ColorizeModifier as GenericColorizeModifier;
class ColorizeModifier extends GenericColorizeModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
// normalize colorize levels
$red = (int) round($this->red * 2.55);
$green = (int) round($this->green * 2.55);
$blue = (int) round($this->blue * 2.55);
foreach ($image as $frame) {
imagefilter($frame->native(), IMG_FILTER_COLORIZE, $red, $green, $blue);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/ColorspaceModifier.php | src/Drivers/Gd/Modifiers/ColorspaceModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ColorspaceModifier as GenericColorspaceModifier;
class ColorspaceModifier extends GenericColorspaceModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
if (!($this->targetColorspace() instanceof RgbColorspace)) {
throw new NotSupportedException(
'Only RGB colorspace is supported by GD driver.'
);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/FlopModifier.php | src/Drivers/Gd/Modifiers/FlopModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\FlopModifier as GenericFlopModifier;
class FlopModifier extends GenericFlopModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imageflip($frame->native(), IMG_FLIP_HORIZONTAL);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/PixelateModifier.php | src/Drivers/Gd/Modifiers/PixelateModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\PixelateModifier as GenericPixelateModifier;
class PixelateModifier extends GenericPixelateModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagefilter($frame->native(), IMG_FILTER_PIXELATE, $this->size, true);
}
return $image;
}
}
| 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.