Jijesh Cherayi
Jijesh Cherayi

Reputation: 1125

Laravel intervention image adding text with font is showing error

I'm using Intervention package in Laravel5 for Inserting a text in image, and its is working well. But if I add font(.ttf) it shows the following error. The directory is correct.

NotSupportedException in Font.php line 30: Internal GD font () not available. Use only 1-5.

        $image = Image::make(public_path('/userimage/') . "user.png");
        $image->text('text string', 10, 5, function($font) {
            $font->file(asset('/web/fonts/OpenSans-Regular.ttf'));
            $font->size(50);
            $font->color('#fdf6e3');
            $font->angle(45);
        });

Upvotes: 2

Views: 10686

Answers (6)

Chandima
Chandima

Reputation: 2081

Removing public_path() worked for me. 

   

     $image = Image::make('userimage/') . "user.png";
                $image->text('text string', 10, 5, function($font) {
                    $font->file('web/fonts/OpenSans-Regular.ttf');
                    $font->size(50);
                    $font->color('#fdf6e3');
                    $font->angle(45);
                });

Upvotes: 1

bandzi
bandzi

Reputation: 31

Try this: $font->file(public_path('fontnameExample.ttf'));

Upvotes: 2

serpentow
serpentow

Reputation: 196

Use base_path() instead of asset().

Example:

$font->file(base_path('public/web/fonts/OpenSans-Regular.ttf'));

Upvotes: 3

Robert C.
Robert C.

Reputation: 31

  1. The GD library does not support custom fonts. You are supposed to use Imagick. Go to config/image.php and edit the driver value to 'imagick' (after you actually install the extension for it):

    'driver' => 'imagick'

  2. asset('/web/fonts/OpenSans-Regular.ttf') returns an URL. You have to provide a path. Use public_path('web/fonts/OpenSans-Regular.ttf') instead.

Upvotes: 3

Niraj Shah
Niraj Shah

Reputation: 15457

Two things you can try:

  • Remove the forward slash in the path to font file: $font->file(asset('web/fonts/OpenSans-Regular.ttf'));
  • Make sure the font file is readable by Laravel / Apache, run chmod 755 path/to/web/fonts/OpenSans-Regular.ttf just in case.

Upvotes: 1

neochief
neochief

Reputation: 567

I would do this:

  • Try removing leading slash in path.
  • Run dd(asset('/web/fonts/OpenSans-Regular.ttf')) and see if it matches expected path.

Upvotes: 1

Related Questions