I created an existing sample that writes input text to a background image no problem. See here.
I attempted to use a font using Imagettftext () following the steps outlined here, however I can't get the function to create the image using the font I specified. This is the code I added to the working page above: - $font = 'arial.ttf';
-
imagettftext ($my_img, 10, 15, 30, 40, $txt_colour, $font, $input_text);
Also tried it with: - putenv('GDFONTPATH=' . realpath('.'));
-
$font = 'arial.ttf';
Attempted troubleshooting
1. My host supports freetype and it's compiled with 4.4.9.
'../configure' '--with-pear=/usr/lib/php' '--prefix=/usr' '--with-mysql=/usr/' '--with-zlib' '--enable-debug=no' '--enable-safe-mode=no' '--enable-discard-path=no' '--with-gd' '--with-png-dir' '--enable-track-vars' '--with-db' '--with-gdbm' '--enable-force-cgi-redirect' '--with-ttf' '--enable-ftp' '--with-mcrypt' '--enable-dbase' '--enable-memory-limit' '--enable-calendar' '--enable-wddx' '--with-jpeg-dir' '--enable-bcmath' '--enable-gd-imgstrttf' '--enable-shmop' '--enable-mhash' '--with-mhash' '--with-openssl' '--enable-xslt' '--with-xslt-sablot' '--with-dom' '--with-dom-xslt' '--with-dom-exslt' '--with-imap' '--with-curl' '--with-iconv' '--with-freetype-dir' '--with-bz2' '--with-gettext' '--enable-exif' '--with-idn' '--enable-mbstring=all' '--with-kerberos' '--with-imap-ssl' '--with-sqlite' '--with-zip'
2. I changed my FTP settings to upload text files as ASCII instead of binary and tried it with a number of basic ttfs in the same folder but still did not work.
3. I confirmed with my web host - 1and1 - and they assured me it should work providing my code was correct.
4. I tried using the imagefttext function but to no avail. It just generates an image with no text at all as seen here.
I can't find any other method of troubleshooting this issue, so anything that I haven't tried here....??
7 16327
You know, over the passed week, I have seen this same problem (ish) 3 times in IRC (#php @ irc.freenode.net), and they all had the same solution: a simple 'make clean' for the PHP source. If you do not have access to this on the server, then you might ask your hosting provider to give you a hand.
However, do you receive any errors? Try turning on error reporting (error_reporting(-1);). Also try - <?php print function_exists('imagettftext') ? 'yes' : 'no';
Hi Markus, I get no errors it just doesn't write text to the image. I tried your function_exists() and I received a 'yes'.
Even going back to basics and running this code gives me a white image with no text and should return 'Testing...' - <?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);
-
?>
Could you possibly test this on your server to ensure it's not the code?
When you say a 'make clean' what exactly do I need to do?
Atli 5,058
Expert 4TB @kip1790
Hey. I tried your code on my server (see here) and it works fine.
Which means there must be a problem with your server.
If you are using a shared hosting service, this is probably something your host would need to fix.
I appreciate you testing this on your end. I've spoken to and sent along a simple script that works for me locally, just not on their servers, and they'll test it on their back end to resolve the problem. So hopefully I should be good to go soon enough. Cheers!
Ask them to run a 'make clean' on their PHP source directory. They'll understand.
Sorry to wake up an old thread, but I have run into this problem with 1and1 servers before. Check the case of your font, if you specify "arial.ttf" but upload "Arial.ttf" then imagettftext will fail silently.
Seems to be something to do with 1and1 settings as my local server does not care about the case.
Atli 5,058
Expert 4TB @MattAldred
Your local server doesn't happen to be a Windows server?
The Windows file-systems are case-insensitive, while Unix file-systems are case-sensitive. So if your file is named "arial.ttf", fetching it as "Arial.ttf" will work on Windows but fail on Unix systems (including Linux, and most likely Mac).
I would have though this sort of problem would produce an error message though.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bof |
last post by:
I'm attempting to use ImageTTFText to render text to an image, I can get
it to work if I
a) specify the full font path
b) switch off...
|
by: John Wellesz |
last post by:
Hi,
since I've upgraded to php 4.3.4 (before I used 4.1.2) I have a problem
with imagettftext():
when executing the line:
imagettftext($im,...
|
by: Leif Wessman |
last post by:
I'm using a bundled version of GD: 2.0.23 compatible. When using the
function imagettftext() with a negative color to get a aliased text,
the text...
|
by: Leif Wessman |
last post by:
From: http://www.php.net/manual/en/function.imagettftext.php
"color is the color index. Using the negative of a color index has the
effect of...
|
by: Axier |
last post by:
I cannot get the swedish character set on images. What can be wrong?
I would very much appreciate help.
regards, axier
I can supply some code...
|
by: franscescomoi |
last post by:
Hi.
On PHP 4.3.10 on Linux I try to:
------
$im = imagecreate(400, 30);
$black = imagecolorallocate($im, 0, 0, 0);
imagettftext($image, 20,...
|
by: Nemo |
last post by:
Hi. I'm having a problem with a php program on debian. As you all
probably guessed from the title, I get an undefined function call error
whenever...
|
by: monomaniac21 |
last post by:
My url is www.aptitudehack.com
Hi i cant get an image to display on another server though it does on
mine. Here is the code for the page. The...
|
by: Doraj |
last post by:
Hello !
Here is my problem :
I had some php scripts which worked well with php 4.0.5 (GD 1.6.2
according to phpinfo() ) and i put them on a...
|
by: cdriccio |
last post by:
Hello,
I'm trying to make a gif image out of a total of 5 (currently) images. One background image and 4 small icons.
This image also includes...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |