2011-11-03 131 views
1

我找不到一个开放源码的PHP脚本,允许我选择字体,然后在其周围应用边框。为文本和颜色添加边框

我也应该能够选择颜色文本/边框,并且还可以应用文本背景阴影。

哪个脚本可以做到这一点?

+6

'' - 其余的由你决定。 –

+0

imagettftext()让您指定一个ttf字体...您可以使用颜色更改和偏移调用它两次,以获得简单的阴影,该示例位于该函数的手册页上。 – Ben

回答

3

下面的代码为你工作一定要donwload ARIAL.TTF和发生在目录

<?php 
$fontsize = 36; 
$fonttext = "test"." "; 


$size = imagettfbbox($fontsize, 0, "arial.ttf", $fonttext); 
$xsize = abs($size[0]) + abs($size[2]); 
$ysize = abs($size[5]) + abs($size[1]); 

$image = imagecreate($xsize, $ysize); 
$black = imagecolorallocate($image, 0, 0, 0); 
imagecolortransparent($image, $black); 
$blue = imagecolorallocate($image, 0, 0, 255); 
//$white = ImageColorAllocate($image, 255,255,255); 


imagettftext($image, $fontsize, 0, abs($size[0]), abs($size[5]), $blue, "arial.ttf", $fonttext); 
$bordercolors = imagecolorallocate($image, 255, 0, 0); 
$x = 0; 
$y = 0; 
$w = $xsize - 1; //get width image and decrease 1px or points ? 
$h = $ysize - 1; //get height image and decrease 1px or points ? 
imageline($image, $x,$y,$x,$y+$h,$bordercolors); //left 
imageline($image, $x,$y,$x+$w,$y,$bordercolors); //top 
imageline($image, $x+$w,$y,$x+$w,$y+$h,$bordercolors); //right 
imageline($image, $x,$y+$h,$x+$w,$y+$h,$bordercolors); 
header('Content-Type: image/gif'); 

imagegif($image); 
imagedestroy($image); 
?> 

大部分的代码是自我解释。