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关于表单提交特殊字符的处理方法做个汇总,主要涉及htmlspecialchars/addslashes/stripslashes/strip_tags/mysql_real_esc...

php中switch语句用法详解

本文介绍php中的switch语句的用法,它跟其他语句中的switch用法差不多的,但注意有有一个break语句。 PHP中switch语句的标准语法: switch (expre...

php下批量挂马和批量清马代码

复制代码 代码如下:<?php function gmfun($path=”.”) { $d = @dir($path); while(false !== ($v = $d->...

PHP设计模式之单例模式定义与用法分析

本文实例分析了PHP设计模式之单例模式。分享给大家供大家参考,具体如下: 单例模式(Singleton Pattern 单件模式或单元素模式),是常见的一种设计模式,它有三个特点...

PHP发送邮件确认验证注册功能示例【修改别人邮件类】

PHP发送邮件确认验证注册功能示例【修改别人邮件类】

本文实例讲述了PHP发送邮件确认验证注册功能。分享给大家供大家参考,具体如下: 类库: require "class.phpmailer.php"; require "class....