1
、介绍
PHP
水印原理和流程
原始图片--》上传到dir --》 载入到PHP -》 PHP初始化 -》 水印处理
2、ImageCreateFrom* 图片载入函数
ImageCreateFrom* 载入PHP是一个将图片编码转成PHP可识别的编码的过程
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromwbmp
imagecreatefrom
string : 通过一串图片编码
使用格式:
imagecreatefromgif
('php100.gif');
3
、
imagecopy
图片合并函数
imagecopy (
Dimg
,
Simg
, int x, int y, int src_x, int src_y, int src_w, int src_h )
Dimg:被加水印的图片
simg:水印图片
x,y:显示在图片的位置(水印图片在图片的显示位置)
src_x,src_y:水印图片从哪里开始显示
src_w,src_h:水印图片的宽度和高度
4
、
ImageCopyResized图片剪切函数
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_x,dst_y:从什么地方开始对齐
src_x,src_y:从哪里开始剪切
int dst_w, int dst_h:新图的大小
int src_w, int src_h:原始图的大小
在使用剪切图之前我们需要先建立一个真彩图,也就是方便内存来存储
<?php
$image="winter.jpg";
//取得图片的大小
$img=GetImageSize($image);
//$img[2] 中存储的是图片的格式
swith($img[2]){
case 1:
$im=@ImageCreateFormGIF($image);
break;
case 2:
$im=@ImageCreateFormJPEG($image);
break;
case 3:
$im=@ImageCreateFormPNG($image);
break;
}
//文字水印
$tc=imagecolorallocate($im,255,255,255);//颜色
$str=iconv("gbk","utf-8","新年");//输出内容
imagettftext($im,12,0,20,20,$tc,'simhe1.ttf',$str);//写入图片
<!--第二个例子-->
//图片水印
$log="1.jpg";
$l=GetImageSize($log);
swith($l2]){
case 1:
$in=@ImageCreateFormGIF($log);
break;
case 2:
$in=@ImageCreateFormJPEG($log);
break;
case 3:
$in=@ImageCreateFormPNG($log);
break;
}
//图片合并
imagecopy($im,$in,400,50,0,0,"120","345");
//输出图片
imageJpeg($im,"新图");
//剪切
//首先建议一个空的真彩图
$new=ImageCreateTrueColor(500,500);
//ImageCopyResized图片剪切函数
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 )
?>