-
Notifications
You must be signed in to change notification settings - Fork 31
/
3.一起学习PHP中GD库的使用(三).php
107 lines (82 loc) · 2.54 KB
/
3.一起学习PHP中GD库的使用(三).php
1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
$imgPath = '../img/2.jpg';
$im = imagecreatefromjpeg($imgPath);
if ($_GET['img'] == -1) {
header("Content-type: image/jpg");
imagejpeg($im);
imagedestroy($im);
}
if ($_GET['img'] == 1) {
$w = imagesx($im);
$h = imagesy($im);
$imNew = imagecreatetruecolor($w / 2, $h / 2);
imagecopyresized($imNew, $im, 0, 0, 0, 0, $w / 2, $h / 2, $w, $h);
header("Content-type: image/jpg");
imagejpeg($imNew);
imagedestroy($imNew);
}
if ($_GET['img'] == 2) {
$w = imagesx($im);
$h = imagesy($im);
$imNew = imagecreatetruecolor($w / 2, $h / 2);
imagecopyresized($imNew, $im, 0, 0, 0, 0, $w / 2, $h / 2, $w, $h);
header("Content-type: image/jpg");
imagejpeg($imNew, null, 10);
imagedestroy($imNew);
}
if ($_GET['img'] == 3) {
$w = imagesx($im);
$h = imagesy($im);
$imNew = imagecreatetruecolor(202, 152);
imagefill($imNew, 0, 0, imagecolorallocate($imNew, 255, 255, 255));
imagerectangle($imNew, 0, 0, 201, 151, imagecolorallocate($imNew, 0, 0, 0));
$sW = 0;
$sH = 0;
if ($w / $h > 200 / 150) {
$q = 200 / $w;
$sH = $h * $q;
$sW = $w * $q;
$sX = 0;
$sY = (150 - $sH) / 2;
} else {
$q = 150 / $h;
$sH = $h * $q;
$sW = $w * $q;
$sX = (200 - $sW) / 2;
$sY = 0;
}
imagecopyresized($imNew, $im, $sX + 2, $sY + 1, 0, 0, $sW, $sH, $w, $h);
header("Content-type: image/jpg");
imagejpeg($imNew);
imagedestroy($imNew);
}
if ($_GET['img'] == 4) {
$imNew = imagecreatetruecolor(150, 30);
imagecolortransparent($imNew, imagecolorallocatealpha($imNew, 255, 255, 255, 128));
imagesavealpha($imNew, true);
$font = '../font/msyh.ttf';
imagettftext($imNew, 16, 0, 11, 21, imagecolorallocate($imNew, 255, 255, 255), $font, '硬核项目经理');
if (imagesx($im) > 150 + 10 && imagesy($im) > 60 + 10) {
imagecopy($im, $imNew, imagesx($im) - 150 - 10, imagesy($im) - 30 - 10, 0, 0, 150, 30);
imagecopymerge($im, $imNew, imagesx($im) - 150 - 10, imagesy($im) - 60 - 10, 0, 0, 150, 30, 50);
}
header("Content-type: image/jpg");
imagejpeg($im);
imagedestroy($im);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<img src="?img=-1"/><br/><br/>
<img src="?img=1" /><br/><br/>
<img src="?img=2" /><br/><br/>
<img src="?img=3"/><br/><br/>
<img src="?img=4"/><br/><br/>
</body>
</html>