参考

User Contributed Notes 12 notes

The documentation above is bad. It says $font:"Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont()."

But it can't. When I put in 1,2,3,4,5 I get"Warning: imagepstext() expects parameter 3 to be resource, integer given"

I get the same thing when using imageloadfont() because imageloadfont() also returns an integer. The documentation should instead say: "resource returned from imagepsloadfont()."

imagepstext() appears to be quite memory intensive and we had a problem where about 50% of the time the script would error. You need to make sure PHP has enough memory assigned to it - we had to increase PHP's allocation from 8MB to 16MB for a simple "hello world" example to work smoothly.

If the png header was commented out it would sometimes error with a message like:

The coordinates given by x, y represent actually a starting point of the text baseline. They represent the lower left corner of the first character only in case that any part of the character doesn't lie below baseline (it works for "Hello" but for "Howdy" it does not - because of letter y). There may be some small differences according to the font and size chosen.

a note on kernnig:t1lib tries to load a corresponding afm file in the directory of the font file.it does this by replacing the extension (.PFB .pfb) with ".afm". note that this has to be a lowercase afm! usually windows-ps-fonts have file names in all-uppercase, so try renaming the *.AFM file to *.afm.

i also noticed that sometimes this gives an error -2. it seems like t1lib chokes on windows-linebreaks in the afm file.

try 'recode dos..lat1 fontfile.afm' and check again.

if it all works, combinations like "Ta" or "Te" should show the second letter slightly moved to the capital T (on normal fonts like Times anyway).

If you have a programming error in your code, using ImagePsText, sometimes t1lib crashes with an unrecoverable error. Because of this, httpd needs to be restarted.

This problem only occurs if there is a programming error, but can drive you crazy when debugging, if you don't know about it. By killing the parent process(httpd) you "reset" t1lib. When debugging, if you get an error then make a code change, restart httpd before testing it again. This will save hours of frustration. Make it a habit to just restart httpd after every error, and you will be much happier.

Also, to see debugging messages, (if you are rendering x's) comment the jpeg header, and the ImageJpeg statement. You will get beautiful error messages. When you get a blank page, your ImagePsText code is working correctly. Uncomment the Header() and ImageJpeg() and see what you have. You might be passing parameters that render a white image with no text, but the code is working!

Numeric t1lib error messages can be decoded using the t1lib_doc.pdf file that comes with t1lib. PHP simply relays these errors from t1lib to the page. Please don't ask the PHP people about these errors... t1lib has beautiful documentation.... use it: )

One other thing... variables. It is important to convert variables to the proper type before they hit this function. In this respect, ImageTtfText is easier to work with. IE, if you pass a font size from one page to the next, via GPC, it becomes a string type. Sooo... use IntVal() to convert it to an integer type that ImagePsText can digest. In addition you must convert HTML special characters or use chr() to represent special characters. ImagePsFont will not decode to represent a space, use Chr(32) or a space:

I made a function that makes it easy to align text to the rightof an image. Below you can find the code because for me itworks great. You can also use it to center text as well, if you like to have that simply remove the -10 and split the resultof $imgwidth and $texwidth