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

yipeiwu_com5年前PHP代码库
文字水印:
复制代码 代码如下:

$w = 80;
$h = 20;
$im = imagecreatetruecolor($w,$h);
$textcolor = imagecolorallocate($im, 123, 12, 255);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $grey); //画一矩形并填充

// 把字符串写在图像左上角
imagestring($im, 3, 2, 3, "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,100,0,0,500,500);
header("Content-type: image/jpeg");

imagejpeg($ground_im);

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

相关文章

Thinkphp和onethink实现微信支付插件

thinkPHP和微支付实现的微信支付插件,在微信中调用微信jssdk实现支付,这里有详细的代码和教程,具体看这里: //实现的Wxpay钩子方法 public funct...

php实现事件监听与触发的方法

本文实例讲述了php实现事件监听与触发的方法。分享给大家供大家参考。具体分析如下: 闲来无事,想了想PHP如何实现事件监听,参考了jQuery的事件绑定思路,简单的实现了一下。 主要功能...

解析左右值无限分类的实现算法

一、引言产品分类,多级的树状结构的论坛,邮件列表等许多地方我们都会遇到这样的问题:如何存储多级结构的数据?在PHP的应用中,提供后台数据存储的通常是关系型数据库,它能够保存大量的数据,提...

php递归函数中使用return的注意事项

php递归函数中使用return的时候会碰到无法正确返回想要的值得情况,如果不明白其中的原因,很难找出错误的,就下面的具体例子来说明一下吧: 复制代码 代码如下: function te...

PHP ADODB实现分页功能简单示例

PHP ADODB实现分页功能简单示例

本文实例讲述了PHP ADODB实现分页功能。分享给大家供大家参考,具体如下: 一、代码 adodb.inc.php可从官方网站http://adodb.sourceforge.net/...