common.php
1.7 KB
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
<?php
/**
* 修改图片为圆形
*/
function createRoundImg($imgpath) {
$ename=getimagesize($imgpath);
$ename=explode('/',$ename['mime']);
$ext=$ename[1];
$src_img = null;
switch($ext){
case "png":
$src_img=imagecreatefrompng($imgpath);
break;
case "jpeg":
$src_img=imagecreatefromjpeg($imgpath);
break;
case "jpg":
$src_img=imagecreatefromjpeg($imgpath);
break;
case "gif":
$src_img=imagecreatefromgif($imgpath);
break;
}
$wh = getimagesize($imgpath);
$w = $wh[0];
$h = $wh[1];
$w = $h = min($w, $h);
$image = imagecreatetruecolor($w, $h);
$bg = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagesavealpha($image, true);
imagefill($image, 0, 0, $bg);
$r = $w / 2;
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$rgbColor = imagecolorat($src_img, $x, $y);
if (((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) {
imagesetpixel($image, $x, $y, $rgbColor);
}
}
}
header("content-type:image/png");
imagepng($image,$imgpath);
imagedestroy($image);
}
/**
* 判断远程文件是否存在
*/
function url_exists($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
//不下载
curl_setopt($ch, CURLOPT_NOBODY, 1);
//设置超时
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == 200) {
return true;
}
return false;
}