php-gdlabel/src/Elements/FrameElement.php

39 lines
1.4 KiB
PHP

<?php
namespace NoccyLabs\GdLabel\Elements;
use NoccyLabs\GdLabel\Element;
class FrameElement extends Element
{
protected function draw($gd, int $x, int $y, int $width, int $height, array $params)
{
$color = $this->getPropRgb("line-color");
if ($color === null) {
return;
}
$radius = (int)$this->getProp("border-radius", 0);
$thickness = (int)$this->getProp("line-width", 1);
\imagesetthickness($gd, $thickness);
if ($radius == 0) {
\imagerectangle($gd, $x, $y, $x + $width, $y + $height, $color);
} else {
\imageline($gd, $x + $radius, $y, $x + $width - $radius, $y, $color);
\imageline($gd, $x + $radius, $y + $height, $x + $width - $radius, $y + $height, $color);
\imageline($gd, $x, $y + $radius, $x, $y + $height - $radius, $color);
\imageline($gd, $x + $width, $y + $radius, $x + $width, $y + $height - $radius, $color);
\imagearc($gd, $x + $radius, $y + $radius, $radius * 2, $radius * 2, 180, 270, $color);
\imagearc($gd, $x + $radius, $y + $height - $radius, $radius * 2, $radius * 2, 90, 180, $color);
\imagearc($gd, $x + $width - $radius, $y + $radius, $radius * 2, $radius * 2, 270, 0, $color);
\imagearc($gd, $x + $width - $radius, $y + $height - $radius, $radius * 2, $radius * 2, 0, 90, $color);
}
\imagesetthickness($gd, 1);
}
}