Image: Multiline text centering

Created on 29 Aug 2014  路  8Comments  路  Source: Intervention/image

Text methods callback parameter align doesn't center multiline text. I'm using GD library. See the image below.

image

bug nextversion

Most helpful comment

Hope this will help someone:
$textToBeShown ="The man, the dwarf and the girlguardian";
$img2 = Image::canvas(300,250);
// inserts character where string is to be split into new line (after 15 characters, keeping words intact)
$string = wordwrap($textToBeShown,15,"|");
//create array of lines
$strings = explode("|",$string);
$i=3; //top position of string
//for each line added
foreach($strings as $string){
$img2->text($string, 150, $i, function($font) {
$font->file('fonts/RobotoCondensed-Bold.ttf');
$font->size(40);
$font->color('#826c61');
$font->align('center');
$font->valign('top');
});
$i=$i+42; //shift top postition down 42
}

All 8 comments

I'm aware of this problem. Multiline is problematic and needs to be fixed.

Any timespan when this bug is fixed?

@julesbloemen No, sorry.

@kivivuori Did you manage to find a work arround so far?

@julesbloemen I used another library for rendering the text. This one https://github.com/stil/gd-text

I've same problem about centered text.

Hope this will help someone:
$textToBeShown ="The man, the dwarf and the girlguardian";
$img2 = Image::canvas(300,250);
// inserts character where string is to be split into new line (after 15 characters, keeping words intact)
$string = wordwrap($textToBeShown,15,"|");
//create array of lines
$strings = explode("|",$string);
$i=3; //top position of string
//for each line added
foreach($strings as $string){
$img2->text($string, 150, $i, function($font) {
$font->file('fonts/RobotoCondensed-Bold.ttf');
$font->size(40);
$font->color('#826c61');
$font->align('center');
$font->valign('top');
});
$i=$i+42; //shift top postition down 42
}

@setvir Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bkkrishna picture bkkrishna  路  7Comments

ludo237 picture ludo237  路  8Comments

knif3rdev picture knif3rdev  路  6Comments

ctf0 picture ctf0  路  4Comments

johnvoncolln picture johnvoncolln  路  7Comments