Documentation here:
http://image.intervention.io/...
There is an example in the document, which contains this piece of code:
$img->text('foo', 0, 0, function($font) { $font->file('foo/bar.ttf'); $font->size(24); $font->color('#fdf6e3'); $font->align('center'); $font->valign('top'); $font->angle(45); });
The problem with the above example:
The reference coordinates, that is,0, 0
in the above code refers to the four corners of a picture Which corner of?
Referring to the above example, I wrote a demo, as follows:
Image::canvas(160, 20)->text('1234567890', 80, 10, function ($font) { $font->file('/fonts/Elephant.ttf'); $font->size(24); $font->align('center'); $font->valign('middle'); });
The functions of the above code are:
1. Create a 160*20 pixel picture;
2. Write the characters1234567890
in the center of the picture.
Questions about my demo:
1. Add$font->file('/fonts/Elephant.ttf');
. Laravel will report an error. There is something wrong with the GD library. I don’t know how to solve it:
NotSupportedException in Font.php line 30: Internal GD font () not available. Use only 1-5.
2. Remove the sentence$font->file('/fonts/Elephant.ttf');
and you can generate a picture, but$font->size() ;
does not work. No matter what value is set in size(), the text size will not change. The main reason is that it does not fill the entire image, but leaves too much white space. The generated image is as follows:
Please help me find out what's going on.
About the second parameter, this is what the document says
That is to say, 2 types of values can be passed:
The first type, path . should be relative to the web directory or relative to the current file directory, similar to
foo/bar
而不是/foo/bar
.The second type, integers 1 - 5 use built-in fonts.