I am trying to make a certificate generator with custom font, but I am unable to import font from it's directory.
Code is below
<?php
// (A) OPEN IMAGE
$img = imagecreatefromjpeg('cert.jpg');
// (B) WRITE TEXT
$white = imagecolorallocate($img, 255, 255, 255);
$txt = "Adnan Khan Akib";
$font = "arial.ttf";
$minus = strlen($txt)*70;
//1 word er jonno 70
// THE IMAGE SIZE
$width = imagesx($img)-$minus;
$height = imagesy($img);
// THE TEXT SIZE
$text_size = imagettfbbox(24, 0, $font, $txt);
$text_width = max([$text_size[2], $text_size[4]]) - min([$text_size[0], $text_size[6]]);
$text_height = max([$text_size[5], $text_size[7]]) - min([$text_size[1], $text_size[3]]);
// CENTERING THE TEXT BLOCK
$centerX = CEIL(($width - $text_width) / 2);
$centerX = $centerX<0 ? 0 : $centerX;
$centerY = CEIL(($height - $text_height) / 2);
$centerY = $centerY<0 ? 0 : $centerY;
imagettftext($img, 120, 0, $centerX, $centerY, $white, $font, $txt);
// (C) OUTPUT IMAGE
header('Content-type: image/jpeg');
imagejpeg($img);
imagedestroy($jpg_image);
?>
I have put arial.ttf on the same directory.
I tried,
$font = "arial.ttf";
and,
$font = realpath("arial.ttf");
also this,
$font = "./arial.ttf";
Error is
Warning: imagettftext(): Could not find/open font