PHP GD Library - Text / Font NOT ShowingGet the solution ↓↓↓
I am able to render the PHP GD image just fine on my localhost, but when I upload it to my Linux Ubuntu Debian LAMP server, the font or text is missing and only the background color shows. So the image is being generated, but it is just missing the text that belongs in the image.
I currently have PHP 7.2 and the GD 7.2 library installed. It is also showing in my php.ini file that I've enabled it and even removed the semicolon to ensure it's enabled as well.
Here is the code that I'm working with:
<?php //create the php image header('Content-type: image/jpeg'); $img = imagecreate(200, 60); $background = imagecolorallocate($img, 1,49,31); $textColor = imagecolorallocate($img, 255, 255, 255); $font = "roboto.ttf"; imagettftext($img, 28, 10, 40, 50, $textColor, $font, "MY TEXT GOES HERE!"); imagejpeg($img); imagedestroy($img); ?>
Any clue what else would be preventing the text from appearing?
I solved the problem after doing a couple hours of research.
When you have a font file on a VPS & using Linux, you need to use the following file path instead:
$font = "./myfont.ttf"
If you dont put the dot & forward slash, the file will not he found on the server.
Share solution ↓
Link To Answer People are also looking for solutions of the problem: malformed utf-8 characters, possibly incorrectly encoded
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.