godsent Posted February 13, 2010 Share Posted February 13, 2010 Is it possible to make text on image underlined or italic? And if its possible to make part of text normal and another part (italic)? And the last question is my code for writing text is proper? $text = wrap(12, 0, "arial.ttf", "One day, Two days, Three days and all other days.",300); $font = "arial.ttf"; $size = "12"; $width = 300; $height = 400; $image = imagecreatetruecolor($width, $height); //blank img $bgcolor = imagecolorallocate($image, 255, 255, 255); // white $color = imagecolorallocate($image, 0, 0, 0); //black $x = 10; //begin write on x $y = 20; //begin write imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bgcolor); imagettftext($image, $size, 0, $x, $y, $color, $font, $text); header('Content-type: image/png'); imagepng($image); imagedestroy($image); function wrap($fontSize, $angle, $fontFace, $string, $width){ $ret = ""; $arr = explode(' ', $string); foreach ( $arr as $word ){ $teststring = $ret.' '.$word; $testbox = imagettfbbox($fontSize, $angle, $fontFace, $teststring); if ( $testbox[2] > $width ){ $ret.=($ret==""?"":"\n").$word; } else { $ret.=($ret==""?"":' ').$word; } } return $ret; } Quote Link to comment Share on other sites More sharing options...
cwarn23 Posted February 13, 2010 Share Posted February 13, 2010 With the gd library the only way you will accomplish italic bold text is with a custom function. To make the text bold you could use a font like "Arial Black" or display the text twice with the second text having an x offset of +1. To make it italic you will need to loop through each character and display each character on an angle. Hope that helps. Quote Link to comment Share on other sites More sharing options...
Zane Posted February 13, 2010 Share Posted February 13, 2010 If bold underlined is what you want.. then a bold underlined custom font you'll need to make.. (at least that's the easiest way I can think of doing it) I'm not too sure how TTF works with GD Library but I do know that you can create a GDF font from a TTF font, using this program http://www.wedwick.com/wftopf.exe. You can load up Arial Black... set your desired size, styles, etc.. and save it; upload it to your server and use it. By use it I mean, use this function imageloadfont .... and too Quote Link to comment 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.