From dc2ef9c62807b8b339899b97f6597b770f40d492 Mon Sep 17 00:00:00 2001 From: Maxim Yalagin Date: Fri, 28 Jun 2024 19:57:28 +0700 Subject: [PATCH] fix: Remove implicit conversion from float to int (#234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon André --- src/Rasterization/Renderers/EllipseRenderer.php | 14 ++++---------- src/Rasterization/Renderers/LineRenderer.php | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Rasterization/Renderers/EllipseRenderer.php b/src/Rasterization/Renderers/EllipseRenderer.php index 7c026e27..9feee808 100644 --- a/src/Rasterization/Renderers/EllipseRenderer.php +++ b/src/Rasterization/Renderers/EllipseRenderer.php @@ -42,7 +42,7 @@ protected function prepareRenderParams(array $options, Transform $transform, ?Fo */ protected function renderFill($image, $params, int $color): void { - imagefilledellipse($image, $params['cx'], $params['cy'], $params['width'], $params['height'], $color); + imagefilledellipse($image, (int)round($params['cx']), (int)round($params['cy']), (int)round($params['width']), (int)round($params['height']), $color); } /** @@ -52,16 +52,10 @@ protected function renderStroke($image, $params, int $color, float $strokeWidth) { imagesetthickness($image, round($strokeWidth)); - $width = $params['width']; - if ($width % 2 === 0) { - $width += 1; - } - $height = $params['height']; - if ($height % 2 === 0) { - $height += 1; - } + $width = (int)round($params['width']) | 1; + $height = (int)round($params['height']) | 1; // imageellipse ignores imagesetthickness; draw arc instead - imagearc($image, $params['cx'], $params['cy'], $width, $height, 0, 360, $color); + imagearc($image, (int)round($params['cx']), (int)round($params['cy']), $width, $height, 0, 360, $color); } } diff --git a/src/Rasterization/Renderers/LineRenderer.php b/src/Rasterization/Renderers/LineRenderer.php index dcb4309a..a31d3d44 100644 --- a/src/Rasterization/Renderers/LineRenderer.php +++ b/src/Rasterization/Renderers/LineRenderer.php @@ -51,6 +51,6 @@ protected function renderFill($image, $params, int $color): void protected function renderStroke($image, $params, int $color, float $strokeWidth): void { imagesetthickness($image, round($strokeWidth)); - imageline($image, $params['x1'], $params['y1'], $params['x2'], $params['y2'], $color); + imageline($image, (int)round($params['x1']), (int)round($params['y1']), (int)round($params['x2']), (int)round($params['y2']), $color); } }