Dev0ps's avatar

how to type long text in Intervention image

in font size 12 estimate 6-7 words come in one line and remaining words are disappearing due to they all are formatted in single line

is there any way to show long text in paragraph formatted way

or any kind of condition that print 6 words then increment coordinates (x and y-axis) and print remaining

code

   // create new Intervention Image
        $img = Image::make(public_path('img/')."/".'a11.jpg');
        $img->resize(500, 500);
        $img->brightness(-35);
        $img->text('The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.', 250, 200, function($font) {
            $font->file(public_path('fonts/Scream Real.ttf'));
            $font->size(12);
            $font->color('#fdf6e3');
            $font->align('center');
            $font->valign('top');
        });
0 likes
6 replies
Dev0ps's avatar

i find

$width       = 600;
$height      = 300;
$center_x    = $width / 2;
$center_y    = $height / 2;
$max_len     = 36;
$font_size   = 30;
$font_height = 20;

$text = 'The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog?';

$lines = explode("\n", wordwrap($text, $max_len)
$y     = $center_y - ((count($lines) - 1) * $font_height);
$img   = \Image::canvas($width, $height, '#777');

foreach ($lines as $line)
{
    $img->text($line, $center_x, $y, function($font) use ($font_size){
        $font->file(base_path('path/to/my/font.ttf'));
        $font->size($font_size);
        $font->color('#fdf6e3');
        $font->align('center');
        $font->valign('center');
    });

    $y += $font_height * 2;
}

return $img->response();

src= https://github.com/Intervention/image/issues/143

but I try this shows error

genrate error

 $lines = explode("\n", wordwrap($text, $max_len);

i added semi colon

jlrdw's avatar

CSS and media queries if needed for mobile vs desktop. Could also place in div which would wrap text. But sounds like you need to learn some css.

Usage of bootstrap is not the same as actually learning css.

Dev0ps's avatar

i want to make an image in .png format

text+image

Cronix's avatar
$lines = explode("\n", wordwrap($text, $max_len);

You still have an error there. You're missing a closing )

1 like
Azhr-M's avatar

Here is the simplest solution,

$lines = explode("\n", wordwrap($description, 120)); // break line after 120 characters

for ($i = 0; $i < count($lines); $i++) {
    $offset = 820 + ($i * 50); // 50 is line height
    $cert->text($lines[$i], 110, $offset, function ($font) {
        $font->file('fonts/Roboto_Regular.ttf');
        $font->size(30);
        $font->color('#000000');
    });
}
4 likes

Please or to participate in this conversation.