Imagettftext, why doesn't it work?


#1

I have a php script which uses imagettftext to load a font within my home directory. I verified with “file_exists” that the font is being seen by the script. But when I try to use imagettftext to write the font out, the script just passes it over and loads the image without the text.

What’s the problem?


#2

I’ve seen this before. I believe I fixed it by using the imagefttext() function instead. It’s the same as imagettftext, but with one additional parameter (just add “, array()” at the end of the parameter list.)

I also believe they fixed this (or changed it or something) in the most recent version of PHP.


#3

Thanks for the suggestion. I gave it a shot but the function is undefined. Do I need to compile my own PHP?


#4

hmm, indeed you are correct… when I run my script with the default PHP, I’m getting imagefttext undefined, and imagettftext doesn’t produce any output.

With the PHPs I compiled myself (both PHP 4.3.9 and 5.0.2), both functions work.

Since I’ve always used my own PHP and remember experiencing this problem, there’s a chance it might be a bug in the version of PHP that Dreamhost is currently running.

I’m also looking at the differences in the options between my PHP and the default one. The default PHP uses “–with-freetype=/usr”, but it looks like the correct setting is actually “–with-freetype-dir=/usr”. (That’s what I’m using.) This could explain why the function is undefined.

I’m also using “–enable-gd-native-ttf”, although I don’t even really know what that does.


#5

Oh wow. In that case it is almost surely the broken compile line. I will compile my own and be on my merry way! Thank you for your help Mark. I appreciate it.


#6

Thank you again. It took me a while to compile, and I don’t have all the options because I didn’t want to install some libraries, but I eventually got it right. And sure enough, the function is working properly now.

I’m going to save my configure line and hopefully life will be easier in the future when I recompile to add features. Thanks again.