Jump to content

newsoft

New Members
  • Posts

    7
  • Joined

  • Last visited

newsoft's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Although not extremely accurate but very precise. Thanks very much Barand for your time
  2. The box is centered well but the text is not
  3. Hey Barand Unfortunately these coordinates aren't working for height. That's actually the problem. Take a look: http://ahpromote.us/status.php?id=1&t=1
  4. Hey Barand Although imagerectangle would be a good fix, it wouldn't work in my situation as the image is actually a picture so having text with borders wouldn't look good. If I could have the borders of the rectangle to be transparent, it would work. If the image had a solid color background, I could give the borders the same color and so they would blend together but that's not my case. Is there a way to hide the borders of the imagerectangle or make them transparent? Thanks
  5. Hey ginerjm Outbounding box is the imaginary box that holds the text. It's what is used to determine the coordinates of the text box. Unlike width, the height of the text is not simply $text_box_d[7] - $text_box_d[1] because the Y coordinates gets the height from the top of the image to the baseline of the text not to the top of the outbounding box. This is the function used to print the text: $x_co = ($imgWidth - $text_box_width) / 2; $y_co = ($imgHeight - $text_box_height) / 2; imagettftext($img, $font_size, 0, $x_co, $y_co, $text_color, $font, $string); Width is calculated by getting the difference between $text_box_d['2'] and $text_box_d['0'] but the coordinates of the Y axis used for the height leads the text getting pushed upward not centered vertically due to, as stated above, the height is calculated from top of page to baseline of letters not the bounding box (top) of the letters Thanks
  6. Sorry I missed the main function : $text_box_d = imagettfbbox('30', 0, 'arial.ttf', 'hello world'); $max_text_box_height = max(array($text_box_d[1],$text_box_d[3],$text_box_d[5],$text_box_d[7])); $min_text_box_height = min(array($text_box_d[1],$text_box_d[3],$text_box_d[5],$text_box_d[7])); $text_box_height = abs($max_text_box_height) - abs($min_text_box_height); When I have the height, I use the height from the image height and divide by 2 to center the text vertically. The problem is calculating the height of the outbounding box correctly.
  7. Hey I have a simple function to center text in an image. It's centered horizontally but not vertically. This is my code for centering vertically: $max_text_box_height = max(array($text_box_d[1],$text_box_d[3],$text_box_d[5],$text_box_d[7])); $min_text_box_height = min(array($text_box_d[1],$text_box_d[3],$text_box_d[5],$text_box_d[7])); $text_box_height = abs($max_text_box_height) - abs($min_text_box_height); This has been driving me crazy for a full day I have tried nearly all the combinations of coordinates with and without absolute with no avail. Thanks in advance Regards Michael
×
×
  • 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.