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 8791979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:55:02+00:00 2026-06-13T22:55:02+00:00

I am trying to create a function that generates an rectangle with some text

  • 0

I am trying to create a function that generates an rectangle with some text on it.

I have the following function:

<?php
function  create_image()
{
 $im = @imagecreate(190, 190)or die("Cannot Initialize new GD image stream");
 $background_color = imagecolorallocate($im, 255, 255, 255);
 imagerectangle($im, 5, 5, $_SESSION['lungime'], 5+$_SESSION['latime'], $black);

 for ($i=1, $k=0; $i<=$_SESSION['rand'] ; $i++, $k=$k+12)
 imagettftext($im, 12, 0,5+x/2-(strlen($_SESSION['rand'.$i]))/2, 12+$k, $black, $_SESSION['fontr'.$i], $_SESSION['rand'.$i]);

 imagepng($im,"image.png");
 imagedestroy($im);
}
?>

I want the text that is generated within the for loop to be centered in the rectangle. I can’t do it with strlen because it returns the number of characters that the string has. How cand I do that?

What about generating a center-aligned text in a generated circle?

Please help me !
Thank you !

  • 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-13T22:55:03+00:00Added an answer on June 13, 2026 at 10:55 pm

    You can use PHP’s imagettfbbox to get the dimensions of text you’re printing in GD.
    Then it’s just a bit of math to work out where to set the left point to.

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

Sidebar

Related Questions

I am trying to create a function that will block access to some of
So I'm trying to create a function that generates a SQL query string based
Following this nice example I found, I was trying to create a function that
I am trying to create a helper function (eg in application_helper.rb ) that generates
I'm trying to create (in r) the equivalent to the following MATLAB function that
I am trying to create a function that generates a random integer out of
Good afternoon chaps.. I'm trying to create a function in Javascript that generates an
I'm trying to create an hashing function that, given a random salt, generates a
I'm trying to create a function that would append two vectors together, but I
I am trying to create a function that updates another value, and initially (after

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.