A problem with laravel using the Image package
世界只因有你
世界只因有你 2017-05-16 16:49:27
0
1
1370

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, 0in 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 characters1234567890in 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.

世界只因有你
世界只因有你

reply all (1)
小葫芦

About the second parameter, this is what the document says

Font File

public Intervention\Image\Font file(string $filepath)

Set path to a True Type Font file or a integer value between 1 and 5 for one of the GD library internal fonts. Default: 1

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 tofoo/bar而不是/foo/bar.

  • in the example
  • The second type, integers 1 - 5 use built-in fonts.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!