Home » Php » php – write a text on an image with a filled background

php – write a text on an image with a filled background

Posted by: admin February 25, 2020 Leave a comment

Questions:

I need to write a text on an image with intervention image, but I want to write on a filled rectangle.
This is what I have right now:

$img = Image::make("url");
$img->text($eventTheatre->event->place->getName(), 10, $img->height() - 10, function($font) {
    $font->file(public_path('fonts/Roboto-Regular.ttf'));
    $font->size(48);
    $font->color('#ffffff');
    $font->angle(0);
});

I know there is rectangle function to draw a rectangle, but I do not know howto get the size of the rectangle based of the text written.

How to&Answers: