首页 > 代码库 > PHP之水印

PHP之水印

 1 <?php
 2 
 3     //水印制作
 4     $create_func_list = array(
 5 
 6         image/jpeg => imagecreatefromjpeg,
 7         image/png  => imagecreatefrompng
 8     );
 9 
10     $output_func_list =array(
11 
12         image/jpeg => image/jpeg
13 
14     );
15 
16     //待加水印的图片
17     $dst_file = psb.jpg;
18     $stamp_file = stamp.jpg;
19 
20     $dst_info = getimagesize($dst_file);
21     $dst_mime = $dst_info[mime];
22 
23     $dst_create_func = $create_func_list[$dst_mime];
24     $dst_image = $dst_create_func($dst_file);
25 
26     $stamp_image = imagecreatefromjpeg($stamp_file);
27     $stamp_w = imagesx($stamp_image);
28     $stamp_h = imagesy($stamp_image);
29 
30     //印章位置
31     $dst_x = 200;
32     $dst_y = 80;
33 
34     //印章采样位置
35     $stamp_area_x = 0;
36     $stamp_area_y = 0;
37     $stamp_area_w = $stamp_w;
38     $stamp_area_h = $stamp_h;
39 
40     $pct = 25;
41     //采样 拷贝 合并
42     imagecopymerge($dst_image, $stamp_image, $dst_x, $dst_y, $stamp_area_x,$stamp_area_y , $stamp_area_w,$stamp_area_h , $pct); 
43 
44     header("content-type:image/jpeg");
45     imagejpeg($dst_image);
46     imagedestroy($dst_image);
47     imagedestroy($stamp_image);

 

PHP之水印