I am using Laravel framework and image/intervention library for generating images with dynamic data. The code is running perfectly fine on my local machine but as soon as I upload it on aws ubuntu instance it is showing error like Internal gd font() not available. I tried switching to imagick and public_path() but it is still showing the same error. My code is as follows:
I tried switching to imagick and public_path() but it is still showing the same error. My code is as follows:
public function generateIdCard(Request $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);
}
A year late, but here's to anyone else searching for the answer in 2020 and beyond like me.
I found you have to use public_path()
to get the correct path to the file. So change this:
$font->file('../../../fonts/Poppins-Medium.ttf');
To this:
$font->file(public_path('../../../fonts/Poppins-Medium.ttf'));
You may need to double-check that the relative path you are giving is correct. (So check what is output by calling public_path()
and make sure the file exists.)