Jump to content

GD Problem With Text


Hate

Recommended Posts

Hi,

 

I'm trying to replicate a the font on a website in my image and I'm having some trouble. The image I'm working with is supposed to have a transparent background and when I write text over the transparent background the text gets distorted and feels pixelated and has some sort of black stroke around the edges of the letters. The text appears nicely when the website has a dark background color, but when it's a lighter/white color it looks terrible and I need to get this fixed. It's not like this is going to remain on a single website, so it's important that it looks good on all background colors.

 

Screenshots:

vniibp.png

 

k4htl2.png

 

Apparently, the only letters that looks like they should is the letter "T" and "i".  : I'm not sure if it has something to do because these letters don't have any curves in them or not. I just noticed that both of those letters have straight lines and look perfect. I'm not sure if I'm just looking too hard, but it appears to me that the same letters on the lighter background that have trouble displaying are smaller/distorted in the darker background as well.

 

I've also included a zip file for anyone interested in trying to help me. It contains the font file within the proper directory structure (trying to get as much help as possible so I made it easy on you :) ) along with the actual php file.

 

Here's my code so far:

 

<?php// Signature dimensions$signatureX = 400;$signatureY = 125;// Create the signature canvas$signature = imagecreate($signatureX, $signatureY);// Make the signature background transparentimagecolorallocatealpha($signature, 0, 0, 0, 127);// Colors$color_gray = imagecolorallocate($signature, 128, 128, 128);$color_black = imagecolorallocate($signature, 100, 100, 100);// Font$verdana = './fonts/Verdana.ttf';// The text to display on the signature$text = "This is not very sexy";// Write the text to the signatuteimagettftext($signature, 8, 0, 10, 20, $color_black, $verdana, $text);// Display the signatureimagepng($signature);// Free up resourcesimagedestroy($signature);?>

 

 

Help?  :

 

[attachment deleted by admin]

Link to comment
Share on other sites

In case anyone was wondering this is for a signature that I plan to use on multiple forums. The signature is going to have a transparent background so it should fit nicely with the background colors of various websites where I use this.

 

Honestly, I'm surprised I haven't got a response yet.. you would figure something like this would be quite common. Knowing my luck though it's probably some extreme rare case that I can't get fixed.

 

Here's some more information regarding my server:

PHP Version 5.2.14

GD Support enabled

GD Version bundled (2.0.34 compatible)

FreeType Support enabled

FreeType Linkage with freetype

FreeType Version 2.2.1

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

 

Link to comment
Share on other sites

This should work for you.  I will try to explain it the best I can.

 

The big thing here is changing from "imagecreate" to "imagecreatetruecolor"  this allows the palette to use over 16 million colors rather than just 256. 

 

By using truecolor you can also now save the alpha channel of the image which can be antialiased.  I also changed the  final "imagepng" to create a file for easier viewing during testing. 

 

Simply change:

// Create the signature canvas
$signature = imagecreate($signatureX, $signatureY);

// Make the signature background transparent
imagecolorallocatealpha($signature, 0, 0, 0, 127);

 

To this:

// Create the signature canvas
$signature = imagecreatetruecolor($signatureX, $signatureY);

// Make the signature background transparent
imageantialias($signature, true);
imagealphablending($signature, true);
imagesavealpha($signature, true);
$trans_colour = imagecolorallocatealpha($signature, 0, 0, 0, 127);
imagefill($signature, 0, 0, $trans_colour);

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.