国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php圖片上添加描邊字和馬賽克

2024-09-04 11:44:32
字體:
供稿:網(wǎng)友

馬賽克:void imagemask ( resource image, int x1, int y1, int x2, int y2, int deep)

imagemask() 把坐標 x1,y1 到 x2,y2(圖像左上角為 0, 0)的矩形區(qū)域加上馬賽克。

deep為模糊程度,數(shù)字越大越模糊。

描邊:void imagetextouter ( resource image, int size, int x, int y, string color, string fontfile, string text, string outercolor)

imagetextouter() 將字符串 text 畫到 image 所代表的圖像上,從坐標 x,y(左上角為 0, 0)開始,顏色為 color,邊框所使用的顏色為 outercolor,使用 fontfile 所指定的 truetype 字體文件。

如果不指定字體文件,則使用gd的內(nèi)部字體。根據(jù) php 所使用的 gd 庫的不同,如果 fontfile 沒有以 ‘/’開頭,則 ‘.ttf’ 將被加到文件名之后并且會搜索庫定義字體路徑。

如果指定了字體文件,由 x,y 所表示的坐標定義了第一個字符的基本點(大概是字符的左下角)。否則 x,y 定義了第一個字符的右上角。

fontfile 是想要使用的 truetype 字體的文件名。

text 是文本字符串,可以包含 utf-8 字符序列(形式為:{)來訪問字體中超過前 255 個的字符。

color 是十六進制的#rrggbb格式的顏色,如#ff0000為紅色。

outercolor 描邊顏色,十六進制的#rrggbb格式。

  1. <?php 
  2. /** 
  3.  * gd image mask 
  4.  * 
  5.  * @copyright ugia.cn 
  6.  
  7.  */ 
  8. function imagemask(&$im$x1$y1$x2$y2$deep
  9. {//開源代碼Vevb.com 
  10.     for($x = $x1$x < $x2$x += $deep
  11.     { 
  12.         for ($y = $y1$y < $y2$y += $deep
  13.         { 
  14.             $color = imagecolorat ($im$x + round($deep / 2), $y + round($deep / 2)); 
  15.             imagefilledrectangle ($im$x$y$x + $deep$y + $deep$color); 
  16.         } 
  17.     } 
  18. ?> 
  19. //示例: 
  20. <?php 
  21. header("content-type: image/png"); 
  22. $im = imagecreatefromjpeg("test.jpg"); 
  23. imagemask($im, 57, 22, 103, 40, 8); 
  24. imagepng($im); 
  25. imagedestroy($im); 
  26. ?> 
  27.  
  28. <?php 
  29. /** 
  30.  * gd image text outer 
  31.  * 
  32.  * @copyright ugia.cn 
  33.  
  34.  */ 
  35. function imagetextouter(&$im$size$x$y$color$fontfile$text$outer
  36.     if (!function_exists('imagecolorallocatehex')) 
  37.     { 
  38.         function imagecolorallocatehex($im$s
  39.         { 
  40.            if($s{0} == "#"$s = substr($s,1); 
  41.            $bg_dec = hexdec($s); 
  42.            return imagecolorallocate($im
  43.                        ($bg_dec & 0xff0000) >> 16, 
  44.                        ($bg_dec & 0x00ff00) >>  8, 
  45.                        ($bg_dec & 0x0000ff) 
  46.                        ); 
  47.         } 
  48.     } 
  49.     $ttf = false; 
  50.     if (is_file($fontfile)) 
  51.     { 
  52.         $ttf = true; 
  53.         $area = imagettfbbox($size$angle$fontfile$text); 
  54.         $width  = $area[2] - $area[0] + 2; 
  55.         $height = $area[1] - $area[5] + 2; 
  56.     } 
  57.     else 
  58.     { 
  59.         $width  = strlen($text) * 10; 
  60.         $height = 16; 
  61.     } 
  62.     $im_tmp = imagecreate($width$height); 
  63.     $white = imagecolorallocate($im_tmp, 255, 255, 255); 
  64.     $black = imagecolorallocate($im_tmp, 0, 0, 0); 
  65.     $color = imagecolorallocatehex($im$color); 
  66.     $outer = imagecolorallocatehex($im$outer); 
  67.     if ($ttf
  68.     { 
  69.         imagettftext($im_tmp$size, 0, 0, $height - 2, $black$fontfile$text); 
  70.         imagettftext($im$size, 0, $x$y$color$fontfile$text); 
  71.         $y = $y - $height + 2; 
  72.     } 
  73.     else 
  74.     { 
  75.         imagestring($im_tmp$size, 0, 0, $text$black); 
  76.         imagestring($im$size$x$y$text$color); 
  77.     } 
  78.     for ($i = 0; $i < $width$i ++) 
  79.     { 
  80.         for ($j = 0; $j < $height$j ++) 
  81.         { 
  82.             $c = imagecolorat($im_tmp$i$j); 
  83.             if ($c !== $white
  84.             { 
  85.                 imagecolorat ($im_tmp$i$j - 1) != $white || imagesetpixel($im$x + $i$y + $j - 1, $outer); 
  86.                 imagecolorat ($im_tmp$i$j + 1) != $white || imagesetpixel($im$x + $i$y + $j + 1, $outer); 
  87.                 imagecolorat ($im_tmp$i - 1, $j) != $white || imagesetpixel($im$x + $i - 1, $y + $j$outer); 
  88.                 imagecolorat ($im_tmp$i + 1, $j) != $white || imagesetpixel($im$x + $i + 1, $y + $j$outer); 
  89.                 // 取消注釋,與fireworks的發(fā)光效果相同 
  90.                 /* 
  91.                 imagecolorat ($im_tmp, $i - 1, $j - 1) != $white || imagesetpixel($im, $x + $i - 1, $y + $j - 1, $outer); 
  92.                 imagecolorat ($im_tmp, $i + 1, $j - 1) != $white || imagesetpixel($im, $x + $i + 1, $y + $j - 1, $outer); 
  93.                 imagecolorat ($im_tmp, $i - 1, $j + 1) != $white || imagesetpixel($im, $x + $i - 1, $y + $j + 1, $outer); 
  94.                 imagecolorat ($im_tmp, $i + 1, $j + 1) != $white || imagesetpixel($im, $x + $i + 1, $y + $j + 1, $outer); 
  95.                 */ 
  96.             } 
  97.         } 
  98.     } 
  99.     imagedestroy($im_tmp); 
  100. ?> 
  101. //示例: 
  102. <?php 
  103. header("content-type: image/png"); 
  104. $im = imagecreatefromjpeg("bluesky.jpg"); 
  105. $white = imagecolorallocate($im, 255,255,255); 
  106. imagetextouter($im, 9, 10, 20, '#000000'"simsun.ttc"'新年快樂''#ffffff'); 
  107. imagetextouter($im, 2, 10, 30, '#ffff00'""'hello, world!' , '#103993'); 
  108. imagepng($im); 
  109. imagedestroy($im); 
  110. ?>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 娄烦县| 安达市| 怀仁县| 苗栗市| 平定县| 象州县| 涿州市| 怀远县| 汶川县| 永寿县| 特克斯县| 固原市| 株洲市| 铜梁县| 利津县| 莱阳市| 夏河县| 兴隆县| 佛坪县| 临沂市| 浑源县| 静宁县| 望都县| 黔西| 宜兴市| 清原| 宜昌市| 仙游县| 泌阳县| 河池市| 平邑县| 朔州市| 越西县| 维西| 湛江市| 博客| 敦化市| 沈阳市| 柘荣县| 金乡县| 泰顺县|