Hate Posted October 1, 2010 Share Posted October 1, 2010 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: 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] Quote Link to comment https://forums.phpfreaks.com/topic/214880-gd-problem-with-text/ Share on other sites More sharing options...
Hate Posted October 1, 2010 Author Share Posted October 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/214880-gd-problem-with-text/#findComment-1117852 Share on other sites More sharing options...
Hate Posted October 1, 2010 Author Share Posted October 1, 2010 Aww, kind of disappointed to wake up and not see a reply. Quote Link to comment https://forums.phpfreaks.com/topic/214880-gd-problem-with-text/#findComment-1117961 Share on other sites More sharing options...
sac0o01 Posted October 1, 2010 Share Posted October 1, 2010 I am no expert on php but I have had some experience wit GD and know exactly the problem you speak of. I will post a solution for you when I get home from work and on my pc. Quote Link to comment https://forums.phpfreaks.com/topic/214880-gd-problem-with-text/#findComment-1118104 Share on other sites More sharing options...
sac0o01 Posted October 1, 2010 Share Posted October 1, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/214880-gd-problem-with-text/#findComment-1118130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.