search

Home  >  Q&A  >  body text

A problem with laravel using the Image package

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 characters 1234567890 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.

世界只因有你世界只因有你2808 days ago1449

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-16 16:51:27

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

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

    reply
    0
  • Cancelreply