Skip to content

Commit

Permalink
TASK: Render border with GD
Browse files Browse the repository at this point in the history
The gd method imagesetthickness seems not to work in all cases.
This change alters the drawing of the border to a loop of 1px lines
to deal with this.

Additionally the border is now always 10px + 10px wide.
  • Loading branch information
mficzel committed Aug 31, 2018
1 parent ccb3bfd commit e388f9c
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions Classes/Controller/DummyImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,36 +180,25 @@ function (Point $point) use ($factor, $xoffset, $yoffset) {
*/
protected function renderBorder(ImageInterface $image, ColorInterface $foregroundColor, ColorInterface $backgroundColor,int $width, int $height): void
{
$borderWidth = ($width + $height) / 100;

$b1 = (int)round($borderWidth * 0.5);
$b2 = (int)round($borderWidth);
$b3 = (int)round($borderWidth * 1.5);

$image->draw()->polygon(
[
new Point($b1,$b1),
new Point($width - $b1,$b1),
new Point($width - $b1 ,$height - $b1),
new Point($b1,$height- $b1)
],
$backgroundColor,
false,
$b2
);

$image->draw()->polygon(
[
new Point($b3,$b3),
new Point($width - $b3, $b3),
new Point($width - $b3, $height - $b3),
new Point($b3, $height - $b3)
],
$foregroundColor,
false,
$b2
);

$borderWidth = 20;

for ($i = 0; $i <= $borderWidth; $i++) {
$x1 = $i;
$x2 = $width - $i;
$y1 = $i;
$y2 = $height - $i;
$image->draw()->polygon(
[
new Point($x1, $y1),
new Point($x2, $y1),
new Point($x2, $y2),
new Point($x1, $y2)
],
($i > $borderWidth / 2 ? $foregroundColor : $backgroundColor),
false,
1
);
}
}

/**
Expand Down Expand Up @@ -241,4 +230,4 @@ protected function renderText(ImageInterface $image, ColorInterface $textColor,
$image->draw()->text($text, $actualFont, $centeredTextPosition);
}

}
}

0 comments on commit e388f9c

Please sign in to comment.