From 67691cd438105f27a275eabc123578484d0bf37c Mon Sep 17 00:00:00 2001 From: DiegoMarty Date: Mon, 16 May 2022 17:11:13 +0200 Subject: [PATCH 1/2] Fix conversion from float to int loses precision --- src/image/Image.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/image/Image.php b/src/image/Image.php index f26dc28f..473b0d63 100644 --- a/src/image/Image.php +++ b/src/image/Image.php @@ -1045,6 +1045,10 @@ public function _StrokeTTF($x, $y, $txt, $dir, $paragraph_align, &$aBoundingBox, // Do nothing the text is drawn at baseline by default } } + + $x = round($x); + $y = round($y); + imagettftext( $this->img, $this->font_size, @@ -1155,12 +1159,16 @@ public function _StrokeTTF($x, $y, $txt, $dir, $paragraph_align, &$aBoundingBox, $xl -= $bbox[0] / 2; $yl = $y - $yadj; //$xl = $xl- $xadj; + + $xl = round($xl); + $yl = round($yl - ($h - $fh) + $fh * $i); + imagettftext( $this->img, $this->font_size, $dir, $xl, - $yl - ($h - $fh) + $fh * $i, + $yl, $this->current_color, $this->font_file, $tmp[$i] From 043d65067ec6c58bc4395b5f5f581dcc17a5cee0 Mon Sep 17 00:00:00 2001 From: DiegoMarty Date: Mon, 16 May 2022 17:20:40 +0200 Subject: [PATCH 2/2] Force return int after round() --- src/image/Image.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/image/Image.php b/src/image/Image.php index 473b0d63..fd19e5bb 100644 --- a/src/image/Image.php +++ b/src/image/Image.php @@ -1046,8 +1046,8 @@ public function _StrokeTTF($x, $y, $txt, $dir, $paragraph_align, &$aBoundingBox, } } - $x = round($x); - $y = round($y); + $x = (int) round($x); + $y = (int) round($y); imagettftext( $this->img, @@ -1160,8 +1160,8 @@ public function _StrokeTTF($x, $y, $txt, $dir, $paragraph_align, &$aBoundingBox, $yl = $y - $yadj; //$xl = $xl- $xadj; - $xl = round($xl); - $yl = round($yl - ($h - $fh) + $fh * $i); + $xl = (int) round($xl); + $yl = (int) round($yl - ($h - $fh) + $fh * $i); imagettftext( $this->img,