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 john@iluvjohn.com

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.