-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile_picture.php
53 lines (44 loc) · 1.38 KB
/
profile_picture.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
<?php
function getPath($user, $local) {
if($local) {
return __DIR__ . "/html/assets/users/".$user."/avatar/";
} else {
//$p = explode("/", __DIR__);
//array_pop($p);
//$p = implode("/", $p);
//return $p . "/html/info/assets/users/".$user."/avatar/";
return "./assets/users/{$user}/avatar/";
}
}
function getPicName($user, $local, $root) {
$path = getPath($user, $local);
if(is_dir( $path )) {
return $root . "assets/users/" . $user . "/avatar/" . scandir($path)[2];
}
return $root . "assets/avatar.png";
}
function getImageTagForHTML($user, $local, $root) {
$path = getPicName($user, $local, $root);
return '<img class="profile-pic" src="' . $path . '" alt="Avatar">';
}
function imagecreatefromfile( $filename ) {
if (!file_exists($filename)) {
throw new InvalidArgumentException('File "'.$filename.'" not found.');
}
switch ( strtolower( pathinfo( $filename, PATHINFO_EXTENSION ))) {
case 'jpeg':
case 'jpg':
return imagecreatefromjpeg($filename);
break;
case 'png':
return imagecreatefrompng($filename);
break;
case 'gif':
return imagecreatefromgif($filename);
break;
default:
throw new InvalidArgumentException('File "'.$filename.'" is not valid jpg, png or gif image.');
break;
}
}
?>