加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php图片加水印原理(超简单的实例代码)

发布时间:2020-12-13 06:13:18 所属栏目:PHP教程 来源:网络整理
导读:文字水印: div class="codetitle" a style="CURSOR: pointer" data="6954" class="copybut" id="copybut6954" onclick="doCopy('code6954')" 代码如下: div class="codebody" id="code6954" $w = 80; $h = 20; $im = imagecreatetruecolor($w,$h); $textcolo

文字水印:
<div class="codetitle"><a style="CURSOR: pointer" data="6954" class="copybut" id="copybut6954" onclick="doCopy('code6954')"> 代码如下:<div class="codebody" id="code6954">
$w = 80;
$h = 20;
$im = imagecreatetruecolor($w,$h);
$textcolor = imagecolorallocate($im,123,12,255);
$white = imagecolorallocate($im,255,255);
$grey = imagecolorallocate($im,128,128);
$black = imagecolorallocate($im,0);
imagefilledrectangle($im,399,29,$grey); //画一矩形并填充 // 把字符串写在图像左上角
imagestring($im,3,2,"Hello world!",$textcolor); // 输出图像
header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im); 图片水印 $groundImg = "DSC05940.jpeg";
$groundInfo = getimagesize($groundImg);
$ground_w = $groundInfo[0];
//print_r($groundInfo);
$ground_h = $groundInfo[1];
switch($groundInfo[2]){
case 1:
$ground_im = imagecreatefromgif($groundImg);
break;
case 2:
$ground_im = imagecreatefromjpeg($groundImg);
break;
case 3:
$ground_im = imagecreatefrompng($groundImg);
break;
} $waterImg = "DSC05949.jpeg";
$imgInfo =getimagesize($waterImg);
$water_w = $imgInfo[0];
$water_w = $imgInfo[1]; switch($imgInfo[2]){
case 1:
$water_im = imagecreatefromgif($waterImg);
break;
case 2:
$water_im = imagecreatefromjpeg($waterImg);
break;
case 3:
$water_im = imagecreatefrompng($waterImg);
break;
}
imagecopy($ground_im,$water_im,100,500,500);
header("Content-type: image/jpeg"); imagejpeg($ground_im);

合并图片php提供了很多函数:例如:imagecopymerge,imagecopyresized

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读