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/Drivers/Gd/Modifiers/TrimModifier.php | src/Drivers/Gd/Modifiers/TrimModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\TrimModifier as GenericTrimModifier;
class TrimModifier extends GenericTrimModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
if ($image->isAnimated()) {
throw new NotSupportedException('Trim modifier cannot be applied to animated images.');
}
// apply tolerance with a min. value of .5 because the default tolerance of '0' should
// already trim away similar colors which is not the case with imagecropauto.
$trimmed = imagecropauto(
$image->core()->native(),
IMG_CROP_THRESHOLD,
max([.5, $this->tolerance / 10]),
$this->trimColor($image)
);
// if the tolerance is very high, it is possible that no image is left.
// imagick returns a 1x1 pixel image in this case. this does the same.
if ($trimmed === false) {
$trimmed = $this->driver()->createImage(1, 1)->core()->native();
}
$image->core()->setNative($trimmed);
return $image;
}
/**
* Create an average color from the colors of the four corner points of the given image
*
* @throws RuntimeException
* @throws AnimationException
*/
private function trimColor(ImageInterface $image): int
{
// trim color base
$red = 0;
$green = 0;
$blue = 0;
// corner coordinates
$size = $image->size();
$cornerPoints = [
new Point(0, 0),
new Point($size->width() - 1, 0),
new Point(0, $size->height() - 1),
new Point($size->width() - 1, $size->height() - 1),
];
// create an average color to be used in trim operation
foreach ($cornerPoints as $pos) {
$cornerColor = imagecolorat($image->core()->native(), $pos->x(), $pos->y());
$rgb = imagecolorsforindex($image->core()->native(), $cornerColor);
$red += round(round(($rgb['red'] / 51)) * 51);
$green += round(round(($rgb['green'] / 51)) * 51);
$blue += round(round(($rgb['blue'] / 51)) * 51);
}
$red = (int) round($red / 4);
$green = (int) round($green / 4);
$blue = (int) round($blue / 4);
return imagecolorallocate($image->core()->native(), $red, $green, $blue);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/InvertModifier.php | src/Drivers/Gd/Modifiers/InvertModifier.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\InvertModifier as GenericInvertModifier;
class InvertModifier extends GenericInvertModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagefilter($frame->native(), IMG_FILTER_NEGATE);
}
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/DrawRectangleModifier.php | src/Drivers/Gd/Modifiers/DrawRectangleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawRectangleModifier as GenericDrawRectangleModifier;
class DrawRectangleModifier extends GenericDrawRectangleModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
$position = $this->drawable->position();
foreach ($image as $frame) {
// draw background
if ($this->drawable->hasBackgroundColor()) {
imagealphablending($frame->native(), true);
imagesetthickness($frame->native(), 0);
imagefilledrectangle(
$frame->native(),
$position->x(),
$position->y(),
$position->x() + $this->drawable->width(),
$position->y() + $this->drawable->height(),
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}
// draw border
if ($this->drawable->hasBorder()) {
imagealphablending($frame->native(), true);
imagesetthickness($frame->native(), $this->drawable->borderSize());
imagerectangle(
$frame->native(),
$position->x(),
$position->y(),
$position->x() + $this->drawable->width(),
$position->y() + $this->drawable->height(),
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
)
);
}
}
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/AlignRotationModifier.php | src/Drivers/Gd/Modifiers/AlignRotationModifier.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\AlignRotationModifier as GenericAlignRotationModifier;
class AlignRotationModifier extends GenericAlignRotationModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$image = match ($image->exif('IFD0.Orientation')) {
2 => $image->flop(),
3 => $image->rotate(180),
4 => $image->rotate(180)->flop(),
5 => $image->rotate(270)->flop(),
6 => $image->rotate(270),
7 => $image->rotate(90)->flop(),
8 => $image->rotate(90),
default => $image
};
return $this->markAligned($image);
}
/**
* Set exif data of image to top-left orientation, marking the image as
* aligned and making sure the rotation correction process is not
* performed again.
*/
private function markAligned(ImageInterface $image): ImageInterface
{
$exif = $image->exif()->map(function ($item) {
if (is_array($item) && array_key_exists('Orientation', $item)) {
$item['Orientation'] = 1;
return $item;
}
return $item;
});
return $image->setExif($exif);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/DrawPolygonModifier.php | src/Drivers/Gd/Modifiers/DrawPolygonModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawPolygonModifier as ModifiersDrawPolygonModifier;
class DrawPolygonModifier extends ModifiersDrawPolygonModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
if ($this->drawable->hasBackgroundColor()) {
imagealphablending($frame->native(), true);
imagesetthickness($frame->native(), 0);
imagefilledpolygon(
$frame->native(),
$this->drawable->toArray(),
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}
if ($this->drawable->hasBorder()) {
imagealphablending($frame->native(), true);
imagesetthickness($frame->native(), $this->drawable->borderSize());
imagepolygon(
$frame->native(),
$this->drawable->toArray(),
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
)
);
}
}
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/ScaleModifier.php | src/Drivers/Gd/Modifiers/ScaleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ScaleModifier extends ResizeModifier
{
protected function getAdjustedSize(ImageInterface $image): SizeInterface
{
return $image->size()->scale($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/ContainModifier.php | src/Drivers/Gd/Modifiers/ContainModifier.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\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\ContainModifier as GenericContainModifier;
class ContainModifier extends GenericContainModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$crop = $this->getCropSize($image);
$resize = $this->getResizeSize($image);
$background = $this->driver()->handleInput($this->background);
$blendingColor = $this->driver()->handleInput(
$this->driver()->config()->blendingColor
);
foreach ($image as $frame) {
$this->modify($frame, $crop, $resize, $background, $blendingColor);
}
return $image;
}
/**
* @throws ColorException
*/
protected function modify(
FrameInterface $frame,
SizeInterface $crop,
SizeInterface $resize,
ColorInterface $background,
ColorInterface $blendingColor
): void {
// create new gd image
$modified = Cloner::cloneEmpty($frame->native(), $resize, $background);
// make image area transparent to keep transparency
// even if background-color is set
$transparent = imagecolorallocatealpha(
$modified,
$blendingColor->channel(Red::class)->value(),
$blendingColor->channel(Green::class)->value(),
$blendingColor->channel(Blue::class)->value(),
127,
);
imagealphablending($modified, false); // do not blend / just overwrite
imagecolortransparent($modified, $transparent);
imagefilledrectangle(
$modified,
$crop->pivot()->x(),
$crop->pivot()->y(),
$crop->pivot()->x() + $crop->width() - 1,
$crop->pivot()->y() + $crop->height() - 1,
$transparent
);
// copy image from original with blending alpha
imagealphablending($modified, true);
imagecopyresampled(
$modified,
$frame->native(),
$crop->pivot()->x(),
$crop->pivot()->y(),
0,
0,
$crop->width(),
$crop->height(),
$frame->size()->width(),
$frame->size()->height()
);
// 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/BrightnessModifier.php | src/Drivers/Gd/Modifiers/BrightnessModifier.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\BrightnessModifier as GenericBrightnessModifier;
class BrightnessModifier extends GenericBrightnessModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagefilter($frame->native(), IMG_FILTER_BRIGHTNESS, intval($this->level * 2.55));
}
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/DrawEllipseModifier.php | src/Drivers/Gd/Modifiers/DrawEllipseModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawEllipseModifier as GenericDrawEllipseModifier;
class DrawEllipseModifier extends GenericDrawEllipseModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
if ($this->drawable->hasBorder()) {
imagealphablending($frame->native(), true);
// slightly smaller ellipse to keep 1px bordered edges clean
if ($this->drawable->hasBackgroundColor()) {
imagefilledellipse(
$frame->native(),
$this->drawable()->position()->x(),
$this->drawable->position()->y(),
$this->drawable->width() - 1,
$this->drawable->height() - 1,
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}
// gd's imageellipse ignores imagesetthickness
// so i use imagearc with 360 degrees instead.
imagesetthickness(
$frame->native(),
$this->drawable->borderSize(),
);
imagearc(
$frame->native(),
$this->drawable()->position()->x(),
$this->drawable()->position()->y(),
$this->drawable->width(),
$this->drawable->height(),
0,
360,
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
)
);
} else {
imagealphablending($frame->native(), true);
imagesetthickness($frame->native(), 0);
imagefilledellipse(
$frame->native(),
$this->drawable()->position()->x(),
$this->drawable()->position()->y(),
$this->drawable->width(),
$this->drawable->height(),
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}
}
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/GammaModifier.php | src/Drivers/Gd/Modifiers/GammaModifier.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\GammaModifier as GenericGammaModifier;
class GammaModifier extends GenericGammaModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagegammacorrect($frame->native(), 1, $this->gamma);
}
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/CoverModifier.php | src/Drivers/Gd/Modifiers/CoverModifier.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\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\CoverModifier as GenericCoverModifier;
class CoverModifier extends GenericCoverModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$crop = $this->getCropSize($image);
$resize = $this->getResizeSize($crop);
foreach ($image as $frame) {
$this->modifyFrame($frame, $crop, $resize);
}
return $image;
}
/**
* @throws ColorException
*/
protected function modifyFrame(FrameInterface $frame, SizeInterface $crop, SizeInterface $resize): void
{
// create new image
$modified = Cloner::cloneEmpty($frame->native(), $resize);
// copy content from resource
imagecopyresampled(
$modified,
$frame->native(),
0,
0,
$crop->pivot()->x(),
$crop->pivot()->y(),
$resize->width(),
$resize->height(),
$crop->width(),
$crop->height()
);
// 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/ProfileModifier.php | src/Drivers/Gd/Modifiers/ProfileModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ProfileModifier as GenericProfileModifier;
class ProfileModifier extends GenericProfileModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
throw new NotSupportedException(
'Color profiles are not supported by GD driver.'
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/SliceAnimationModifier.php | src/Drivers/Gd/Modifiers/SliceAnimationModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\SliceAnimationModifier as GenericSliceAnimationModifier;
class SliceAnimationModifier extends GenericSliceAnimationModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
if ($this->offset >= $image->count()) {
throw new AnimationException('Offset is not in the range of frames.');
}
$image->core()->slice($this->offset, $this->length);
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/ScaleDownModifier.php | src/Drivers/Gd/Modifiers/ScaleDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ScaleDownModifier extends ResizeModifier
{
/**
* {@inheritdoc}
*
* @see ResizeModifier::getAdjustedSize()
*/
protected function getAdjustedSize(ImageInterface $image): SizeInterface
{
return $image->size()->scaleDown($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/FlipModifier.php | src/Drivers/Gd/Modifiers/FlipModifier.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\FlipModifier as GenericFlipModifier;
class FlipModifier extends GenericFlipModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imageflip($frame->native(), IMG_FLIP_VERTICAL);
}
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/ProfileRemovalModifier.php | src/Drivers/Gd/Modifiers/ProfileRemovalModifier.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\ProfileRemovalModifier as GenericProfileRemovalModifier;
class ProfileRemovalModifier extends GenericProfileRemovalModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
// Color profiles are not supported by GD, so the decoded
// image is already free of profiles anyway.
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/GreyscaleModifier.php | src/Drivers/Gd/Modifiers/GreyscaleModifier.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\GreyscaleModifier as GenericGreyscaleModifier;
class GreyscaleModifier extends GenericGreyscaleModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagefilter($frame->native(), IMG_FILTER_GRAYSCALE);
}
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/ResolutionModifier.php | src/Drivers/Gd/Modifiers/ResolutionModifier.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\ResolutionModifier as GenericResolutionModifier;
class ResolutionModifier extends GenericResolutionModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$x = intval(round($this->x));
$y = intval(round($this->y));
foreach ($image as $frame) {
imageresolution($frame->native(), $x, $y);
}
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/ResizeDownModifier.php | src/Drivers/Gd/Modifiers/ResizeDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ResizeDownModifier extends ResizeModifier
{
protected function getAdjustedSize(ImageInterface $image): SizeInterface
{
return $image->size()->resizeDown($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/RemoveAnimationModifier.php | src/Drivers/Gd/Modifiers/RemoveAnimationModifier.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\RemoveAnimationModifier as GenericRemoveAnimationModifier;
class RemoveAnimationModifier extends GenericRemoveAnimationModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$image->core()->setNative(
$this->selectedFrame($image)->native()
);
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/QuantizeColorsModifier.php | src/Drivers/Gd/Modifiers/QuantizeColorsModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Drivers\Gd\Cloner;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\QuantizeColorsModifier as GenericQuantizeColorsModifier;
class QuantizeColorsModifier extends GenericQuantizeColorsModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
if ($this->limit <= 0) {
throw new InputException('Quantization limit must be greater than 0.');
}
// no color reduction if the limit is higher than the colors in the img
$colorCount = imagecolorstotal($image->core()->native());
if ($colorCount > 0 && $this->limit > $colorCount) {
return $image;
}
$width = $image->width();
$height = $image->height();
$background = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->background)
);
$blendingColor = $this->driver()->handleInput(
$this->driver()->config()->blendingColor
);
foreach ($image as $frame) {
// create new image for color quantization
$reduced = Cloner::cloneEmpty($frame->native(), background: $blendingColor);
// fill with background
imagefill($reduced, 0, 0, $background);
// set transparency
imagecolortransparent($reduced, $background);
// copy original image (colors are limited automatically in the copy process)
imagecopy($reduced, $frame->native(), 0, 0, 0, 0, $width, $height);
// gd library does not support color quantization directly therefore the
// colors are decrease by transforming the image to a palette version
imagetruecolortopalette($reduced, true, $this->limit);
$frame->setNative($reduced);
}
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/PlaceModifier.php | src/Drivers/Gd/Modifiers/PlaceModifier.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\PointInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\PlaceModifier as GenericPlaceModifier;
class PlaceModifier extends GenericPlaceModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$watermark = $this->driver()->handleInput($this->element);
$position = $this->getPosition($image, $watermark);
foreach ($image as $frame) {
imagealphablending($frame->native(), true);
if ($this->opacity === 100) {
$this->placeOpaque($frame, $watermark, $position);
} else {
$this->placeTransparent($frame, $watermark, $position);
}
}
return $image;
}
/**
* Insert watermark with 100% opacity
*
* @throws RuntimeException
*/
private function placeOpaque(FrameInterface $frame, ImageInterface $watermark, PointInterface $position): void
{
imagecopy(
$frame->native(),
$watermark->core()->native(),
$position->x(),
$position->y(),
0,
0,
$watermark->width(),
$watermark->height()
);
}
/**
* Insert watermark transparent with current opacity
*
* Unfortunately, the original PHP function imagecopymerge does not work reliably.
* For example, any transparency of the image to be inserted is not applied correctly.
* For this reason, a new GDImage is created into which the original image is inserted
* in the first step and the watermark is inserted with 100% opacity in the second
* step. This combination is then transferred to the original image again with the
* respective opacity.
*
* Please note: Unfortunately, there is still an edge case, when a transparent image
* is placed on a transparent background, the "double" transparent areas appear opaque!
*
* @throws RuntimeException
*/
private function placeTransparent(FrameInterface $frame, ImageInterface $watermark, PointInterface $position): void
{
$cut = imagecreatetruecolor($watermark->width(), $watermark->height());
imagecopy(
$cut,
$frame->native(),
0,
0,
$position->x(),
$position->y(),
imagesx($cut),
imagesy($cut)
);
imagecopy(
$cut,
$watermark->core()->native(),
0,
0,
0,
0,
imagesx($cut),
imagesy($cut)
);
imagecopymerge(
$frame->native(),
$cut,
$position->x(),
$position->y(),
0,
0,
$watermark->width(),
$watermark->height(),
$this->opacity
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/BlurModifier.php | src/Drivers/Gd/Modifiers/BlurModifier.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\BlurModifier as GenericBlurModifier;
class BlurModifier extends GenericBlurModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
for ($i = 0; $i < $this->amount; $i++) {
imagefilter($frame->native(), IMG_FILTER_GAUSSIAN_BLUR);
}
}
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/SharpenModifier.php | src/Drivers/Gd/Modifiers/SharpenModifier.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\SharpenModifier as GenericSharpenModifier;
class SharpenModifier extends GenericSharpenModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$matrix = $this->matrix();
foreach ($image as $frame) {
imageconvolution($frame->native(), $matrix, 1, 0);
}
return $image;
}
/**
* Create matrix to be used by imageconvolution()
*
* @return array<array<float>>
*/
private function matrix(): array
{
$min = $this->amount >= 10 ? $this->amount * -0.01 : 0;
$max = $this->amount * -0.025;
$abs = ((4 * $min + 4 * $max) * -1) + 1;
return [
[$min, $max, $min],
[$max, $abs, $max],
[$min, $max, $min]
];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Gd/Modifiers/ResizeCanvasModifier.php | src/Drivers/Gd/Modifiers/ResizeCanvasModifier.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\ResizeCanvasModifier as GenericResizeCanvasModifier;
class ResizeCanvasModifier extends GenericResizeCanvasModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$cropSize = $this->cropSize($image);
$image->modify(new CropModifier(
$cropSize->width(),
$cropSize->height(),
$cropSize->pivot()->x(),
$cropSize->pivot()->y(),
$this->background,
));
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/ContrastModifier.php | src/Drivers/Gd/Modifiers/ContrastModifier.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\ContrastModifier as GenericContrastModifier;
class ContrastModifier extends GenericContrastModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagefilter($frame->native(), IMG_FILTER_CONTRAST, ($this->level * -1));
}
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/CoverDownModifier.php | src/Drivers/Gd/Modifiers/CoverDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Interfaces\SizeInterface;
class CoverDownModifier extends CoverModifier
{
/**
* @throws GeometryException
*/
public function getResizeSize(SizeInterface $size): SizeInterface
{
return $size->resizeDown($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/DrawLineModifier.php | src/Drivers/Gd/Modifiers/DrawLineModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Gd\Modifiers;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawLineModifier as GenericDrawLineModifier;
class DrawLineModifier extends GenericDrawLineModifier implements SpecializedInterface
{
/**
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
foreach ($image as $frame) {
imagealphablending($frame->native(), true);
imageantialias($frame->native(), true);
imagesetthickness($frame->native(), $this->drawable->width());
imageline(
$frame->native(),
$this->drawable->start()->x(),
$this->drawable->start()->y(),
$this->drawable->end()->x(),
$this->drawable->end()->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/Imagick/Frame.php | src/Drivers/Imagick/Frame.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick;
use Imagick;
use ImagickException;
use ImagickPixel;
use Intervention\Image\Drivers\AbstractFrame;
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 object
*
* @throws ImagickException
* @return void
*/
public function __construct(protected Imagick $native)
{
$background = new ImagickPixel('rgba(255, 255, 255, 0)');
$this->native->setImageBackgroundColor($background);
$this->native->setBackgroundColor($background);
}
/**
* {@inheritdoc}
*
* @see DriverInterface::toImage()
*/
public function toImage(DriverInterface $driver): ImageInterface
{
return new Image($driver, new Core($this->native()));
}
/**
* {@inheritdoc}
*
* @see DriverInterface::setNative()
*/
public function setNative(mixed $native): FrameInterface
{
$this->native = $native;
return $this;
}
/**
* {@inheritdoc}
*
* @see DriverInterface::native()
*/
public function native(): Imagick
{
return $this->native;
}
/**
* {@inheritdoc}
*
* @see DriverInterface::size()
*/
public function size(): SizeInterface
{
return new Rectangle(
$this->native->getImageWidth(),
$this->native->getImageHeight()
);
}
/**
* {@inheritdoc}
*
* @see DriverInterface::delay()
*/
public function delay(): float
{
return $this->native->getImageDelay() / 100;
}
/**
* {@inheritdoc}
*
* @see DriverInterface::setDelay()
*/
public function setDelay(float $delay): FrameInterface
{
$this->native->setImageDelay(intval(round($delay * 100)));
return $this;
}
/**
* {@inheritdoc}
*
* @see DriverInterface::dispose()
*/
public function dispose(): int
{
return $this->native->getImageDispose();
}
/**
* {@inheritdoc}
*
* @see DriverInterface::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->native->setImageDispose($dispose);
return $this;
}
/**
* {@inheritdoc}
*
* @see DriverInterface::setOffset()
*/
public function setOffset(int $left, int $top): FrameInterface
{
$this->native->setImagePage(
$this->native->getImageWidth(),
$this->native->getImageHeight(),
$left,
$top
);
return $this;
}
/**
* {@inheritdoc}
*
* @see DriverInterface::offsetLeft()
*/
public function offsetLeft(): int
{
return $this->native->getImagePage()['x'];
}
/**
* {@inheritdoc}
*
* @see DriverInterface::setOffsetLeft()
*/
public function setOffsetLeft(int $offset): FrameInterface
{
return $this->setOffset($offset, $this->offsetTop());
}
/**
* {@inheritdoc}
*
* @see DriverInterface::offsetTop()
*/
public function offsetTop(): int
{
return $this->native->getImagePage()['y'];
}
/**
* {@inheritdoc}
*
* @see DriverInterface::setOffsetTop()
*/
public function setOffsetTop(int $offset): FrameInterface
{
return $this->setOffset($this->offsetLeft(), $offset);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Core.php | src/Drivers/Imagick/Core.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick;
use Imagick;
use ImagickException;
use Iterator;
use Intervention\Image\Interfaces\CoreInterface;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Interfaces\CollectionInterface;
use Intervention\Image\Interfaces\FrameInterface;
/**
* @implements Iterator<FrameInterface>
*/
class Core implements CoreInterface, Iterator
{
protected int $iteratorIndex = 0;
/**
* Create new core instance
*
* @return void
*/
public function __construct(protected Imagick $imagick)
{
//
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::has()
*/
public function has(int|string $key): bool
{
try {
$result = $this->imagick->setIteratorIndex($key);
} catch (ImagickException) {
return false;
}
return $result;
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::push()
*/
public function push(mixed $item): CollectionInterface
{
return $this->add($item);
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::get()
*/
public function get(int|string $key, mixed $default = null): mixed
{
try {
$this->imagick->setIteratorIndex($key);
} catch (ImagickException) {
return $default;
}
return new Frame($this->imagick->current());
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::getAtPosition()
*/
public function getAtPosition(int $key = 0, mixed $default = null): mixed
{
return $this->get($key, $default);
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::empty()
*/
public function empty(): CollectionInterface
{
$this->imagick->clear();
return $this;
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::slice()
*/
public function slice(int $offset, ?int $length = null): CollectionInterface
{
$allowed_indexes = [];
$length = is_null($length) ? $this->count() : $length;
for ($i = $offset; $i < $offset + $length; $i++) {
$allowed_indexes[] = $i;
}
$sliced = new Imagick();
foreach ($this->imagick as $key => $native) {
if (in_array($key, $allowed_indexes)) {
$sliced->addImage($native->getImage());
}
}
$sliced = $sliced->coalesceImages();
$sliced->setImageIterations($this->imagick->getImageIterations());
$this->imagick = $sliced;
return $this;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::add()
*/
public function add(FrameInterface $frame): CoreInterface
{
$imagick = $frame->native();
$imagick->setImageDelay(
(int) round($frame->delay() * 100)
);
$imagick->setImageDispose($frame->dispose());
$size = $frame->size();
$imagick->setImagePage(
$size->width(),
$size->height(),
$frame->offsetLeft(),
$frame->offsetTop()
);
$this->imagick->addImage($imagick);
return $this;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::count()
*/
public function count(): int
{
return $this->imagick->getNumberImages();
}
/**
* {@inheritdoc}
*
* @see Iterator::rewind()
*/
public function current(): mixed
{
$this->imagick->setIteratorIndex($this->iteratorIndex);
return new Frame($this->imagick->current());
}
/**
* {@inheritdoc}
*
* @see Iterator::rewind()
*/
public function next(): void
{
$this->iteratorIndex += 1;
}
/**
* {@inheritdoc}
*
* @see Iterator::rewind()
*/
public function key(): mixed
{
return $this->iteratorIndex;
}
/**
* {@inheritdoc}
*
* @see Iterator::rewind()
*/
public function valid(): bool
{
try {
$result = $this->imagick->setIteratorIndex($this->iteratorIndex);
} catch (ImagickException) {
return false;
}
return $result;
}
/**
* {@inheritdoc}
*
* @see Iterator::rewind()
*/
public function rewind(): void
{
$this->iteratorIndex = 0;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::native()
*/
public function native(): mixed
{
return $this->imagick;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::setNative()
*/
public function setNative(mixed $native): CoreInterface
{
$this->imagick = $native;
return $this;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::frame()
*/
public function frame(int $position): FrameInterface
{
foreach ($this->imagick as $core) {
if ($core->getIteratorIndex() === $position) {
return new Frame($core);
}
}
throw new AnimationException('Frame #' . $position . ' could not be found in the image.');
}
/**
* {@inheritdoc}
*
* @see CoreInterface::loops()
*/
public function loops(): int
{
return $this->imagick->getImageIterations();
}
/**
* {@inheritdoc}
*
* @see CoreInterface::setLoops()
*/
public function setLoops(int $loops): CoreInterface
{
$this->imagick = $this->imagick->coalesceImages();
$this->imagick->setImageIterations($loops);
return $this;
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::first()
*/
public function first(): FrameInterface
{
return $this->frame(0);
}
/**
* {@inheritdoc}
*
* @see CollectableInterface::last()
*/
public function last(): FrameInterface
{
return $this->frame($this->count() - 1);
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::toArray()
*/
public function toArray(): array
{
$frames = [];
foreach ($this as $frame) {
$frames[] = $frame;
}
return $frames;
}
/**
* Clone instance
*/
public function __clone(): void
{
$this->imagick = clone $this->imagick;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/FontProcessor.php | src/Drivers/Imagick/FontProcessor.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick;
use Imagick;
use ImagickDraw;
use ImagickDrawException;
use ImagickException;
use ImagickPixel;
use Intervention\Image\Drivers\AbstractFontProcessor;
use Intervention\Image\Exceptions\FontException;
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
{
// no text - no box size
if (mb_strlen($text) === 0) {
return new Rectangle(0, 0);
}
$draw = $this->toImagickDraw($font);
$dimensions = (new Imagick())->queryFontMetrics($draw, $text);
return new Rectangle(
intval(round($dimensions['textWidth'])),
intval(round($dimensions['ascender'] + $dimensions['descender'])),
);
}
/**
* Imagick::annotateImage() needs an ImagickDraw object - this method takes
* the font object as the base and adds an optional passed color to the new
* ImagickDraw object.
*
* @throws FontException
* @throws ImagickDrawException
* @throws ImagickException
*/
public function toImagickDraw(FontInterface $font, ?ImagickPixel $color = null): ImagickDraw
{
if (!$font->hasFilename()) {
throw new FontException('No font file specified.');
}
$draw = new ImagickDraw();
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
$draw->setFont($font->filename());
$draw->setFontSize($this->nativeFontSize($font));
$draw->setTextAlignment(Imagick::ALIGN_LEFT);
if ($color instanceof ImagickPixel) {
$draw->setFillColor($color);
}
return $draw;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/ColorProcessor.php | src/Drivers/Imagick/ColorProcessor.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick;
use Imagick;
use ImagickPixel;
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorProcessorInterface;
use Intervention\Image\Interfaces\ColorspaceInterface;
class ColorProcessor implements ColorProcessorInterface
{
public function __construct(protected ColorspaceInterface $colorspace)
{
//
}
public function colorToNative(ColorInterface $color): ImagickPixel
{
return new ImagickPixel(
(string) $color->convertTo($this->colorspace)
);
}
public function nativeToColor(mixed $native): ColorInterface
{
return match ($this->colorspace::class) {
CmykColorspace::class => $this->colorspace->colorFromNormalized([
$native->getColorValue(Imagick::COLOR_CYAN),
$native->getColorValue(Imagick::COLOR_MAGENTA),
$native->getColorValue(Imagick::COLOR_YELLOW),
$native->getColorValue(Imagick::COLOR_BLACK),
]),
default => $this->colorspace->colorFromNormalized([
$native->getColorValue(Imagick::COLOR_RED),
$native->getColorValue(Imagick::COLOR_GREEN),
$native->getColorValue(Imagick::COLOR_BLUE),
$native->getColorValue(Imagick::COLOR_ALPHA),
]),
};
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Driver.php | src/Drivers/Imagick/Driver.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\AbstractDriver;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\NotSupportedException;
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 'Imagick';
}
/**
* {@inheritdoc}
*
* @see DriverInterface::checkHealth()
*
* @codeCoverageIgnore
*/
public function checkHealth(): void
{
if (!extension_loaded('imagick') || !class_exists('Imagick')) {
throw new DriverException(
'Imagick PHP extension must be installed to use this driver.'
);
}
}
/**
* {@inheritdoc}
*
* @see DriverInterface::createImage()
*/
public function createImage(int $width, int $height): ImageInterface
{
$background = new ImagickPixel('rgba(255, 255, 255, 0)');
$imagick = new Imagick();
$imagick->newImage($width, $height, $background, 'png');
$imagick->setType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setColorspace(Imagick::COLORSPACE_SRGB);
$imagick->setImageResolution(96, 96);
$imagick->setImageBackgroundColor($background);
return new Image($this, new Core($imagick));
}
/**
* {@inheritdoc}
*
* @see DriverInterface::createAnimation()
*
* @throws RuntimeException
*/
public function createAnimation(callable $init): ImageInterface
{
$imagick = new Imagick();
$imagick->setFormat('gif');
$animation = new class ($this, $imagick)
{
public function __construct(
protected DriverInterface $driver,
public Imagick $imagick
) {
//
}
/**
* @throws RuntimeException
*/
public function add(mixed $source, float $delay = 1): self
{
$native = $this->driver->handleInput($source)->core()->native();
$native->setImageDelay(intval(round($delay * 100)));
$this->imagick->addImage($native);
return $this;
}
/**
* @throws RuntimeException
*/
public function __invoke(): ImageInterface
{
return new Image(
$this->driver,
new Core($this->imagick)
);
}
};
$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
{
try {
$format = Format::create($identifier);
} catch (NotSupportedException) {
return false;
}
return count(Imagick::queryFormats($format->name)) >= 1;
}
/**
* Return version of ImageMagick library
*
* @throws DriverException
*/
public static function version(): string
{
$pattern = '/^ImageMagick (?P<version>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' .
'(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?' .
'(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/';
if (preg_match($pattern, Imagick::getVersion()['versionString'], $matches) !== 1) {
throw new DriverException('Unable to read ImageMagick version number.');
}
return $matches['version'];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/TiffEncoder.php | src/Drivers/Imagick/Encoders/TiffEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Intervention\Image\Drivers\Imagick\Modifiers\StripMetaModifier;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\TiffEncoder as GenericTiffEncoder;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class TiffEncoder extends GenericTiffEncoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'TIFF';
// strip meta data
if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) {
$image->modify(new StripMetaModifier());
}
$imagick = $image->core()->native();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($imagick->getImageCompression());
$imagick->setImageCompression($imagick->getImageCompression());
$imagick->setCompressionQuality($this->quality);
$imagick->setImageCompressionQuality($this->quality);
return new EncodedImage($imagick->getImagesBlob(), 'image/tiff');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/BmpEncoder.php | src/Drivers/Imagick/Encoders/BmpEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Imagick;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\BmpEncoder as GenericBmpEncoder;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class BmpEncoder extends GenericBmpEncoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'BMP';
$compression = Imagick::COMPRESSION_NO;
$imagick = $image->core()->native();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
return new EncodedImage($imagick->getImagesBlob(), 'image/bmp');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php | src/Drivers/Imagick/Encoders/Jpeg2000Encoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Imagick;
use Intervention\Image\Drivers\Imagick\Modifiers\StripMetaModifier;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\Jpeg2000Encoder as GenericJpeg2000Encoder;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class Jpeg2000Encoder extends GenericJpeg2000Encoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'JP2';
$compression = Imagick::COMPRESSION_JPEG;
// strip meta data
if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) {
$image->modify(new StripMetaModifier());
}
$imagick = $image->core()->native();
$imagick->setImageBackgroundColor('white');
$imagick->setBackgroundColor('white');
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
$imagick->setCompressionQuality($this->quality);
$imagick->setImageCompressionQuality($this->quality);
return new EncodedImage($imagick->getImagesBlob(), 'image/jp2');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/PngEncoder.php | src/Drivers/Imagick/Encoders/PngEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Imagick;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\PngEncoder as GenericPngEncoder;
use Intervention\Image\Interfaces\EncodedImageInterface;
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): EncodedImageInterface
{
if ($this->indexed) {
// reduce colors
$output = clone $image;
$output->reduceColors(256);
$output = $output->core()->native();
$output->setFormat('PNG');
$output->setImageFormat('PNG');
} else {
$output = clone $image->core()->native();
$output->setFormat('PNG32');
$output->setImageFormat('PNG32');
}
$output->setCompression(Imagick::COMPRESSION_ZIP);
$output->setImageCompression(Imagick::COMPRESSION_ZIP);
if ($this->interlaced) {
$output->setInterlaceScheme(Imagick::INTERLACE_LINE);
}
return new EncodedImage($output->getImagesBlob(), 'image/png');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/JpegEncoder.php | src/Drivers/Imagick/Encoders/JpegEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Imagick;
use Intervention\Image\Drivers\Imagick\Modifiers\StripMetaModifier;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\JpegEncoder as GenericJpegEncoder;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class JpegEncoder extends GenericJpegEncoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'JPEG';
$compression = Imagick::COMPRESSION_JPEG;
$blendingColor = $this->driver()->handleInput(
$this->driver()->config()->blendingColor
);
// resolve blending color because jpeg has no transparency
$background = $this->driver()
->colorProcessor($image->colorspace())
->colorToNative($blendingColor);
// set alpha value to 1 because Imagick renders
// possible full transparent colors as black
$background->setColorValue(Imagick::COLOR_ALPHA, 1);
// strip meta data
if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) {
$image->modify(new StripMetaModifier());
}
/** @var Imagick $imagick */
$imagick = $image->core()->native();
$imagick->setImageBackgroundColor($background);
$imagick->setBackgroundColor($background);
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
$imagick->setCompressionQuality($this->quality);
$imagick->setImageCompressionQuality($this->quality);
$imagick->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
if ($this->progressive) {
$imagick->setInterlaceScheme(Imagick::INTERLACE_PLANE);
}
return new EncodedImage($imagick->getImagesBlob(), 'image/jpeg');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/AvifEncoder.php | src/Drivers/Imagick/Encoders/AvifEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Imagick;
use Intervention\Image\Drivers\Imagick\Modifiers\StripMetaModifier;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\AvifEncoder as GenericAvifEncoder;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class AvifEncoder extends GenericAvifEncoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'AVIF';
$compression = Imagick::COMPRESSION_ZIP;
// strip meta data
if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) {
$image->modify(new StripMetaModifier());
}
$imagick = $image->core()->native();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
$imagick->setCompressionQuality($this->quality);
$imagick->setImageCompressionQuality($this->quality);
return new EncodedImage($imagick->getImagesBlob(), 'image/avif');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/GifEncoder.php | src/Drivers/Imagick/Encoders/GifEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Imagick;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\GifEncoder as GenericGifEncoder;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class GifEncoder extends GenericGifEncoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'GIF';
$compression = Imagick::COMPRESSION_LZW;
$imagick = $image->core()->native();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
if ($this->interlaced) {
$imagick->setInterlaceScheme(Imagick::INTERLACE_LINE);
}
return new EncodedImage($imagick->getImagesBlob(), 'image/gif');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/HeicEncoder.php | src/Drivers/Imagick/Encoders/HeicEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Intervention\Image\Drivers\Imagick\Modifiers\StripMetaModifier;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\HeicEncoder as GenericHeicEncoder;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class HeicEncoder extends GenericHeicEncoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'HEIC';
// strip meta data
if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) {
$image->modify(new StripMetaModifier());
}
$imagick = $image->core()->native();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompressionQuality($this->quality);
$imagick->setImageCompressionQuality($this->quality);
return new EncodedImage($imagick->getImagesBlob(), 'image/heic');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Encoders/WebpEncoder.php | src/Drivers/Imagick/Encoders/WebpEncoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Encoders;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Modifiers\StripMetaModifier;
use Intervention\Image\EncodedImage;
use Intervention\Image\Encoders\WebpEncoder as GenericWebpEncoder;
use Intervention\Image\Interfaces\EncodedImageInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class WebpEncoder extends GenericWebpEncoder implements SpecializedInterface
{
public function encode(ImageInterface $image): EncodedImageInterface
{
$format = 'WEBP';
$compression = Imagick::COMPRESSION_ZIP;
// strip meta data
if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) {
$image->modify(new StripMetaModifier());
}
$imagick = $image->core()->native();
$imagick->setImageBackgroundColor(new ImagickPixel('transparent'));
if (!$image->isAnimated()) {
$imagick = $imagick->mergeImageLayers(Imagick::LAYERMETHOD_MERGE);
}
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
$imagick->setImageCompressionQuality($this->quality);
if ($this->quality === 100) {
$imagick->setOption('webp:lossless', 'true');
}
return new EncodedImage($imagick->getImagesBlob(), 'image/webp');
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Decoders/DataUriImageDecoder.php | src/Drivers/Imagick/Decoders/DataUriImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class DataUriImageDecoder extends BinaryImageDecoder
{
/**
* {@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/Imagick/Decoders/FilePointerImageDecoder.php | src/Drivers/Imagick/Decoders/FilePointerImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\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/Imagick/Decoders/BinaryImageDecoder.php | src/Drivers/Imagick/Decoders/BinaryImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Decoders;
use Imagick;
use ImagickException;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Format;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class BinaryImageDecoder extends NativeObjectDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
try {
$imagick = new Imagick();
$imagick->readImageBlob($input);
} catch (ImagickException) {
throw new DecoderException('Unable to decode input');
}
// decode image
$image = parent::decode($imagick);
// get media type enum from string media type
$format = Format::tryCreate($image->origin()->mediaType());
// extract exif data for appropriate formats
if (in_array($format, [Format::JPEG, Format::TIFF])) {
$image->setExif($this->extractExifData($input));
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php | src/Drivers/Imagick/Decoders/FilePathImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Decoders;
use Imagick;
use ImagickException;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class FilePathImageDecoder extends NativeObjectDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!$this->isFile($input)) {
throw new DecoderException('Unable to decode input');
}
try {
$imagick = new Imagick();
$imagick->readImage($input);
} catch (ImagickException) {
throw new DecoderException('Unable to decode input');
}
// decode image
$image = parent::decode($imagick);
// set file path on origin
$image->origin()->setFilePath($input);
// extract exif data for the appropriate formats
if (in_array($imagick->getImageFormat(), ['JPEG', 'TIFF', 'TIF'])) {
$image->setExif($this->extractExifData($input));
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Decoders/SplFileInfoImageDecoder.php | src/Drivers/Imagick/Decoders/SplFileInfoImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Decoders;
use SplFileInfo;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class SplFileInfoImageDecoder extends FilePathImageDecoder
{
/**
* {@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/Imagick/Decoders/EncodedImageObjectDecoder.php | src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\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/Imagick/Decoders/Base64ImageDecoder.php | src/Drivers/Imagick/Decoders/Base64ImageDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
class Base64ImageDecoder extends BinaryImageDecoder
{
/**
* {@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/Imagick/Decoders/NativeObjectDecoder.php | src/Drivers/Imagick/Decoders/NativeObjectDecoder.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Decoders;
use Imagick;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\SpecializableDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\AlignRotationModifier;
use Intervention\Image\Modifiers\RemoveAnimationModifier;
class NativeObjectDecoder extends SpecializableDecoder implements SpecializedInterface
{
/**
* {@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 Imagick)) {
throw new DecoderException('Unable to decode input');
}
// For some JPEG formats, the "coalesceImages()" call leads to an image
// completely filled with background color. The logic behind this is
// incomprehensible for me; could be an imagick bug.
if ($input->getImageFormat() !== 'JPEG') {
$input = $input->coalesceImages();
}
// turn images with colorspace 'GRAY' into 'SRGB' to avoid working on
// greyscale colorspace images as this results images loosing color
// information when placed into this image.
if ($input->getImageColorspace() == Imagick::COLORSPACE_GRAY) {
$input->setImageColorspace(Imagick::COLORSPACE_SRGB);
}
// create image object
$image = new Image(
$this->driver(),
new Core($input)
);
// discard animation depending on config
if (!$this->driver()->config()->decodeAnimation) {
$image->modify(new RemoveAnimationModifier());
}
// adjust image rotatation
if ($this->driver()->config()->autoOrientation) {
$image->modify(new AlignRotationModifier());
}
// set media type on origin
$image->origin()->setMediaType($input->getImageMimeType());
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Analyzers/ColorspaceAnalyzer.php | src/Drivers/Imagick/Analyzers/ColorspaceAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Analyzers;
use Imagick;
use Intervention\Image\Analyzers\ColorspaceAnalyzer as GenericColorspaceAnalyzer;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\Interfaces\SpecializedInterface;
class ColorspaceAnalyzer extends GenericColorspaceAnalyzer implements SpecializedInterface
{
public function analyze(ImageInterface $image): mixed
{
return match ($image->core()->native()->getImageColorspace()) {
Imagick::COLORSPACE_CMYK => new CmykColorspace(),
default => new RgbColorspace(),
};
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Analyzers/HeightAnalyzer.php | src/Drivers/Imagick/Analyzers/HeightAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Analyzers;
use Intervention\Image\Analyzers\HeightAnalyzer as GenericHeightAnalyzer;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class HeightAnalyzer extends GenericHeightAnalyzer implements SpecializedInterface
{
public function analyze(ImageInterface $image): mixed
{
return $image->core()->native()->getImageHeight();
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Analyzers/PixelColorsAnalyzer.php | src/Drivers/Imagick/Analyzers/PixelColorsAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Analyzers;
use Intervention\Image\Collection;
use Intervention\Image\Interfaces\ImageInterface;
class PixelColorsAnalyzer extends PixelColorAnalyzer
{
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/Imagick/Analyzers/WidthAnalyzer.php | src/Drivers/Imagick/Analyzers/WidthAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Analyzers;
use Intervention\Image\Analyzers\WidthAnalyzer as GenericWidthAnalyzer;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class WidthAnalyzer extends GenericWidthAnalyzer implements SpecializedInterface
{
public function analyze(ImageInterface $image): mixed
{
return $image->core()->native()->getImageWidth();
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Analyzers/ResolutionAnalyzer.php | src/Drivers/Imagick/Analyzers/ResolutionAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\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
{
public function analyze(ImageInterface $image): mixed
{
$imagick = $image->core()->native();
$imageResolution = $imagick->getImageResolution();
return new Resolution(
$imageResolution['x'],
$imageResolution['y'],
$imagick->getImageUnits(),
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php | src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Analyzers;
use Imagick;
use Intervention\Image\Analyzers\PixelColorAnalyzer as GenericPixelColorAnalyzer;
use Intervention\Image\Exceptions\ColorException;
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
{
public function analyze(ImageInterface $image): mixed
{
return $this->colorAt(
$image->colorspace(),
$image->core()->frame($this->frame_key)->native()
);
}
/**
* @throws ColorException
*/
protected function colorAt(ColorspaceInterface $colorspace, Imagick $imagick): ColorInterface
{
return $this->driver()
->colorProcessor($colorspace)
->nativeToColor(
$imagick->getImagePixelColor($this->x, $this->y)
);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Analyzers/ProfileAnalyzer.php | src/Drivers/Imagick/Analyzers/ProfileAnalyzer.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Analyzers;
use Intervention\Image\Analyzers\ProfileAnalyzer as GenericProfileAnalyzer;
use Intervention\Image\Colors\Profile;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class ProfileAnalyzer extends GenericProfileAnalyzer implements SpecializedInterface
{
public function analyze(ImageInterface $image): mixed
{
$profiles = $image->core()->native()->getImageProfiles('icc');
if (!array_key_exists('icc', $profiles)) {
throw new ColorException('No ICC profile found in image.');
}
return new Profile($profiles['icc']);
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/BlendTransparencyModifier.php | src/Drivers/Imagick/Modifiers/BlendTransparencyModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\BlendTransparencyModifier as GenericBlendTransparencyModifier;
class BlendTransparencyModifier extends GenericBlendTransparencyModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$blendingColor = $this->blendingColor($this->driver());
// get imagickpixel from blending color
$pixel = $this->driver()
->colorProcessor($image->colorspace())
->colorToNative($blendingColor);
// merge transparent areas with the background color
foreach ($image as $frame) {
$frame->native()->setImageBackgroundColor($pixel);
$frame->native()->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
$frame->native()->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ResizeCanvasRelativeModifier.php | src/Drivers/Imagick/Modifiers/ResizeCanvasRelativeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\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/Imagick/Modifiers/DrawPixelModifier.php | src/Drivers/Imagick/Modifiers/DrawPixelModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawPixelModifier as GenericDrawPixelModifier;
class DrawPixelModifier extends GenericDrawPixelModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->color)
);
$pixel = new ImagickDraw();
$pixel->setFillColor($color);
$pixel->point($this->position->x(), $this->position->y());
foreach ($image as $frame) {
$frame->native()->drawImage($pixel);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/TextModifier.php | src/Drivers/Imagick/Modifiers/TextModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use ImagickDrawException;
use ImagickException;
use Intervention\Image\Drivers\Imagick\FontProcessor;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\PointInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\TextModifier as GenericTextModifier;
use Intervention\Image\Typography\Line;
class TextModifier extends GenericTextModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
$lines = $this->processor()->textBlock($this->text, $this->font, $this->position);
$drawText = $this->imagickDrawText($image, $this->font);
$drawStroke = $this->imagickDrawStroke($image, $this->font);
foreach ($image as $frame) {
foreach ($lines as $line) {
foreach ($this->strokeOffsets($this->font) as $offset) {
// Draw the stroke outline under the actual text
$this->maybeDrawTextline($frame, $line, $drawStroke, $offset);
}
// Draw the actual text
$this->maybeDrawTextline($frame, $line, $drawText);
}
}
return $image;
}
/**
* Create an ImagickDraw object to draw text on the image
*
* @throws RuntimeException
* @throws ColorException
* @throws FontException
* @throws ImagickDrawException
* @throws ImagickException
*/
private function imagickDrawText(ImageInterface $image, FontInterface $font): ImagickDraw
{
$color = $this->driver()->handleInput($font->color());
if ($font->hasStrokeEffect() && $color->isTransparent()) {
throw new ColorException(
'The text color must be fully opaque when using the stroke effect.'
);
}
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative($color);
return $this->processor()->toImagickDraw($font, $color);
}
/**
* Create a ImagickDraw object to draw the outline stroke effect on the Image
*
* @throws RuntimeException
* @throws ColorException
* @throws FontException
* @throws ImagickDrawException
* @throws ImagickException
*/
private function imagickDrawStroke(ImageInterface $image, FontInterface $font): ?ImagickDraw
{
if (!$font->hasStrokeEffect()) {
return null;
}
$color = $this->driver()->handleInput($font->strokeColor());
if ($color->isTransparent()) {
throw new ColorException(
'The stroke color must be fully opaque.'
);
}
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative($color);
return $this->processor()->toImagickDraw($font, $color);
}
/**
* Maybe draw given line of text on frame instance depending on given
* ImageDraw instance. Optionally move line position by given offset.
*/
private function maybeDrawTextline(
FrameInterface $frame,
Line $textline,
?ImagickDraw $draw = null,
PointInterface $offset = new Point(),
): void {
if ($draw instanceof ImagickDraw) {
$frame->native()->annotateImage(
$draw,
$textline->position()->x() + $offset->x(),
$textline->position()->y() + $offset->y(),
$this->font->angle(),
(string) $textline
);
}
}
/**
* Return imagick font processor
*
* @throws FontException
*/
private function processor(): FontProcessor
{
$processor = $this->driver()->fontProcessor();
if (!($processor instanceof FontProcessor)) {
throw new FontException('Font processor does not match the driver.');
}
return $processor;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ResizeModifier.php | src/Drivers/Imagick/Modifiers/ResizeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\RuntimeException;
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
{
public function apply(ImageInterface $image): ImageInterface
{
$resizeTo = $this->getAdjustedSize($image);
foreach ($image as $frame) {
$frame->native()->scaleImage(
$resizeTo->width(),
$resizeTo->height()
);
}
return $image;
}
/**
* @throws RuntimeException
*/
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/Imagick/Modifiers/DrawBezierModifier.php | src/Drivers/Imagick/Modifiers/DrawBezierModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
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
{
/**
* @throws RuntimeException
* @throws GeometryException
*/
public function apply(ImageInterface $image): ImageInterface
{
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');
}
$drawing = new ImagickDraw();
if ($this->drawable->hasBackgroundColor()) {
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
} else {
$background_color = 'transparent';
}
$drawing->setFillColor($background_color);
if ($this->drawable->hasBorder() && $this->drawable->borderSize() > 0) {
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
$drawing->setStrokeColor($border_color);
$drawing->setStrokeWidth($this->drawable->borderSize());
}
$drawing->pathStart();
$drawing->pathMoveToAbsolute(
$this->drawable->first()->x(),
$this->drawable->first()->y()
);
if ($this->drawable->count() === 3) {
$drawing->pathCurveToQuadraticBezierAbsolute(
$this->drawable->second()->x(),
$this->drawable->second()->y(),
$this->drawable->last()->x(),
$this->drawable->last()->y()
);
} elseif ($this->drawable->count() === 4) {
$drawing->pathCurveToAbsolute(
$this->drawable->second()->x(),
$this->drawable->second()->y(),
$this->drawable->third()->x(),
$this->drawable->third()->y(),
$this->drawable->last()->x(),
$this->drawable->last()->y()
);
}
$drawing->pathFinish();
foreach ($image as $frame) {
$frame->native()->drawImage($drawing);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/RotateModifier.php | src/Drivers/Imagick/Modifiers/RotateModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\RotateModifier as GenericRotateModifier;
class RotateModifier extends GenericRotateModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$background = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->background)
);
foreach ($image as $frame) {
$frame->native()->rotateImage(
$background,
$this->rotationAngle() * -1
);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/PadModifier.php | src/Drivers/Imagick/Modifiers/PadModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\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/Imagick/Modifiers/CropModifier.php | src/Drivers/Imagick/Modifiers/CropModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use ImagickPixel;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\CropModifier as GenericCropModifier;
class CropModifier extends GenericCropModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
// decode background color
$background = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->background)
);
// create empty container imagick to rebuild core
$imagick = new Imagick();
// save resolution to add it later
$resolution = $image->resolution()->perInch();
// define position of the image on the new canvas
$crop = $this->crop($image);
$position = [
($crop->pivot()->x() + $this->offset_x) * -1,
($crop->pivot()->y() + $this->offset_y) * -1,
];
foreach ($image as $frame) {
// create new frame canvas with modifiers background
$canvas = new Imagick();
$canvas->newImage($crop->width(), $crop->height(), $background, 'png');
$canvas->setImageResolution($resolution->x(), $resolution->y());
$canvas->setImageAlphaChannel(Imagick::ALPHACHANNEL_SET); // or ALPHACHANNEL_ACTIVATE?
// set animation details
if ($image->isAnimated()) {
$canvas->setImageDelay($frame->native()->getImageDelay());
$canvas->setImageIterations($frame->native()->getImageIterations());
$canvas->setImageDispose($frame->native()->getImageDispose());
}
// make the rectangular position of the original image transparent
// so that we can later place the original on top. this preserves
// the transparency of the original and shows the background color
// of the modifier in the other areas. if the original image has no
// transparent area the rectangular transparency will be covered by
// the original.
$clearer = new Imagick();
$clearer->newImage(
$frame->native()->getImageWidth(),
$frame->native()->getImageHeight(),
new ImagickPixel('black'),
);
$canvas->compositeImage($clearer, Imagick::COMPOSITE_DSTOUT, ...$position);
// place original frame content onto prepared frame canvas
$canvas->compositeImage($frame->native(), Imagick::COMPOSITE_DEFAULT, ...$position);
// add newly built frame to container imagick
$imagick->addImage($canvas);
}
// replace imagick in the original image
$image->core()->setNative($imagick);
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/FillModifier.php | src/Drivers/Imagick/Modifiers/FillModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use ImagickDraw;
use ImagickPixel;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\FillModifier as ModifiersFillModifier;
class FillModifier extends ModifiersFillModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$pixel = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->color)
);
foreach ($image->core()->native() as $frame) {
if ($this->hasPosition()) {
$this->floodFillWithColor($frame, $pixel);
} else {
$this->fillAllWithColor($frame, $pixel);
}
}
return $image;
}
private function floodFillWithColor(Imagick $frame, ImagickPixel $pixel): void
{
$target = $frame->getImagePixelColor(
$this->position->x(),
$this->position->y()
);
$frame->floodfillPaintImage(
$pixel,
100,
$target,
$this->position->x(),
$this->position->y(),
false,
Imagick::CHANNEL_ALL
);
}
private function fillAllWithColor(Imagick $frame, ImagickPixel $pixel): void
{
$draw = new ImagickDraw();
$draw->setFillColor($pixel);
$draw->rectangle(0, 0, $frame->getImageWidth(), $frame->getImageHeight());
$frame->drawImage($draw);
// deactive alpha channel when image was filled with opaque color
if ($pixel->getColorValue(Imagick::COLOR_ALPHA) == 1) {
$frame->setImageAlphaChannel(Imagick::ALPHACHANNEL_DEACTIVATE);
}
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ColorizeModifier.php | src/Drivers/Imagick/Modifiers/ColorizeModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ColorizeModifier as GenericColorizeModifier;
class ColorizeModifier extends GenericColorizeModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$red = $this->normalizeLevel($this->red);
$green = $this->normalizeLevel($this->green);
$blue = $this->normalizeLevel($this->blue);
foreach ($image as $frame) {
$qrange = $frame->native()->getQuantumRange();
$frame->native()->levelImage(0, $red, $qrange['quantumRangeLong'], Imagick::CHANNEL_RED);
$frame->native()->levelImage(0, $green, $qrange['quantumRangeLong'], Imagick::CHANNEL_GREEN);
$frame->native()->levelImage(0, $blue, $qrange['quantumRangeLong'], Imagick::CHANNEL_BLUE);
}
return $image;
}
private function normalizeLevel(int $level): int
{
return $level > 0 ? intval(round($level / 5)) : intval(round(($level + 100) / 100));
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php | src/Drivers/Imagick/Modifiers/ColorspaceModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\ColorspaceInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ColorspaceModifier as GenericColorspaceModifier;
class ColorspaceModifier extends GenericColorspaceModifier implements SpecializedInterface
{
/**
* Map own colorspace classname to Imagick classnames
*
* @var array<string, int>
*/
protected static array $mapping = [
RgbColorspace::class => Imagick::COLORSPACE_SRGB,
CmykColorspace::class => Imagick::COLORSPACE_CMYK,
];
public function apply(ImageInterface $image): ImageInterface
{
$colorspace = $this->targetColorspace();
$imagick = $image->core()->native();
$imagick->transformImageColorspace(
$this->getImagickColorspace($colorspace)
);
return $image;
}
/**
* @throws NotSupportedException
*/
private function getImagickColorspace(ColorspaceInterface $colorspace): int
{
if (!array_key_exists($colorspace::class, self::$mapping)) {
throw new NotSupportedException('Given colorspace is not supported.');
}
return self::$mapping[$colorspace::class];
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/FlopModifier.php | src/Drivers/Imagick/Modifiers/FlopModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\FlopModifier as ModifiersFlopModifier;
class FlopModifier extends ModifiersFlopModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->flopImage();
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/PixelateModifier.php | src/Drivers/Imagick/Modifiers/PixelateModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\PixelateModifier as GenericPixelateModifier;
class PixelateModifier extends GenericPixelateModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$this->pixelateFrame($frame);
}
return $image;
}
protected function pixelateFrame(FrameInterface $frame): void
{
$size = $frame->size();
$frame->native()->scaleImage(
(int) round(max(1, $size->width() / $this->size)),
(int) round(max(1, $size->height() / $this->size))
);
$frame->native()->scaleImage($size->width(), $size->height());
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/TrimModifier.php | src/Drivers/Imagick/Modifiers/TrimModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\NotSupportedException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\TrimModifier as GenericTrimModifier;
class TrimModifier extends GenericTrimModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
if ($image->isAnimated()) {
throw new NotSupportedException('Trim modifier cannot be applied to animated images.');
}
$imagick = $image->core()->native();
$imagick->trimImage(($this->tolerance / 100 * $imagick->getQuantum()) / 1.5);
$imagick->setImagePage(0, 0, 0, 0);
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/InvertModifier.php | src/Drivers/Imagick/Modifiers/InvertModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\InvertModifier as GenericInvertModifier;
class InvertModifier extends GenericInvertModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->negateImage(false);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/DrawRectangleModifier.php | src/Drivers/Imagick/Modifiers/DrawRectangleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawRectangleModifier as GenericDrawRectangleModifier;
class DrawRectangleModifier extends GenericDrawRectangleModifier implements SpecializedInterface
{
/**
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
$drawing = new ImagickDraw();
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
$drawing->setFillColor($background_color);
if ($this->drawable->hasBorder()) {
$drawing->setStrokeColor($border_color);
$drawing->setStrokeWidth($this->drawable->borderSize());
}
// build rectangle
$drawing->rectangle(
$this->drawable->position()->x(),
$this->drawable->position()->y(),
$this->drawable->position()->x() + $this->drawable->width(),
$this->drawable->position()->y() + $this->drawable->height()
);
foreach ($image as $frame) {
$frame->native()->drawImage($drawing);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/StripMetaModifier.php | src/Drivers/Imagick/Modifiers/StripMetaModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Collection;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
class StripMetaModifier implements ModifierInterface, SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see Intervention\Image\Interfaces\ModifierInterface::apply()
*/
public function apply(ImageInterface $image): ImageInterface
{
// preserve icc profiles
$profiles = $image->core()->native()->getImageProfiles('icc');
// remove meta data
$image->core()->native()->stripImage();
$image->setExif(new Collection());
if ($profiles !== []) {
// re-apply icc profiles
$image->core()->native()->profileImage("icc", $profiles['icc']);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/AlignRotationModifier.php | src/Drivers/Imagick/Modifiers/AlignRotationModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\AlignRotationModifier as GenericAlignRotationModifier;
class AlignRotationModifier extends GenericAlignRotationModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
switch ($image->core()->native()->getImageOrientation()) {
case Imagick::ORIENTATION_TOPRIGHT: // 2
$image->core()->native()->flopImage();
break;
case Imagick::ORIENTATION_BOTTOMRIGHT: // 3
$image->core()->native()->rotateImage("#000", 180);
break;
case Imagick::ORIENTATION_BOTTOMLEFT: // 4
$image->core()->native()->rotateImage("#000", 180);
$image->core()->native()->flopImage();
break;
case Imagick::ORIENTATION_LEFTTOP: // 5
$image->core()->native()->rotateImage("#000", -270);
$image->core()->native()->flopImage();
break;
case Imagick::ORIENTATION_RIGHTTOP: // 6
$image->core()->native()->rotateImage("#000", -270);
break;
case Imagick::ORIENTATION_RIGHTBOTTOM: // 7
$image->core()->native()->rotateImage("#000", -90);
$image->core()->native()->flopImage();
break;
case Imagick::ORIENTATION_LEFTBOTTOM: // 8
$image->core()->native()->rotateImage("#000", -90);
break;
}
// set new orientation in image
$image->core()->native()->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/DrawPolygonModifier.php | src/Drivers/Imagick/Modifiers/DrawPolygonModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use ImagickPixel;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawPolygonModifier as GenericDrawPolygonModifier;
class DrawPolygonModifier extends GenericDrawPolygonModifier implements SpecializedInterface
{
/**
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
$drawing = new ImagickDraw();
$drawing->setFillColor(new ImagickPixel('transparent')); // defaults to no backgroundColor
if ($this->drawable->hasBackgroundColor()) {
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
$drawing->setFillColor($background_color);
}
if ($this->drawable->hasBorder()) {
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
$drawing->setStrokeColor($border_color);
$drawing->setStrokeWidth($this->drawable->borderSize());
}
$drawing->polygon($this->points());
foreach ($image as $frame) {
$frame->native()->drawImage($drawing);
}
return $image;
}
/**
* Return points of drawable in processable form for ImagickDraw
*
* @return array<array<string, int>>
*/
private function points(): array
{
$points = [];
foreach ($this->drawable as $point) {
$points[] = ['x' => $point->x(), 'y' => $point->y()];
}
return $points;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ScaleModifier.php | src/Drivers/Imagick/Modifiers/ScaleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ScaleModifier extends ResizeModifier
{
protected function getAdjustedSize(ImageInterface $image): SizeInterface
{
return $image->size()->scale($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/Imagick/Modifiers/ContainModifier.php | src/Drivers/Imagick/Modifiers/ContainModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use ImagickPixel;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ContainModifier as GenericContainModifier;
class ContainModifier extends GenericContainModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$crop = $this->getCropSize($image);
$resize = $this->getResizeSize($image);
$transparent = new ImagickPixel('transparent');
$background = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->background)
);
foreach ($image as $frame) {
$frame->native()->scaleImage(
$crop->width(),
$crop->height(),
);
$frame->native()->setBackgroundColor($transparent);
$frame->native()->setImageBackgroundColor($transparent);
$frame->native()->extentImage(
$resize->width(),
$resize->height(),
$crop->pivot()->x() * -1,
$crop->pivot()->y() * -1
);
if ($resize->width() > $crop->width()) {
// fill new emerged background
$draw = new ImagickDraw();
$draw->setFillColor($background);
$delta = abs($crop->pivot()->x());
if ($delta > 0) {
$draw->rectangle(
0,
0,
$delta - 1,
$resize->height()
);
}
$draw->rectangle(
$crop->width() + $delta,
0,
$resize->width(),
$resize->height()
);
$frame->native()->drawImage($draw);
}
if ($resize->height() > $crop->height()) {
// fill new emerged background
$draw = new ImagickDraw();
$draw->setFillColor($background);
$delta = abs($crop->pivot()->y());
if ($delta > 0) {
$draw->rectangle(
0,
0,
$resize->width(),
$delta - 1
);
}
$draw->rectangle(
0,
$crop->height() + $delta,
$resize->width(),
$resize->height()
);
$frame->native()->drawImage($draw);
}
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/BrightnessModifier.php | src/Drivers/Imagick/Modifiers/BrightnessModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\BrightnessModifier as GenericBrightnessModifier;
class BrightnessModifier extends GenericBrightnessModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->modulateImage(100 + $this->level, 100, 100);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/DrawEllipseModifier.php | src/Drivers/Imagick/Modifiers/DrawEllipseModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawEllipseModifier as GenericDrawEllipseModifier;
class DrawEllipseModifier extends GenericDrawEllipseModifier implements SpecializedInterface
{
/**
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
foreach ($image as $frame) {
$drawing = new ImagickDraw();
$drawing->setFillColor($background_color);
if ($this->drawable->hasBorder()) {
$drawing->setStrokeWidth($this->drawable->borderSize());
$drawing->setStrokeColor($border_color);
}
$drawing->ellipse(
$this->drawable->position()->x(),
$this->drawable->position()->y(),
$this->drawable->width() / 2,
$this->drawable->height() / 2,
0,
360
);
$frame->native()->drawImage($drawing);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/GammaModifier.php | src/Drivers/Imagick/Modifiers/GammaModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\GammaModifier as GenericGammaModifier;
class GammaModifier extends GenericGammaModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->gammaImage($this->gamma);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/CoverModifier.php | src/Drivers/Imagick/Modifiers/CoverModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\CoverModifier as GenericCoverModifier;
class CoverModifier extends GenericCoverModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$crop = $this->getCropSize($image);
$resize = $this->getResizeSize($crop);
foreach ($image as $frame) {
$frame->native()->cropImage(
$crop->width(),
$crop->height(),
$crop->pivot()->x(),
$crop->pivot()->y()
);
$frame->native()->scaleImage(
$resize->width(),
$resize->height()
);
$frame->native()->setImagePage(0, 0, 0, 0);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ProfileModifier.php | src/Drivers/Imagick/Modifiers/ProfileModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ProfileModifier as GenericProfileModifier;
class ProfileModifier extends GenericProfileModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$imagick = $image->core()->native();
$result = $imagick->profileImage('icc', (string) $this->profile);
if ($result === false) {
throw new ColorException('ICC color profile could not be set.');
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/SliceAnimationModifier.php | src/Drivers/Imagick/Modifiers/SliceAnimationModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\SliceAnimationModifier as GenericSliceAnimationModifier;
class SliceAnimationModifier extends GenericSliceAnimationModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
if ($this->offset >= $image->count()) {
throw new AnimationException('Offset is not in the range of frames.');
}
$image->core()->slice($this->offset, $this->length);
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ScaleDownModifier.php | src/Drivers/Imagick/Modifiers/ScaleDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ScaleDownModifier extends ResizeModifier
{
protected function getAdjustedSize(ImageInterface $image): SizeInterface
{
return $image->size()->scaleDown($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/Imagick/Modifiers/FlipModifier.php | src/Drivers/Imagick/Modifiers/FlipModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\FlipModifier as GenericFlipModifier;
class FlipModifier extends GenericFlipModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->flipImage();
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ProfileRemovalModifier.php | src/Drivers/Imagick/Modifiers/ProfileRemovalModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ProfileRemovalModifier as GenericProfileRemovalModifier;
class ProfileRemovalModifier extends GenericProfileRemovalModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$imagick = $image->core()->native();
$result = $imagick->profileImage('icc', null);
if ($result === false) {
throw new ColorException('ICC color profile could not be removed.');
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/GreyscaleModifier.php | src/Drivers/Imagick/Modifiers/GreyscaleModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\GreyscaleModifier as GenericGreyscaleModifier;
class GreyscaleModifier extends GenericGreyscaleModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->modulateImage(100, 0, 100);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ResolutionModifier.php | src/Drivers/Imagick/Modifiers/ResolutionModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ResolutionModifier as GenericResolutionModifier;
class ResolutionModifier extends GenericResolutionModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$imagick = $image->core()->native();
$imagick->setImageResolution($this->x, $this->y);
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ResizeDownModifier.php | src/Drivers/Imagick/Modifiers/ResizeDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SizeInterface;
class ResizeDownModifier extends ResizeModifier
{
protected function getAdjustedSize(ImageInterface $image): SizeInterface
{
return $image->size()->resizeDown($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/Imagick/Modifiers/RemoveAnimationModifier.php | src/Drivers/Imagick/Modifiers/RemoveAnimationModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\RemoveAnimationModifier as GenericRemoveAnimationModifier;
class RemoveAnimationModifier extends GenericRemoveAnimationModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
// create new imagick with just one image
$imagick = new Imagick();
$frame = $this->selectedFrame($image);
$imagick->addImage($frame->native()->getImage());
// set new imagick to image
$image->core()->setNative($imagick);
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/QuantizeColorsModifier.php | src/Drivers/Imagick/Modifiers/QuantizeColorsModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\QuantizeColorsModifier as GenericQuantizeColorsModifier;
class QuantizeColorsModifier extends GenericQuantizeColorsModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
if ($this->limit <= 0) {
throw new InputException('Quantization limit must be greater than 0.');
}
// no color reduction if the limit is higher than the colors in the img
if ($this->limit > $image->core()->native()->getImageColors()) {
return $image;
}
foreach ($image as $frame) {
$frame->native()->quantizeImage(
$this->limit,
$frame->native()->getImageColorspace(),
0,
false,
false
);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/PlaceModifier.php | src/Drivers/Imagick/Modifiers/PlaceModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Imagick;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\PlaceModifier as GenericPlaceModifier;
class PlaceModifier extends GenericPlaceModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$watermark = $this->driver()->handleInput($this->element);
$position = $this->getPosition($image, $watermark);
// set opacity of watermark
if ($this->opacity < 100) {
$watermark->core()->native()->setImageAlphaChannel(Imagick::ALPHACHANNEL_SET);
$watermark->core()->native()->evaluateImage(
Imagick::EVALUATE_DIVIDE,
$this->opacity > 0 ? 100 / $this->opacity : 1000,
Imagick::CHANNEL_ALPHA,
);
}
foreach ($image as $frame) {
$frame->native()->compositeImage(
$watermark->core()->native(),
Imagick::COMPOSITE_DEFAULT,
$position->x(),
$position->y()
);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/BlurModifier.php | src/Drivers/Imagick/Modifiers/BlurModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\BlurModifier as GenericBlurModifier;
class BlurModifier extends GenericBlurModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->blurImage($this->amount, 0.5 * $this->amount);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/SharpenModifier.php | src/Drivers/Imagick/Modifiers/SharpenModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\SharpenModifier as GenericSharpenModifier;
class SharpenModifier extends GenericSharpenModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->unsharpMaskImage(1, 1, $this->amount / 6.25, 0);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ResizeCanvasModifier.php | src/Drivers/Imagick/Modifiers/ResizeCanvasModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ResizeCanvasModifier as GenericResizeCanvasModifier;
class ResizeCanvasModifier extends GenericResizeCanvasModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
$cropSize = $this->cropSize($image);
$image->modify(new CropModifier(
$cropSize->width(),
$cropSize->height(),
$cropSize->pivot()->x(),
$cropSize->pivot()->y(),
$this->background,
));
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/ContrastModifier.php | src/Drivers/Imagick/Modifiers/ContrastModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\ContrastModifier as GenericContrastModifier;
class ContrastModifier extends GenericContrastModifier implements SpecializedInterface
{
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
$frame->native()->sigmoidalContrastImage($this->level > 0, abs($this->level / 4), 0);
}
return $image;
}
}
| php | MIT | 5f6d27d9fd56312c47f347929e7ac15345c605a1 | 2026-01-04T15:02:42.957046Z | false |
Intervention/image | https://github.com/Intervention/image/blob/5f6d27d9fd56312c47f347929e7ac15345c605a1/src/Drivers/Imagick/Modifiers/CoverDownModifier.php | src/Drivers/Imagick/Modifiers/CoverDownModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\GeometryException;
use Intervention\Image\Interfaces\SizeInterface;
class CoverDownModifier extends CoverModifier
{
/**
* @throws GeometryException
*/
public function getResizeSize(SizeInterface $size): SizeInterface
{
return $size->resizeDown($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/Imagick/Modifiers/DrawLineModifier.php | src/Drivers/Imagick/Modifiers/DrawLineModifier.php | <?php
declare(strict_types=1);
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use RuntimeException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\DrawLineModifier as GenericDrawLineModifier;
class DrawLineModifier extends GenericDrawLineModifier implements SpecializedInterface
{
/**
* @throws RuntimeException
*/
public function apply(ImageInterface $image): ImageInterface
{
$drawing = new ImagickDraw();
$drawing->setStrokeWidth($this->drawable->width());
$drawing->setFillOpacity(0);
$drawing->setStrokeColor(
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
$drawing->line(
$this->drawable->start()->x(),
$this->drawable->start()->y(),
$this->drawable->end()->x(),
$this->drawable->end()->y(),
);
foreach ($image as $frame) {
$frame->native()->drawImage($drawing);
}
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.