Skip to content

Commit

Permalink
Address GD compatibility issue when using PHP < 8.0.0
Browse files Browse the repository at this point in the history
fixes #3428
  • Loading branch information
bsweeney committed Apr 15, 2024
1 parent 0e242f5 commit 572b025
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Adapter/GD.php
Expand Up @@ -467,12 +467,17 @@ public function rectangle($x1, $y1, $w, $h, $color, $width, $style = [], $cap =
imagesetthickness($this->get_image(), $width);

if ($c === IMG_COLOR_STYLED) {
imagepolygon($this->get_image(), [
$points = [
$x1, $y1,
$x1 + $w, $y1,
$x1 + $w, $y1 + $h,
$x1, $y1 + $h
], $c);
];
if (version_compare(PHP_VERSION, "8.1.0", "<")) {
imagepolygon($this->get_image(), $points, count($points)/2, $c);
} else {
imagepolygon($this->get_image(), $points, $c);
}
} else {
imagerectangle($this->get_image(), $x1, $y1, $x1 + $w, $y1 + $h, $c);
}
Expand Down Expand Up @@ -570,9 +575,17 @@ public function polygon($points, $color, $width = null, $style = [], $fill = fal
imagesetthickness($this->get_image(), isset($width) ? $width : 0);

if ($fill) {
imagefilledpolygon($this->get_image(), $points, $c);
if (version_compare(PHP_VERSION, "8.1.0", "<")) {
imagefilledpolygon($this->get_image(), $points, count($points)/2, $c);
} else {
imagefilledpolygon($this->get_image(), $points, $c);
}
} else {
imagepolygon($this->get_image(), $points, $c);
if (version_compare(PHP_VERSION, "8.1.0", "<")) {
imagepolygon($this->get_image(), $points, count($points)/2, $c);
} else {
imagepolygon($this->get_image(), $points, $c);
}
}
}

Expand Down

0 comments on commit 572b025

Please sign in to comment.