John Davidson

php - How to use text stroke effect in image intervention?

0 comments
Message:


I am using the Image Intervention package to print text on image. But I want this kind of stroke to be the same as this sample image. How to do that?


https://prnt.sc/sIpJBJNzwQhF



My Answer:
To achieve a text stroke effect in Image Intervention, you can use the `textOutline()` method along with the `text()` method. Here's an example code snippet to add text with a stroke effect to an image:

php
use Intervention\Image\ImageManagerStatic;

// Load the image
$image = ImageManagerStatic::make('path/to/your/image.jpg');

// Add text with stroke effect
$image->text('Your Text Here', 100, 100, function($font) {
$font->file(public_path('path/to/your/font.ttf'));
$font->size(24);
$font->color('#ffffff');
$font->align('center');
$font->valign('top');
$font->textOutline(2, '#000000'); // Set the stroke width and color
});

// Save the image
$image->save('path/to/save/image.jpg');


In the above code, the `textOutline()` method is used to set the stroke width and color for the text. You can adjust the values as needed to achieve the desired stroke effect.

Rate this post

3 of 5 based on 2392 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us