php 图片添加文字水印 以及 图片合成(微信快码传播)
1、图片添加文字水印:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | $bigImgPath= 'backgroud.png';    $img= imagecreatefromstring(file_get_contents($bigImgPath));    $font= 'msyhl.ttc';//字体    $black= imagecolorallocate($img, 0, 0, 0);//字体颜色 RGB    $fontSize= 20;   //字体大小    $circleSize= 60; //旋转角度    $left= 50;      //左边距    $top= 150;       //顶边距    imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, 'Rhythmk| 坤');    list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);    switch($bgType) {        case1: //gif            header('Content-Type:image/gif');            imagegif($img);            break;        case2: //jpg            header('Content-Type:image/jpg');            imagejpeg($img);            break;        case3: //jpg            header('Content-Type:image/png');            imagepng($img);            break;        default:            break;    }    imagedestroy($img); | 
效果:
    
2、图片合成
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | $bigImgPath= 'backgroud.png';$qCodePath= 'qcode.png';$bigImg= imagecreatefromstring(file_get_contents($bigImgPath));$qCodeImg= imagecreatefromstring(file_get_contents($qCodePath));list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);// imagecopymerge使用注解imagecopymerge($bigImg, $qCodeImg, 200, 300, 0, 0, $qCodeWidth, $qCodeHight, 100);list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);switch($bigType) {    case1: //gif        header('Content-Type:image/gif');        imagegif($bigImg);        break;    case2: //jpg        header('Content-Type:image/jpg');        imagejpeg($bigImg);        break;    case3: //jpg        header('Content-Type:image/png');        imagepng($bigImg);        break;    default:        # code...        break;}imagedestroy($bigImg);imagedestroy($qcodeImg); | 
函数注解:
imagecopymerge()
imagecopymerge() 函数用于拷贝并合并图像的一部分,成功返回 TRUE ,否则返回 FALSE 。
语法:
bool imagecopymerge( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct )
参数说明:
dst_im 目标图像
src_im 被拷贝的源图像
dst_x 目标图像开始 x 坐标
dst_y 目标图像开始 y 坐标,x,y同为 0 则从左上角开始
src_x 拷贝图像开始 x 坐标
src_y 拷贝图像开始 y 坐标,x,y同为 0 则从左上角开始拷贝
src_w (从 src_x 开始)拷贝的宽度
src_h (从 src_y 开始)拷贝的高度
pct 图像合并程度,取值 0-100 ,当 pct=0 时,实际上什么也没做,反之完全合并。
效果图:

https://www.cnblogs.com/rhythmK/p/5426050.html
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号 
