bluesguitarman25 Posted July 3, 2007 Share Posted July 3, 2007 I need to specifically place text over an image. I've got the image creation down, but all I can seem to do is center the text. So lets say I have an image 300px(W) by 150px(H). I want to right align the text. Any help? Quote Link to comment Share on other sites More sharing options...
cjohnweb Posted July 24, 2010 Share Posted July 24, 2010 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! Quote Link to comment Share on other sites More sharing options...
Alex Posted July 24, 2010 Share Posted July 24, 2010 You can center text using PHP GD using some simple math. Here's a tutorial on it: http://www.bitrepository.com/php-how-to-center-a-text-on-an-image-using-gd.html Quote Link to comment Share on other sites More sharing options...
litebearer Posted July 24, 2010 Share Posted July 24, 2010 will it be a single line of text or multiple lines? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.