1
<?php
2
function watermask($destination,$waterpngfilename,$pos = 'rb',$transparent = 20)
3
{
4
// 参数分别是 $destination => 图片地址,
5
// $waterpngfilename => 水印图片地址
6
// $pos => 水印位置 lt 左上 lb 左下 rt 右上 rb 右下(默认)
7
// $transparent => 透明度 默认 20
8
$imagetype = array("1"=>"gif","2"=>"jepg","3"=>"png","4"=>"wbmp");
9
$image_size = getimagesize($destination);
10
$iinfo=getimagesize($destination,$iinfo);
11
$f ="imagecreatefrom".$imagetype[$iinfo[2]];
12
$simage = $f($destination);
13
$imagesize_mask = getimagesize($waterpngfilename);
14
$f ="imagecreatefrom".$imagetype[$imagesize_mask[2]];
15
$simage1 = $f($waterpngfilename); // 水印文件
16
// 合并2个文件
17
switch($pos)
18
{
19
case 'lt':
20
imagecopymerge($simage,$simage1,0,0,0,0,$imagesize_mask[0],
21
$imagesize_mask[1],$transparent); // 左上
22
break;
23
case 'lb':
24
imagecopymerge($simage,$simage1,0,$image_size[1]-$imagesize_mask[1]
25
,0,0,$imagesize_mask[0],$imagesize_mask[1],$transparent); // 左下
26
break;
27
case 'rt':
28
imagecopymerge($simage,$simage1,$image_size[0]-$imagesize_mask[0],
29
0,0,0,$imagesize_mask[0],$imagesize_mask[1],$transparent); // 右上
30
break;
31
case 'rb':
32
imagecopymerge($simage,$simage1,$image_size[0]-$imagesize_mask[0],
33
$image_size[1]-$imagesize_mask[1],0,0,$imagesize_mask[0],
34
$imagesize_mask[1],$transparent); // 右下
35
break;
36
}
37
// 输出
38
$f ="image".$imagetype[$iinfo[2]];
39
$f($simage,$destination);
40
imagedestroy($simage);
41
imagedestroy($simage1);
42
}
43
watermask("图片.gif","水印.gif");
44
?>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步