472,351 Members | 1,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

Imagettftext () function not working

13
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:
Expand|Select|Wrap|Line Numbers
  1. $font = 'arial.ttf';
  2. imagettftext ($my_img, 10, 15, 30, 40, $txt_colour, $font, $input_text);
Also tried it with:
Expand|Select|Wrap|Line Numbers
  1. putenv('GDFONTPATH=' . realpath('.'));
  2. $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....??
Feb 8 '10 #1
7 16327
Markus
6,050 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. <?php print function_exists('imagettftext') ? 'yes' : 'no';
Feb 8 '10 #2
kip1790
13
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...'
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Set the content-type
  3. header('Content-type: image/png');
  4.  
  5. // Create the image
  6. $im = imagecreatetruecolor(400, 30);
  7.  
  8. // Create some colors
  9. $white = imagecolorallocate($im, 255, 255, 255);
  10. $grey = imagecolorallocate($im, 128, 128, 128);
  11. $black = imagecolorallocate($im, 0, 0, 0);
  12. imagefilledrectangle($im, 0, 0, 399, 29, $white);
  13.  
  14. // The text to draw
  15. $text = 'Testing...';
  16. // Replace path by your own font path
  17. $font = 'arial.ttf';
  18.  
  19. // Add some shadow to the text
  20. imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
  21.  
  22. // Add the text
  23. imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
  24.  
  25. // Using imagepng() results in clearer text compared with imagejpeg()
  26. imagepng($im);
  27. imagedestroy($im);
  28. ?>
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?
Feb 8 '10 #3
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.
Feb 9 '10 #4
kip1790
13
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!
Feb 9 '10 #5
Markus
6,050 Expert 4TB
Ask them to run a 'make clean' on their PHP source directory. They'll understand.
Feb 9 '10 #6
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.
Feb 13 '10 #7
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.
Feb 13 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
0
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,...
0
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...
3
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...
1
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...
1
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,...
0
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...
6
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...
3
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...
9
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...
0
better678
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...
0
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
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...
0
jalbright99669
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...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
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...
0
Oralloy
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...
0
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....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.