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

yipeiwu_com6年前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

相关文章

自制PHP框架之模型与数据库

自制PHP框架之模型与数据库

什么是模型? 我们的WEB系统一定会和各种数据打交道,实际开发过程中,往往一个类对应了关系数据库的一张或多张数据表,这里就会出现两个问题。 1.类和数据表,一方修改会导致另一方的修改,只...

基于PHP创建Cookie数组的详解

创建:复制代码 代码如下:setcookie("ICNet[Reg]", "This is reg cookie", time() + 3600);setcookie("ICNet[Ac...

php快速url重写更新版[需php 5.30以上]

对于apache的rewrite模块打开和设置则非本文主题,请见其他文章详解. 这个类只能php 5.30以上的版本才能使用,继承了上一个版本的快速重定向的特点(单独类,全部使用静态调用...

php调用google接口生成二维码示例

复制代码 代码如下: <?php $data = isset($_GET['t']) ? $_GET['t'] : 'http://www.XXX.com'; $size = is...

php正则表达式(regar expression)

php正则表达式(regar expression)

引言: 在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串 的需要。正则表达式就是用于描述这些规则的语法。 例:在判断用户邮件地址格式、手机号码格式或者采集别人网页内容...