-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.inc.php
62 lines (50 loc) · 1.59 KB
/
functions.inc.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
<?php
$full_url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$parse_url = parse_url($full_url);
function safeQ($worse) {
// Stripslashes
$okay = htmlspecialchars(stripslashes($worse));
$better = str_ireplace("script", "blocked", $okay);
$good = mysql_escape_string($better);
return $good;
}
function cache_skin($image_url){
//replace with your cache directory
$image_path = '';
//get the name of the file
$exploded_image_url = explode("/",$image_url);
$image_filename = end($exploded_image_url);
$exploded_image_filename = explode(".",$image_filename);
$extension = end($exploded_image_filename);
//make sure its an image
if($extension=="gif"||$extension=="jpg"||$extension=="png"){
//get the remote image
$image_to_fetch = file_get_contents($image_url);
//save it
$local_image_file = fopen($image_path."tmp.png", 'w+');
chmod($image_path."tmp.png",0755);
fwrite($local_image_file, $image_to_fetch);
fclose($local_image_file);
}
}
function skin($username, $clothing, $download){
if (empty($username)) {
echo "No username given";
exit;
}
cache_skin('http://s3.amazonaws.com/MinecraftSkins/'.$username.'.png');
$tmpskin = imagecreatefrompng('tmp.png');
$clothing = imagecreatefrompng("clothes/".$clothing.".png");
if(!isset($clothing)){
$clothing = imagecreatefrompng("assets/img/1x1.png");
}
imagealphablending($tmpskin, true);
imagesavealpha($tmpskin, true);
imagecopy($tmpskin, $clothing, 0, 0, 0, 0, 64, 32);
header('Content-Type: image/png');
if($download){
header('Content-Disposition: attachment; filename="'.$username.'.png"');
}
imagepng($tmpskin);
}
?>