Вывод изображения с подчеркнутым текстом с использованием библиотеки php GD
Вопрос
Как лучше всего отобразить подчеркнутый текст и вывести результат в виде изображения с помощью GD или любой другой библиотеки?
Решение
Вы можете попробовать использовать символ объединения подчеркивания Unicode. 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 = "̲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);
?>
Другие советы
Существует множество БЕСПЛАТНЫХ PHP CAPTCHA, которые имеют множество настроек. Загрузите одну и посмотрите, что именно происходит за кулисами.Также взгляните на это связь
ХТХ
Я использую это...
$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);
Не связан с StackOverflow