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 UNIX时间戳用法详解

本文实例讲述了php UNIX时间戳用法。分享给大家供大家参考,具体如下: 时间戳是文件属性中的创建、修改、和访问时间。数字时间戳服务是Web网站安全服务项目之一,能提供电子文件的日期和...

php变量与JS变量实现不通过跳转直接交互的方法

本文实例讲述了php变量与JS变量实现不通过跳转直接交互的方法。分享给大家供大家参考,具体如下: 大家都知道如果JS变量要获取后台传来的php变量可以这么写: <?ph...

PHP加密解密实例分析

本文实例讲述了PHP加密解密方法。分享给大家供大家参考,具体如下: //加密 function string2secret($str) { $key = "123"; $td =...

php简单判断两个字符串是否相等的方法

本文实例讲述了php简单判断两个字符串是否相等的方法。分享给大家供大家参考。具体实现方法如下: <?php function strcomp($str1,$str2)...

利用PHPExcel读取Excel的数据和导出数据到Excel

利用PHPExcel读取Excel的数据和导出数据到Excel

PHPExcel是一个PHP类库,用来帮助我们简单、高效实现从Excel读取Excel的数据和导出数据到Excel。也是我们日常开发中,经常会遇到的使用场景。比如有个客户信息表,要批量导...