激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - PHP教程 - php實(shí)現(xiàn)圖片添加描邊字和馬賽克的方法

php實(shí)現(xiàn)圖片添加描邊字和馬賽克的方法

2020-08-21 12:35PHP之家 PHP教程

這篇文章主要介紹了php實(shí)現(xiàn)圖片添加描邊字和馬賽克的方法,通過自定義函數(shù)imagemask與imagetextouter實(shí)現(xiàn)圖片添加馬賽克與文字描邊的效果,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)圖片添加描邊字和馬賽克的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

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

imagemask() 把坐標(biāo) 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 所代表的圖像上,從坐標(biāo) x,y(左上角為 0, 0)開始,顏色為 color,邊框所使用的顏色為 outercolor,使用 fontfile 所指定的 truetype 字體文件。

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

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

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

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

color 是十六進(jìn)制的#rrggbb格式的顏色,如#ff0000為紅色。

outercolor 描邊顏色,十六進(jìn)制的#rrggbb格式。

復(fù)制代碼 代碼如下:
<?php
/**
 * gd image mask
 *
 * @copyright ugia.cn
 
 */
function imagemask(&$im, $x1, $y1, $x2, $y2, $deep)
{
    for($x = $x1; $x < $x2; $x += $deep)
    {
        for ($y = $y1; $y < $y2; $y += $deep)
        {
            $color = imagecolorat ($im, $x + round($deep / 2), $y + round($deep / 2));
            imagefilledrectangle ($im, $x, $y, $x + $deep, $y + $deep, $color);
        }
    }
}
//馬賽克用法示例:
header("content-type: image/png");
$im = imagecreatefromjpeg("test.jpg");
imagemask($im, 57, 22, 103, 40, 8);
imagepng($im);
imagedestroy($im);
?>

 

運(yùn)行效果如下圖所示:

php實(shí)現(xiàn)圖片添加描邊字和馬賽克的方法

 

復(fù)制代碼 代碼如下:

<?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程序設(shè)計(jì)有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91成人精品 | 久久精品中文字幕一区二区三区 | 成人做爰s片免费看网站 | 极品大长腿啪啪高潮露脸 | 99在线免费观看视频 | 国产成人av免费看 | 欧美 国产 综合 | 欧美日韩精品中文字幕 | 亚洲一区二区三区在线 | 一级电影免费 | 国产大片在线观看 | 日本精品视频一区二区三区四区 | 一级毛片真人免费播放视频 | 99热高清| 亚洲综合视频网站 | 色播久久| 午夜天堂在线视频 | 国产精品99久久久久久久女警 | 久久久久国产一区二区三区不卡 | 蜜桃视频在线免费观看 | 免费在线观看中文字幕 | 国产精品99久久久久久久vr | 久久久久久久久久美女 | 天天看夜夜爽 | 黄色高清免费 | 操操操操操| 久久久久久久久国产精品 | 成人精品免费在线观看 | 久久探花| 免费h片| av电影在线播放 | 久久久久久久亚洲精品 | 国产88久久久国产精品免费二区 | 91久久精品一二三区 | 欧美国产二区 | 久久99精品国产自在现线 | 在线a毛片免费视频观看 | xfplay噜噜av | 成人性视频欧美一区二区三区 | 少妇的肉体2无删减版 | 久久96国产精品久久久 |