Jump to content

GD Text Alignment


Recommended Posts

  • 3 years later...

Hey there,

 

The PHP GD Image stuff doesn't have an "align" function, all nice and neat like html does. It actually uses set widths, heights, and positioning all specified in Pixels. So in order to align right you basically need to trial and error because the text may be cut off on the right side as the text is printed left to right.

 

It is actually a lot easier to align left that it is right. I want to share with you a script I wrote a few months ago that basically places text into an image. You give the script a .ttf true type font file, some text, image height and width, font color, background color, transparent background yes or no, text position...a few other things....and it pops out a nice PNG image.

 

The script does not need any configuration, just plop it into your images folder or something and view the sample.php in your browser. sample.php is a nice generator / front end where you enter the info into a form and it generates a sample image and gives you the code to place the image on another html page.

 

Any questions, direct them to [email protected]

 

I am not sure if this would help you, but as I understand it you simply want to get PHP to output an image, correct?

 

I have a little tool I wrote in PHP; a single file with no need for configuration. If you have the GD image library working it will place text into an image. It has code/usage samples: A code generator and a .js script to add reflection to the bottom of the image for really nice headers and things of the like....

 

PHP GD Text<->PNG Creator: http://iluvjohn.com/welcome-to-iluvjohn/custom-fonts-on-a-website-with-php-704

 

Good luck!

Link to comment
https://forums.phpfreaks.com/topic/58251-gd-text-alignment/#findComment-1090691
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.