-
-
/**
- * GD 圖片文字外層
- *
- * @copyright UGiA.CN
- * [url=home.php?mod=space&uid=17823]@LINK[/url] www.ugia.cn / ?p=88
- * @edit bbs.it-home.org
- */
- function imagetextouter(&$im, $size, $x, $y, $顏色, $fontfile, $text, $outer)
- {
- if (!function_exists('ImageColorAllocateHEX'))
- {
- function ImageColorAllocateHEX($im, $s)
- 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)
- );
- } 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 = imagecreate($width, $height);
- $white = imagecolorallocate($ im_tmp, 255, 255, 255);
- $black = imagecolorallocate($im_tmp, 0, 0, 0);
- $color = ImageColorAllocateHEX($im, $color);
- $color = ImageColorAllocateHEX($im, $color);
- $color = ImageColorAllocateHEX($im, $color);
- $.m = ImageColorAllocateHEX($im, $color);
- $ $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
- {
- 映像字串($im_tmp, $size, 0, 0, $text, $black);
- 映像字串($im, $size, $x, $y, $text, $顏色);
- }
- For ($i = 0; $i {
- for ($j = 0; $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的發光效果相同
- /*
- 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);
} imagedestroy($im_tmp); } imagedestroy($im_tmp); } imagedestroy($im_tmp); } imagedestroy($im_tmp); } imagedestroy($im_tmp);- }
- ?>
-
-
- 複製程式碼
-
-
- 2,呼叫範例:
-
-
header("內容類型:image/png"); $im = imagecreatefromjpeg("bluesky.jpg "bluesky.jpg " ; $white = imagecolorallocate($im, 255,255,255); imagetextouter($im, 9, 10, 20, '#000000', "simsun.ttc", '新年快樂', '#ffffff ') ; imagetextouter($im, 2, 10, 30, '#FFFF00', "", '你好,世界!', '#103993'); imagepng($im); imagedestroy ($im); ?>
複製程式碼-
-
- 感謝馬賽克:void imagemask (resource image, int x1, int y1, int x2 , inty int x1, int y1, int x2 , inty int x1, int y1, int x2 , inty int x1, int , int 深)
imagemask() 把座標 x1,y1 到 x2,y2(圖左上角為 0, 0)的幾何加上馬賽克。
深為模糊程度,數字越大越模糊。
- 效果,如下圖:
-
-
- 1,馬賽克函數程式碼:
-
-
-
-
-
-
/**
- * GD 影像遮罩
- *
- * @edit bbs.it-home.org
- */
- 函數 imagemask(&$im, $x1, $y1, $ x2 , $y2, $deep)
{ for($x = $x1; $x { for ($y = $y1 ; $ y { $color = ImageColorAt ($im, $x round($deep / 2), $y round($deep / 2)); imagefilledrectangle ($im, $x, $y, $x $deep, $y $deep, $color); } }}?>複製程式碼 2,呼叫範例:
-
-
header("Content-type: image/png");
- $im = imagecreatefromjpeg("test.jpg" );
- imagemask($im, 57, 22, 103, 40, 8);
- imagepng($im);
- imagedestroy($im);
- ?>
複製程式碼
|