php图片加水印原理(超简单的实例代码)
2015-01-24信息快讯网
我看到网上有好多关于图片加水印的类,写的很好 ,我这里只是把相应的原理写下,具体需求,根据自己的情况来修改,很简单的,写的不好,高手见谅
文字水印:
$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下载远程图片函数 可伪造来路
基于PHP服务端图片生成缩略图的方法详解
解析php中两种缩放图片的函数,为图片添加水印
php缩放图片(根据宽高的等比例缩放)实例介绍
php实现多张图片上传加水印技巧
APACHE的AcceptPathInfo指令使用介绍
php加水印的代码(支持半透明透明打水印,支持png透明背景)
php图片的裁剪与缩放生成符合需求的缩略图
php判断上传的Excel文件中是否有图片及PHPExcel库认识
用php实现百度网盘图片直链的代码分享
php图片加中文水印实现代码分享
关于UEditor编辑器远程图片上传失败的解决办法
PHP 图片水印类代码
PHP 透明水印生成代码