Saída de imagem com texto sublinhado usando a biblioteca php GD
Pergunta
O que é a melhor maneira de exibir texto sublinhado e saída o resultado como imagem com GD ou qualquer outra biblioteca?
Solução
Você pode tentar usar o Unicode sublinhado combinando U+0332
personagem.
<?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 = "̲U̲d̲e̲r̲l̲i̲n̲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);
?>
Outras dicas
Existem muitas GRÁTIS PHP CAPTCHA lá fora, que vêm com um monte de personalização, baixar um e ver o que exatamente acontece por trás da cena. Também dê uma olhada neste ligação
HTH
Eu estou usando este ...
$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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow