使用php GD库输出带下划线文本的图像 [英] Outputting image with underlined text using php GD library

查看:235
本文介绍了使用php GD库输出带下划线文本的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GD或任何其他库显示带下划线的文本并将结果输出为图像的最佳方法是什么?

What is the best way to display underlined text and output the result as image with GD or any other library?

推荐答案

您可以尝试使用结合了字符U+0332的Unicode下划线.

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);
?>

这篇关于使用php GD库输出带下划线文本的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆