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

相关文章

php cli模式学习(PHP命令行模式)

php cli模式学习(PHP命令行模式)

php_cli模式简介 php-cli是php Command Line Interface的简称,如同它名字的意思,就是php在命令行运行的接口,区别于在Web服务器上运行的php环境...

PHP中Notice错误常见解决方法

对于初学者,肯定会遇到不同的错误提示,比如:警告,致命,等等,其中NOTICE错误等级最低,页面中,好多类似 Notice: Use of undefined constant titl...

PHP计算2点经纬度之间的距离代码

复制代码 代码如下:function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitud...

PHP中数组转换为SimpleXML教程

SimpleXML扩展函数提供了将XML转换为对象的工具集。这些对象处理普通的属性选择器和数组迭代器。 示例1: <?php // 将php数组转换为xml文档的代码...

php使用CURL不依赖COOKIEJAR获取COOKIE的方法

本文实例讲述了php使用CURL不依赖COOKIEJAR获取COOKIE的方法。分享给大家供大家参考。具体分析如下: PHP中CURL类是一个非常牛逼的工具类,具体怎么牛逼就不啰嗦了。...