實現(xiàn)代碼如下:復制代碼 代碼如下:$dst_path = 'dst.jpg';//創(chuàng)建圖片的實例$dst = imagecreatefromstring(file_get " /> 精品亚洲国产成av人片传媒 ,日韩欧美中文字幕电影,国产999精品久久久

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php文字水印和php圖片水印實現(xiàn)代碼(二種加水印方法)

文字水印

文字水印就是在圖片上加上文字,主要使用gd庫的imagefttext方法,并且需要字體文件。效果圖如下:

實現(xiàn)代碼如下:

復制代碼 代碼如下:
$dst_path = 'dst.jpg';

//創(chuàng)建圖片的實例
$dst = imagecreatefromstring(file_get_contents($dst_path));

//打上文字
$font = './simsun.ttc';//字體
$black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字體顏色
imagefttext($dst, 13, 0, 20, 20, $black, $font, '快樂編程');

//輸出圖片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
    case 1://GIF
        header('Content-Type: image/gif');
        imagegif($dst);
        break;
    case 2://JPG
        header('Content-Type: image/jpeg');
        imagejpeg($dst);
        break;
    case 3://PNG
        header('Content-Type: image/png');
        imagepng($dst);
        break;
    default:
        break;
}

imagedestroy($dst);

圖片水印

圖片水印就是將一張圖片加在另外一張圖片上,主要使用gd庫的imagecopy和imagecopymerge。效果圖如下:

實現(xiàn)代碼如下:

復制代碼 代碼如下:
$dst_path = 'dst.jpg';
$src_path = 'src.jpg';

//創(chuàng)建圖片的實例
$dst = imagecreatefromstring(file_get_contents($dst_path));
$src = imagecreatefromstring(file_get_contents($src_path));

//獲取水印圖片的寬高
list($src_w, $src_h) = getimagesize($src_path);

//將水印圖片復制到目標圖片上,最后個參數(shù)50是設(shè)置透明度,這里實現(xiàn)半透明效果
imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50);
//如果水印圖片本身帶透明色,則使用imagecopy方法
//imagecopy($dst, $src, 10, 10, 0, 0, $src_w, $src_h);

//輸出圖片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
    case 1://GIF
        header('Content-Type: image/gif');
        imagegif($dst);
        break;
    case 2://JPG
        header('Content-Type: image/jpeg');
        imagejpeg($dst);
        break;
    case 3://PNG
        header('Content-Type: image/png');
        imagepng($dst);
        break;
    default:
        break;
}

imagedestroy($dst);
imagedestroy($src);

php技術(shù)php文字水印和php圖片水印實現(xiàn)代碼(二種加水印方法),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 固阳县| 交城县| 延长县| 新源县| 西充县| 讷河市| 汾阳市| 广宁县| 吉隆县| 阿坝| 靖边县| 海南省| 德阳市| 鱼台县| 海伦市| 嘉禾县| 大同市| 甘泉县| 蒙阴县| 大余县| 岳阳市| 柯坪县| 大同市| 珲春市| 荣成市| 洪泽县| 纳雍县| 扬中市| 莎车县| 百色市| 绍兴县| 叶城县| 宁德市| 尉犁县| 光泽县| 九龙城区| 新昌县| 鹤壁市| 正安县| 萨迦县| 腾冲县|