Файл: vendor/intervention/image/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php
Строк: 117
<?php
declare(strict_types=1);
namespace InterventionImageDriversGdModifiers;
use GdImage;
use InterventionImageExceptionsColorDecoderException;
use InterventionImageExceptionsModifierException;
use InterventionImageExceptionsStateException;
use InterventionImageInterfacesImageInterface;
use InterventionImageInterfacesPointInterface;
use InterventionImageInterfacesSpecializedInterface;
use InterventionImageModifiersDrawRectangleModifier as GenericDrawRectangleModifier;
class DrawRectangleModifier extends GenericDrawRectangleModifier implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see ModifierInterface::apply()
*
* @throws ModifierException
* @throws StateException
* @throws ColorDecoderException
*/
public function apply(ImageInterface $image): ImageInterface
{
$position = $this->drawable->position();
$backgroundColor = $this->driver()->colorProcessor($image)->export($this->backgroundColor());
$borderColor = $this->driver()->colorProcessor($image)->export($this->borderColor());
foreach ($image as $frame) {
if ($this->drawable->hasBackgroundColor()) {
$this->drawRectangleBackground($frame->native(), $position, $backgroundColor);
}
if ($this->drawable->hasBorder()) {
$this->drawRectangleBorder($frame->native(), $position, $borderColor);
}
}
return $image;
}
/**
* Draw background of rectangle.
*
* @throws ModifierException
*/
private function drawRectangleBackground(GdImage $canvas, PointInterface $position, int $backgroundColor): void
{
imagealphablending($canvas, true);
imagesetthickness($canvas, 0);
imagefilledrectangle(
$canvas,
$position->x(),
$position->y(),
$position->x() + $this->drawable->width(),
$position->y() + $this->drawable->height(),
$backgroundColor,
);
}
/**
* Draw border of rectangle.
*
* @throws ModifierException
*/
private function drawRectangleBorder(GdImage $canvas, PointInterface $position, int $borderColor): void
{
imagealphablending($canvas, true);
imagesetthickness($canvas, $this->drawable->borderSize());
imagerectangle(
$canvas,
$position->x(),
$position->y(),
$position->x() + $this->drawable->width(),
$position->y() + $this->drawable->height(),
$borderColor,
);
}
}