Image: Cannot set custom font file.

Created on 3 Jun 2014  路  8Comments  路  Source: Intervention/image

Hello.

I'm trying to do this simple callback in Laravel 4 with PHP 5.5.13 (latest stable at the moment). I've downloaded a font from DaFont called Alpaca and stored it in public/fonts/alpaca/ . I want to use, so I made up this

$dealImage->text("Text on Image", 5, 5, function($font) {
                $font->file(asset('fonts/alpaca/alpaca_ttf));
                $font->size(120);
                $font->color('#00000');
                $font->align('left');
                $font->valign('top');
});

But the application returns an exception

Intervention \ Image \ Exception \ NotSupportedException
Internal GD font () not available. Use only 1-5.`

I don't know how to setup the custom font. I've read the entire documentation but no clue on some configuration or similar so I tough it might be an issue.

Most helpful comment

isn't asset() a function used to generate the url?
Don't you want public_path('fonts/alpaca/alpaca_ttf')?

So this would become:

$dealImage->text("Text on Image", 5, 5, function($font) {
    $font->file(public_path('fonts/alpaca/alpaca_ttf'));
    $font->size(120);
    $font->color('#00000');
    $font->align('left');
    $font->valign('top');
});

Also when you set the font in your example your missing the final single quote from the font string.

All 8 comments

You have to link directly to a TTF file.

$font->file(asset('fonts/alpaca/whereever/alpaca.ttf'));

isn't asset() a function used to generate the url?
Don't you want public_path('fonts/alpaca/alpaca_ttf')?

So this would become:

$dealImage->text("Text on Image", 5, 5, function($font) {
    $font->file(public_path('fonts/alpaca/alpaca_ttf'));
    $font->size(120);
    $font->color('#00000');
    $font->align('left');
    $font->valign('top');
});

Also when you set the font in your example your missing the final single quote from the font string.

@olivervogel Yup sorry typo here. The problem still remains with the correct dot notation. Even if I try with a brand new font.

@djekl Dude thanks... I'm an idiot :smile: public_path() is the right answer!

@ludo237 Not a problem m8, made this mistake myself a few times

Guys any idea why this would result in a 8bit sketchy font instead of the one im specifying? I have confirmed that the path is accurate and that the font does exist when hitting the direct link to it.

$img = Image::canvas(345, 190);
        $img->text('Your Name Here',100,50, function($font) {
            $font->file(public_path('fonts/OpenSans-Light.ttf'));
            $font->size(27);
            $font->color('#222222');
        })->save('img/test.jpg');

if anyone is trying to access storage/app and not the public folder - i was able to utilize storage_path('app/fonts/abril-fatface.ttf')

 $imtimg->text('uparjanpatrika.com',530,400,function($font){ 
    $font->file(__DIR__.'/myfonts/proloybhaduri.ttf');
    $font->size(14);
    $font->color('#000000');
    $font->align('center');
    $font->valign('top');
}); 

this code worked for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knif3rdev picture knif3rdev  路  6Comments

REPTILEHAUS picture REPTILEHAUS  路  5Comments

theofidry picture theofidry  路  5Comments

kamov picture kamov  路  6Comments

johnvoncolln picture johnvoncolln  路  7Comments