很多学生都在问我缩略图和打水印怎么做?就算我给了他们现成的功能类,他们也不能理解。这里我把缩略图的打水印主要用到的几个功能函数的中文解释写出来,供大家更好的学习。

1、介绍PHP水印原理和流程
 
          原始图片--》上传到dir --》 载入到内存 -》 PHP初始化 -》 水印处理

2、ImageCreateFrom* 图片载入函数

     ImageCreateFrom* 载入内存是一个将图片文件载入内存供PHP使用的过程

 
   imagecreatefromgif
   imagecreatefromjpeg
   imagecreatefrompng
   imagecreatefromwbmp
   imagecreatefromstring   : 通过一串图片编码

 
使用格式:
   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:原始图的大小

 
在使用剪切图之前我们需要先建立一个真彩图,也就是方便内存来存储

引用
1.2.  
3.    $image="winter.jpg";  
4.  
5.    //取得图片的大小  
6.    $img=GetImageSize($image);  
7.  
8.    //$img[2] 中存储的是图片的格式  
9.    swith($img[2]){  
10.            case 1:  
11.                 $im=@ImageCreateFormGIF($image);  
12.            break;  
13.  
14.           case 2:  
15.                 $im=@ImageCreateFormJPEG($image);  
16.           break;  
17.  
18.           case 3:  
19.                 $im=@ImageCreateFormPNG($image);  
20.            break;  
21.            }  
22.    
23.    //文字水印  
24.   $tc=imagecolorallocate($im,255,255,255);//颜色  
25.     $str=iconv("gbk","utf-8","新年");//输出内容  
26.     imagettftext($im,12,0,20,20,$tc,'simhe1.ttf',$str);//写入图片  
27.    
28.  
29.  
30.  
31.  
32.      //图片水印  
33.    $log="1.jpg";  
34.      $l=GetImageSize($log);  
35.    
36.       swith($l2]){  
37.  
38.              case 1:  
39.                 $in=@ImageCreateFormGIF($log);  
40.               break;  
41.  
42.              case 2:  
43.                $in=@ImageCreateFormJPEG($log);  
44.              break;  
45.  
46.             case 3:  
47.                $in=@ImageCreateFormPNG($log);  
48.              break;  
49.  
50.            }  
51.  
52.     //图片合并  
53.      imagecopy($im,$in,400,50,0,0,"120","345");  
54.  
55.   //输出图片  
56.    imageJpeg($im,"新图");  
57.    
58.//剪切  
59.  
60.//首先建议一个空的真彩图  
61. $new=ImageCreateTrueColor(500,500);  
62.    
63. //ImageCopyResized图片剪切函数    
64.    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 )    
65.  
66.  
67.?>  
Tags: , ,
PHP | 评论(0) | 引用(0) | 阅读(9246)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]