vilvendhan Posted May 28, 2007 Share Posted May 28, 2007 Using GD library how to make the text underline. I have used imagettftext ( resource $image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text ) this function for write text to the image. I could not make underline text on image. Please any one help me. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/53237-gd-library-underline/ Share on other sites More sharing options...
siwelis Posted May 28, 2007 Share Posted May 28, 2007 I found a few artciles that may help you out... I've looked into it and I'm not sure how to do it either just yet, if I did learn though, it would probably be from these articles: http://us.php.net/gd (Search for "Underline") and http://www.nyphp.org/content/presentations/GDintro/gd0.php (Search for line) - Perhaps you can combine GD Functions... I think that's what a php.net article implies is doable. This right here may be able to help some too... http://www.phpfreaks.com/tutorials/52/0.php Quote Link to comment https://forums.phpfreaks.com/topic/53237-gd-library-underline/#findComment-263079 Share on other sites More sharing options...
vilvendhan Posted May 29, 2007 Author Share Posted May 29, 2007 Thank for your reply. I found the solution. You given articles links was very useful. This is the example code require_once ('Image_Toolbox.class.php'); $text="Underline.%0D________"; $text=urldecode($text); $img = new Image_Toolbox('cardaa.jpg'); $img->addText($text, 'C:/WINDOWS/Fonts/ARIAL.ttf', '18', '#000000', '50', '100',$angle = 0); $img ->addImage('cardaa.jpg'); $img->output(); Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/53237-gd-library-underline/#findComment-263701 Share on other sites More sharing options...
maqueem Posted July 26, 2011 Share Posted July 26, 2011 This script Works ... I had spent alot of time on internet and collected different ideas and generate an algorithm that will underline text written on an image. Please have fun with this and post any improvement. i will be glad to see that. <?php // Create the image $im = imagecreatetruecolor(399, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = "Muhammad Aqeel Mirza"; // Replace path by your own font path $font = 'arial.ttf'; // Place this file in your code directory or if font is in font directory set its path with font name as $font=$path.'arial.ttf'; // Add the text $x=10; $y=20; $font_size=12; $angle=0; $total_width=0; // getting total width of all the characters in the input string. for($i=0; $i<strlen($text); $i++) { $dimensions = imagettfbbox($font_size, $angle, $font, substr($text,$i,1)); $total_width+=($dimensions[2]); } echo "<pre>"; // getting total length of the string as a whole and compare both widths. $dimensions = imagettfbbox($font_size, $angle, $font, $text); echo "Dimension of full string=".$dimensions[2]."<br/>"; echo "Total width calcuated by algorithm=".$total_width."<br/>"; $difference=$dimensions[2]-$total_width; echo "Difference=".$difference; imagettftext($im, $font_size, $angle, $x, $y, $black, $font, $text); $x2=$x+$total_width+$difference+2; //echo $total_width; echo "<pre/>"; imageline( $im , $x , $y+4 , $x2 , $y+4 , $black ); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im,"underline.png"); echo "<img src='underline.png'/>"; imagedestroy($im); die(); [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/53237-gd-library-underline/#findComment-1247196 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.