From cf3abfc67725bb1a4d3ca78bd57848110b60f81b Mon Sep 17 00:00:00 2001 From: Thibault Richy Date: Mon, 25 Feb 2019 11:25:55 +0100 Subject: [PATCH] ecartement texte --- app/Traits/GenerateBR.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Traits/GenerateBR.php b/app/Traits/GenerateBR.php index 6cb46c8..b5642c5 100644 --- a/app/Traits/GenerateBR.php +++ b/app/Traits/GenerateBR.php @@ -46,7 +46,13 @@ trait GenerateBR { $boxMentions = imagettfbbox(7, 0, $arial, $txt_mentions); $white = imagecolorallocate($ImageMentionFond, 255, 255, 255); $black = imagecolorallocate($ImageMentionFond, 0, 0, 0); - imagettftext($ImageMentionFond , 7 , 0, (415/2)-(abs($boxMentions[4])-abs($boxMentions[6]))/2, 23, $black, $arial, $txt_mentions); + $lines_mentions = explode("\r\n", $txt_mentions); + $y = 4; + foreach ($lines_mentions as $line) { + $y = $y +13; + $this->imagettftextSp($ImageMentionFond , 7 , 0, (415/2)-(abs($boxMentions[4])-abs($boxMentions[6]))/2, $y, $black, $arial, $line, 1); + } + imagecolortransparent($ImageMentionFond, $white); imagecopy($mask, $ImageMentionFond, 335, 235, 0, 0, imagesx($ImageMentionFond), imagesy($ImageMentionFond)); @@ -123,6 +129,24 @@ trait GenerateBR { return "generation/".$coupon->coupon_code.".png"; } + function imagettftextSp($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0) { + if ($spacing == 0) { + imagettftext($image, $size, $angle, $x, $y, $color, $font, $text); + } else { + $temp_x = $x; + $temp_y = $y; + //to avoid special char problems + $char_array = preg_split('//u',$text, -1, PREG_SPLIT_NO_EMPTY); + foreach($char_array as $char) { + imagettftext($image, $size, $angle, $temp_x, $temp_y, $color, $font, $char); + $bbox = imagettfbbox($size, 0, $font, $char); + $temp_x += cos(deg2rad($angle)) * ($spacing + ($bbox[2] - $bbox[0])); + $temp_y -= sin(deg2rad($angle)) * ($spacing + ($bbox[2] - $bbox[0])); + } + } + } + + function imagettftext_contour($image, $fontsize, $angle, $x, $y, $color, $font, $text, $color_contour, $contour_haut=1, $contour_bas=1, $contour_gauche=1, $contour_droite=1) {