Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8778341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:30:46+00:00 2026-06-13T19:30:46+00:00

Using the imagettftext function from the PHP GD library, one can only draw text

  • 0

Using the imagettftext function from the PHP GD library, one can only draw text that is left-aligned onto an image. At least so it would seem, perhaps I’m missing something.

How can I control the alignment of the text drawn onto an image? i.e. left / center / right (/ justified – not necessary, but useful)

I should mention that the alignment is visible when the drawn text contains multiple lines (e.g. “bla bla bla/nAnd another line of bla.”).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:30:47+00:00Added an answer on June 13, 2026 at 7:30 pm

    with imagettftext() you’re not writing into some kind of “box” but just at the given coordnates. to alingn the text properly, you’ll have to calculate the correct coordinates to make it “look like” it’s right-aligned or centered.

    to do so, you can use imagettfbox() to get the size of your text – the rest is simple math:

    • to right-align add [textarea-width]-[textwidth] to your X-coordinate
    • to center add ([textarea-width]-[textwidth]) / 2 to your X-coordinate

    (*textarea = the area you want to write the text at in your image – it’s size should be known to you)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the PHP function imagettftext() to convert text into a GIF image. The
I'm trying to render images with verdana text using PHP imagettftext function. However, all
I can create an image using GD with PHP using the imagettftext() function. The
I'm using php and gd library to draw a triangle. I'm able to draw
I'm trying to render text aligned within the center of a box using imagettftext()
I have been using this simple script to generate images from text: <?php header('Content-type:
Using CMake I want to check if a particular function (cv::getGaborKernel) from OpenCV library
in php, is there an easy way to draw text with imagettftext and imagefilledarc
Using mercurial, I've run into an odd problem where a line from one committer
I'm willing to create an image with certain text using the following code <?PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.