imagemask() 把坐標 x1,y1 到 x2,y2(圖像左上角為 0, 0)的矩形區(qū)域加上馬賽克.PHP教程
deep為模糊程度,數(shù)字越大越模糊.PHP教程
描邊:void imagetextouter ( resource image, int size, int x, int y, string color, string fontfile, string text, string outercolor)PHP教程
imagetextouter() 將字符串 text 畫到 image 所代表的圖像上,從坐標 x,y(左上角為 0, 0)開始,顏色為 color,邊框所使用的顏色為 outercolor,使用 fontfile 所指定的 truetype 字體文件.PHP教程
如果不指定字體文件,則使用gd的內(nèi)部字體.根據(jù) php 所使用的 gd 庫的不同,如果 fontfile 沒有以 ‘/'開頭,則 ‘.ttf' 將被加到文件名之后并且會搜索庫定義字體路徑.PHP教程
如果指定了字體文件,由 x,y 所表示的坐標定義了第一個字符的基本點(大概是字符的左下角).否則 x,y 定義了第一個字符的右上角.PHP教程
fontfile 是想要使用的 truetype 字體的文件名.PHP教程
text 是文本字符串,可以包含 utf-8 字符序列(形式為:{)來拜訪字體中超過前 255 個的字符.PHP教程
color 是十六進制的#rrggbb格式的顏色,如#ff0000為紅色.PHP教程
outercolor 描邊顏色,十六進制的#rrggbb格式.
PHP教程
<?php
/**
?* gd image text outer
?*
?* @copyright ugia.cn
?
?*/
function imagetextouter(&$im, $size, $x, $y, $color, $fontfile, $text, $outer)
{
??? if (!function_exists('imagecolorallocatehex'))
??? {
??????? function imagecolorallocatehex($im, $s)
??????? {
?????????? if($s{0} == "#") $s = substr($s,1);
?????????? $bg_dec = hexdec($s);
?????????? return imagecolorallocate($im,
?????????????????????? ($bg_dec & 0xff0000) >> 16,
?????????????????????? ($bg_dec & 0x00ff00) >>? 8,
?????????????????????? ($bg_dec & 0x0000ff)
?????????????????????? );
??????? }
??? }
??? $ttf = false;
??? if (is_file($fontfile))
??? {
??????? $ttf = true;
??????? $area = imagettfbbox($size, $angle, $fontfile, $text);
??????? $width? = $area[2] - $area[0] + 2;
??????? $height = $area[1] - $area[5] + 2;
??? }
??? else
??? {
??????? $width? = strlen($text) * 10;
??????? $height = 16;
??? }
??? $im_tmp = imagecreate($width, $height);
??? $white = imagecolorallocate($im_tmp, 255, 255, 255);
??? $black = imagecolorallocate($im_tmp, 0, 0, 0);
??? $color = imagecolorallocatehex($im, $color);
??? $outer = imagecolorallocatehex($im, $outer);
??? if ($ttf)
??? {
??????? imagettftext($im_tmp, $size, 0, 0, $height - 2, $black, $fontfile, $text);
??????? imagettftext($im, $size, 0, $x, $y, $color, $fontfile, $text);
??????? $y = $y - $height + 2;
??? }
??? else
??? {
??????? imagestring($im_tmp, $size, 0, 0, $text, $black);
??????? imagestring($im, $size, $x, $y, $text, $color);
??? }
??? for ($i = 0; $i < $width; $i ++)
??? {
??????? for ($j = 0; $j < $height; $j ++)
??????? {
??????????? $c = imagecolorat($im_tmp, $i, $j);
??????????? if ($c !== $white)
??????????? {
??????????????? imagecolorat ($im_tmp, $i, $j - 1) != $white || imagesetpixel($im, $x + $i, $y + $j - 1, $outer);
??????????????? imagecolorat ($im_tmp, $i, $j + 1) != $white || imagesetpixel($im, $x + $i, $y + $j + 1, $outer);
??????????????? imagecolorat ($im_tmp, $i - 1, $j) != $white || imagesetpixel($im, $x + $i - 1, $y + $j, $outer);
??????????????? imagecolorat ($im_tmp, $i + 1, $j) != $white || imagesetpixel($im, $x + $i + 1, $y + $j, $outer);
??????????????? // 取消注釋,與fireworks的發(fā)光效果相同
??????????????? /*
??????????????? imagecolorat ($im_tmp, $i - 1, $j - 1) != $white || imagesetpixel($im, $x + $i - 1, $y + $j - 1, $outer);
??????????????? imagecolorat ($im_tmp, $i + 1, $j - 1) != $white || imagesetpixel($im, $x + $i + 1, $y + $j - 1, $outer);
??????????????? imagecolorat ($im_tmp, $i - 1, $j + 1) != $white || imagesetpixel($im, $x + $i - 1, $y + $j + 1, $outer);
??????????????? imagecolorat ($im_tmp, $i + 1, $j + 1) != $white || imagesetpixel($im, $x + $i + 1, $y + $j + 1, $outer);
??????????????? */
??????????? }
??????? }
??? }
??? imagedestroy($im_tmp);
}
//用法示例:
header("content-type: image/png");
$im = imagecreatefromjpeg("bluesky.jpg");
$white = imagecolorallocate($im, 255,255,255);
imagetextouter($im, 9, 10, 20, '#000000', "simsun.ttc", '新年快樂', '#ffffff');
imagetextouter($im, 2, 10, 30, '#ffff00', "", 'hello, world!' , '#103993');
imagepng($im);
imagedestroy($im);
?>PHP教程
希望本文所述對大家的PHP程序設計有所贊助.PHP教程