Skip to content

Commit

Permalink
Merge pull request #3 from sitegeist/task/renderBorderAlsoWithGd
Browse files Browse the repository at this point in the history
TASK: Render border with GD
  • Loading branch information
mficzel committed Aug 31, 2018
2 parents ccb3bfd + e388f9c commit 55019bb
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 55019bb

Please sign in to comment.