Reputation: 2538
I created an image 500X200 with white background and text on it. How can I wrap "Text" if it will be long in GD.
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill ( $image, 0, 0, $white );
...
imagettftext($image, 18, 0, $x, 100, $black, $font, "text");
Upvotes: 2
Views: 2569
Reputation: 3037
GD supports rotation, vertical and horizontal alignments, configurable line heights and leading, word wrap (obviously), character wrap, and text outlines. While this frankly belongs in a class (or a namespace) due its size, it’s in a function. You’re free to trim away unneeded functionality.
Example usage:
$size = 14;
$angle = 34;
$left = 10;
$top = 40;
$color = imagecolorallocate($im, 255, 0, 0);
$fontfile = "arial.ttf";
$text = "Test";
$opt = array('width' => 300,'line_height' => 15,'orientation' =>array(ORIENTATION_TOP, ORIENTATION_LEFT),
'align' => ALIGN_LEFT,
'v_align' => VALIGN_TOP,
'outlines' = array(
array(5, imagecolorallocate($im, 0, 255, 0)),
array(2, imagecolorallocate($im, 0, 0, 255)),
),
// More options
);
imagettftextboxopt($im, $size, $angle, $left, $top, $color, $fontfile, $text, $opt);
UPDATE:
And also refer this question
Upvotes: 3