php生成文字图片效果
最近看到php的GD功能,试着做了一个基本生成文字图片效果的代码:
显示文字图片页面:demo.php
<?php
$str = $_REQUEST['str'] ? $_REQUEST['str']:"暂无输入";
//$str = "中华人民共和国";
$im = imagecreate(200,200);
$white = imagecolorallocate($im,0xFF,0xFF,0xFF);
imagecolortransparent($im,$white); //imagecolortransparent() 设置具体某种颜色为透明色,若注释
$black = imagecolorallocate($im,0x00,0x00,0x00);
imagefilledrectangle($im,50,50,150,150,$black);
imagestring($im,5,50,160,"happy every day",$black);
imagettftext($im,15,0,50,40,$black,"D:\windows\Fonts\simhei.ttf",$str); //字体设置部分linux和windows的路径可能不同
header("Content-type:image/png");
imagepng($im);
?>
调用图片页面:demo2.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php $var = "中华人民共和国"; ?>
<img src="demo.php?str=<?php echo $var?>">
文字图片进阶:
环境:Red Hat AS4.0+GD2.0.28+FreeType 2.1.9
目的:生成类似链接的即具有下划线的蓝色文字图像
//获取文字并将其转化成图片

最低0.47元/天 解锁文章
3725

被折叠的 条评论
为什么被折叠?



