Outputting image with underlined text using php GD library

风流意气都作罢 提交于 2019-12-01 08:02:31

You can try using the Unicode underline combining character U+0332.

<?php
// Set the content-type
header('Content-type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 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 = "&#x0332;U&#x0332;d&#x0332;e&#x0332;r&#x0332;l&#x0332;i&#x0332;n&#x0332;e";
// Replace path by your own font path
$font = 'arial.ttf';


// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

There are lots of FREE PHP CAPTCHA out there that come with a lot of customization, download one and see what exactly happens behind the scene. Also have a look at this link

HTH

I am using this...

    $font = imageloadfont($font_file);  
$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
    $str_width = strlen($text)*$font_width;
    ImageLine($image, $left, $top+$font_height, $left+$str_width,  $top+$font_height, $color);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!