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 多关键字 高亮显示实现代码

php 多关键字 高亮显示实现代码

项目结构: 开始搜索:   这里搜索关键字("大""这") 搜索结果:  高亮显示 项目所需数据库结构: 实现代码: conn.php 复制代码 代码...

PHP实现动态创建XML文档的方法

PHP实现动态创建XML文档的方法

本文实例讲述了PHP实现动态创建XML文档的方法。分享给大家供大家参考,具体如下: 一. 代码 conn.php <?php $id=mysql_connect("lo...

php文件操作之文件写入字符串、数组的方法分析

php文件操作之文件写入字符串、数组的方法分析

本文实例讲述了php文件操作之文件写入字符串、数组的方法。分享给大家供大家参考,具体如下: 场景一:用文本文档记录一些操作日志,因为对于一些频繁的操作,操作记录的数据量势必会很大,...

php输出文字乱码的解决方法

php输出文字乱码的解决办法: 在php文件最开头写上: <?php header('Content-type: text/html; charset=UTF8');...

phplist及phpmailer(组合使用)通过gmail发送邮件的配置方法

本文实例讲述了phplist及phpmailer通过gmail发送邮件的配置方法。分享给大家供大家参考,具体如下: 一般来说,只要你使用的不是gmail邮箱,那么利用phplist发送邮...