php - 内部 gd 字体 () 不可用仅使用 1-5

标签 php laravel amazon-web-services php-gd

我正在使用 Laravel 框架和图像/干预库来生成具有动态数据的图像。该代码在我的本地机器上运行得非常好,但是一旦我将它上传到 aws ubuntu 实例上,它就会显示错误,例如 Internal gd font() not available。我尝试切换到 imagick 和 public_path() 但它仍然显示相同的错误。我的代码如下:

我尝试切换到 imagick 和 public_path() 但它仍然显示相同的错误。我的代码如下:

公共(public)函数 generateIdCard(请求 $request){

    $user = app('App\Http\Controllers\ApiTokenController')->authenticate($request);
    if($user == null)
        return response()->json(['message' => 'Token Invalid','status'=>0], 200);

    $user = MatchmakerUser::where('id', $user->id)->first();
    if($user){
    $img=Image::make($this->url2.'2.png');
    $filename = 'mmProfilePic_'.$user->id.'.jpg';
    $profilepicurl=$this->url.$filename;
    $img2=Image::make($profilepicurl)->resize(82,82);
    $img->insert($img2,'top-left',22,24);
    $name=$user->first_name.$user->last_name;
    $img->text($name,115, 50, function($font) {
        $font->file('../../../fonts/Poppins-Bold.ttf');
        $font->size(18);
        $font->color('#fff');
        $font->valign('top');
    });
    $designation=$user->matchmaker_type;
    $img->text($designation,115, 73, function($font) {
        $font->file('../../../fonts/Poppins-Medium.ttf');
        $font->size(10);
        $font->color('#fff');
        $font->valign('top');
    });
    $phone=$user->phone_number;
    $img->text($phone,31, 129, function($font) {
        $font->file('../../../fonts/Poppins-Medium.ttf');
        $font->size(10);
        $font->color('#4e4e4e');
        $font->valign('top'); 
    });
    $location=$user->location;
    $img->text($location,33, 148, function($font) {
        $font->file('../../../fonts/Poppins-Medium.ttf');
        $font->size(10);
        $font->color('#4e4e4e');
        $font->valign('top'); 
    });
    $website="www.hansmatrimony.com/matchmaker";
    $img->text($website,33, 167, function($font) {
        $font->file('../../../fonts/Poppins-Medium.ttf');
        $font->size(9);
        $font->color('#4e4e4e');
        $font->valign('top'); 
    });
    Storage::disk('s3')->put('static/matchmakerz/id_card/'.'Id_card'.$user->id, file_get_contents($img), 'public');
    IdCard::create([
        'id_card'=>'static/matchmakerz/id_card/'.'Id_card'.$user->id,
        'matchmaker_id'=>$user->id
        ]);
        return response(['matchmaker_id_card'=>$this->url2.'id_card'.$user->id,'name'=>$name,'status'=>1,'message'=>'success'], 200);
    }

    elseif($user == null)
        return response()->json(['status' => 0, 'message' => 'No User details found'], 200);
    else
        return response()->json(['status' => 0, 'message' => 'Some Error Occurred'], 200);
}

最佳答案

晚了一年,但这是给像我这样在 2020 年及以后寻找答案的人。
我发现你必须使用 public_path()获取文件的正确路径。所以改变这个:

    $font->file('../../../fonts/Poppins-Medium.ttf');
对此:
    $font->file(public_path('../../../fonts/Poppins-Medium.ttf'));
您可能需要仔细检查您提供的相对路径是否正确。 (因此,通过调用 public_path() 检查输出内容并确保文件存在。)

关于php - 内部 gd 字体 () 不可用仅使用 1-5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57221655/

相关文章:

javascript - 将 json 数组从 PHP 传输到 JS

php - 使用 SHA1 时如何检查 PHP 字段是否为空

php - 如何将参数添加到 google oauth 2

java - 2.1.6 Spring Boot-Elasticsearch Healthcheck失败

amazon-web-services - 当消息发布到SQS时如何触发lambda?

c# - 尝试了解 DynamoDB .NET 中的查询表操作

php - 触发 HTTP 错误 : 4xx 5xx via HTML/PHP

javascript - 编辑 Wordpress 主题中的现有元素

php - laravel 获取所有具有关系的模型以及这些关系的关系

laravel - 使用 Laravel、Patternlab、Atomic Design 和 Vue.js 结合后端和前端开发