一、水印制作
1.水印文字
PHP 中为图片打上水印文字主要是通过 GD 库提供的 imagettftext() 函数来实现的。
其过程为:载入图片 =》 调好水印文字的颜色 =》 打上水印
奥硕企业网站管理系统具有一下特色功能1、双语双模(中英文采用单独模板设计,可制作中英文不同样式的网站)2、在线编辑JS动态菜单支持下拉效果,同时生成中文,英文,静态3个JS菜单3、在线制作并调用FLASH展示动画4、自动生成缩略图,可以自由设置宽高5、图片批量加水印,可以自由设置字体,大小,样式,水印位置(同时支持文字或图片类型水印)6、强大的标签式数据调用,可以调用(新闻,产品,下载,招聘)支持
<?php
$img = 'Desert.jpg';//图像的路径。这里以 Windows 7 自带的一幅沙漠的图片为例
$img_info = getimagesize($img);
//载入图像到PHP,转成 PHP 可识别的编码
switch($img_info[2]) {
case 1:
$res = imagecreatefromgif($img);//返回一图像标识符,代表了从给定的文件名取得的图像。
break;
case 2:
$res = imagecreatefromjpeg($img);
break;
case 3:
$res = imagecreatefrompng($img);
break;
}
// 为一幅图像分配颜色(相当于 PhotoShop 的调色板)
// imagecolorallocate ( resource image, int red, int green, int blue ) 返回一个标识符,代表了由给定的 RGB 成分组成的颜色。
$te = imagecolorallocate($res,225,225,225);
//rand(0,10)倾斜度。msyh.ttf 是微软雅黑字体,可在 C:\Windows\Fonts 找到。然后拷贝到该文件的目录下
imagettftext($res,12,rand(0,10),20,80,$te,'msyh.ttf',"我的博客 www.woqilin.net");
switch($img_info[2]) {
case 1:
header("Content-type: image/gif");
imagegif($res);//以 GIF 格式将图像输出到浏览器
break;
case 2:
header("Content-type: image/jpeg");
imagejpeg($res);
break;
case 3:
header("Content-type: image/png");
imagepng($res);
break;
}
?>2.水印图片
PHP 中为图片打上图片水印是通过 imagecopy() 函数来实现的。
立即学习“PHP免费学习笔记(深入)”;
<?php
$img = 'Desert.jpg';//图像的路径。这里以 Windows 7 下一幅沙漠的图片为例,像素为 1024 X 768
$img_info = getimagesize($img);
//载入图像到PHP
switch($img_info[2]) {
case 1:
$res = imagecreatefromgif($img);//返回一图像标识符,代表了从给定的文件名取得的图像。
break;
case 2:
$res = imagecreatefromjpeg($img);
break;
case 3:
$res = imagecreatefrompng($img);
break;
}
//新建一个真彩色图像
$new = imagecreatetruecolor(400,400);
//bool imagecopyresized ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
//将一幅图像中的一块正方形区域拷贝到另一个图像中。dst_image 和 src_image 分别是目标图像和源图像的标识符。如果源和目标的宽度和高度不同,则会进行相应的图像收缩和拉伸。坐标指的是左上角。本函数可用来在同一幅图内部拷贝(如果 dst_image 和 src_image 相同的话)区域,但如果区域交迭的话则结果不可预知。
imagecopyresized($new,$res,0,0,0,0,400,400,$img_info[0],$img_info[1]);
header("Content-type: image/png");
imagepng($new);// 以 PNG 格式将图像输出到浏览器
?>










