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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:22:52+00:00 2026-06-08T18:22:52+00:00

for some reason PHP’s imagettftext creates a funny looking text when I create the

  • 0

for some reason PHP’s imagettftext creates a funny looking text when I create the text at an angle.

Below the source code. I can’t post the image ’cause I don’t have enough reputation points but the text looks like parts of the letters are cut off.

Help!!!


$text = 'My Text Is Messed Up!!!';
$font = './fonts/arial.ttf';
$font_size = 20;
$font_multiplier = 0.5;

$x=10; 
$y=190; 
$angle=45; 
$width= ($font_size * $font_multiplier) * strlen($text); 
echo $width;
$height=200; 

$size = imageTTFBBox($font_size, $angle, $font, $text);
$img = imageCreateTrueColor($width, $height);
imageSaveAlpha($img, true);
ImageAlphaBlending($img, false);

$transparentColor = imagecolorallocatealpha($img, 200, 200, 200, 127);
imagefill($img, 0, 0, $transparentColor);
$white = imagecolorallocate($img, 255, 255, 255);

// Add the text
imagettftext($img, $font_size, $angle, $x, $y, $white, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($img, 'welcome-phrase.png');
imagedestroy($img);

EDIT: here’s an example of the output (I changed text colour from white to black to make it visible on the white background – AG):

enter image description here

  • 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-08T18:22:53+00:00Added an answer on June 8, 2026 at 6:22 pm

    It seems there is an issue with it rotating each character and leaving a “mask” of sorts that isn’t rotated and then obscures the text around it, causing the issue you are seeing. It is more visible when you turn off the transparent image fill.

    A workaround could be to rotate the image instead of the text. You will have to fix your coordinates but something like this seems to work:

    // Add the text
    imagettftext($img, $font_size, 0, $x, $y, $black, $font, $text);
    
    
    $img = imagerotate($img, $angle, $transparentColor);
    imageSaveAlpha($img, true);
    ImageAlphaBlending($img, false);
    

    Thus the full code would be:

    $text = 'My Text Is Messed Up!!!';
    $font = './fonts/arial.ttf';
    $font_size = 20;
    $font_multiplier = 0.5;
    
    $x=10;
    $y=190;
    $angle=45.0;
    $width = ($font_size * $font_multiplier) * strlen($text);
    echo $width;
    $height=200;
    
    $size = imageTTFBBox($font_size, $angle, $font, $text);
    $img = imageCreateTrueColor($width, $height);
    
    
    $transparentColor = imagecolorallocatealpha($img, 200, 200, 200, 127);
    imagefill($img, 0, 0, $transparentColor);
    $white = imagecolorallocate($img, 255, 255, 255);
    
    // Add the text
    imagettftext($img, $font_size, 0, $x, $y, $white, $font, $text);
    
    
    $img = imagerotate($img, $angle, $transparentColor);
    imageSaveAlpha($img, true);
    ImageAlphaBlending($img, false);
    // Using imagepng() results in clearer text compared with imagejpeg()
    imagepng($img, 'welcome-phrase.png');
    imagedestroy($img);
    

    I moved the imageSaveAlpha and ImageAlphaBlending to the bottom to take care of all that after the rotation has taken place. It’s not the best solution but with some tweaking will provide the correct result.

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

Sidebar

Related Questions

For some reason this PHP code below will not work, I can not figure
I know PHP 5 already supports SQLite but for some reason I can't get
for some reason this code wont work, it doesn't seem to read the javascript.php
I'm new to JQuery but for some reason I cant get the php code
I can't change the php.ini for some reason, how can I do it in
For some reason the item description returns NULL with the following code: <?php include('db.php');
For some reason I can't get Basic Authentication to work using PHP on my
For some reason, only the first imagejpeg is working. help? FULL CODE <?php imagecopymerge($image,
I have a bit of PHP code that's baffling me for some reason. I
For some reason, when php mail() is sent to a text number (via email)

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.