ecartement texte

This commit is contained in:
Thibault Richy 2019-02-25 11:25:55 +01:00
parent b3e774391f
commit cf3abfc677

View file

@ -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)
{