View previous topic :: View next topic |
Author |
Message |
blaineca -
Joined: 05 Dec 2018 Posts: 14
|
Posted: Fri Feb 19, 2021 6:42 am Post subject: using truetype fonts in gd |
|
|
it seems I am unable to display truetype fonts.
Using all samples and also other scripts people have written. I can not display them. Is there some additional I need to do to the prepackaged PHP?
I see there is a new version of GD. Is there a way to upgrade it? |
|
Back to top |
|
|
admin Site Admin
Joined: 03 Mar 2002 Posts: 1296
|
Posted: Sat Feb 20, 2021 8:58 pm Post subject: Re: using truetype fonts in gd |
|
|
blaineca,
Without any context, it is difficult to give you a detailed answer.
Anyway, GD functions related to TrueType fonts mention that there is a need for specifying the path where fonts reside. This could be done using a global or local definition of the environment variable GDFONTPATH:
https://www.php.net/manual/en/function.imagettftext.php _________________ Follow @abyssws on Twitter
Subscribe to our newsletter
_________________
Forum Administrator
Aprelium - https://aprelium.com |
|
Back to top |
|
|
blaineca -
Joined: 05 Dec 2018 Posts: 14
|
Posted: Sun Feb 21, 2021 6:04 pm Post subject: |
|
|
here is a test script I am trying to get working.
Code: | <?php
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?> |
|
|
Back to top |
|
|
admin Site Admin
Joined: 03 Mar 2002 Posts: 1296
|
Posted: Mon Feb 22, 2021 10:10 pm Post subject: |
|
|
The script reports errors because the function imagettftext() is unable to locate the font. Here are the reported errors:
Code: | <b>Warning</b>: imagettftext(): Could not find/open font in
<b>/Users/test/testphp/fonttest.php</b> on line <b>20</b><br /> <br />
<b>Warning</b>: imagettftext(): Could not find/open font in
<b>/Users/test/testphp/fonttest.php</b> on line <b>23</b><br /> |
A quick solution is to copy arial.ttf inside the local working directory (usually it is the directory where the file fonttest.php is located.)
A better solution, as suggested in the PHP documentation we cited, is to declare a GDFONTPATH environment variable containing the full path of a directory containing the TTF fonts (such as c:\windows\fonts).
This can be done by declaring the environment variable in Windows.
A better solution would be declaring that same environment variable in the console of Abyss Web Server: in the host, select "Scripting Parameter", and add GDFONTPATH in "Custom Environment Variables". _________________ Follow @abyssws on Twitter
Subscribe to our newsletter
_________________
Forum Administrator
Aprelium - https://aprelium.com |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|