-
Notifications
You must be signed in to change notification settings - Fork 3
/
itemlink.php
142 lines (135 loc) · 3.4 KB
/
itemlink.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
define('IN_MYBB', 1);
require_once ("./global.php");
if(isset($_GET['id'])) $id = $_GET['id'];
unset($_GET['id']);
$sql = mysql_query("SELECT * FROM dbsphere.items WHERE DEFNAME='$id'");
while($item = mysql_fetch_array($sql)) {
fixart($item['ID'],$item['COLOR'],1);
}
if (isset($_GET["id"])) {
$id = $_GET["id"];
if($id[0] == 0)
$id = hexdec($id);
else
$id = intval($id);
if (!(isset($_GET["hue"]))) {
$hue = 0;
} else {
$hue = $_GET["hue"];
if($hue[0] == 0)
$hue = hexdec($hue);
else
$hue = intval($hue);
}
if(!(file_exists("images/art/art_".$id."_".$hue.".png")))
{
include("art.php");
createart($id,$hue,0);
}
if(!(file_exists("images/art/fixedart_".$id."_".$hue.".png")))
fixart($id,$hue,1);
else {
Header("Content-type: image/png");
Header("Content-disposition: inline; filename=art_".$id."_".$hue.".png");
$img = imagecreatefrompng("images/art/fixedart_".$id."_".$hue.".png");
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
imagepng($img);
imagedestroy($img);
}
exit;
}
function fixart($id,$hue,$show) {
if(!(file_exists("images/art/fixedart_".$id."_".$hue.".png")))
{
if(!(file_exists("images/art/art_".$id."_".$hue.".png")))
{
include("art.php");
createart($id,$hue,0);
}
$imgurl = "images/art/art_".$id."_".$hue.".png";
$img = imagecreatefrompng("$imgurl");
$box = imageTrimBox($img);
$img2 = imagecreatetruecolor($box['w'], $box['h']);
imagecopy($img2, $img, 0, 0, $box['l'], $box['t'], $box['w'], $box['h']);
imagepng($img2,'images/art/fixedart_'.$id.'_'.$hue.'.png',0,NULL);
imagedestroy($img);
imagedestroy($img2);
}
if($show == 1) {
Header("Content-type: image/png");
Header("Content-disposition: inline; filename=art_".$id."_".$hue.".png");
$img = imagecreatefrompng("images/art/fixedart_".$id."_".$hue.".png");
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
imagepng($img);
imagedestroy($img);
return;
}
}
function imageTrimBox($img, $hex=null) {
if (!ctype_xdigit($hex)) { $hex = imagecolorat($img, 0,0); }
$b_top = $b_lft = 0;
$b_rt = $w1 = $w2 = imagesx($img);
$b_btm = $h1 = $h2 = imagesy($img);
do {
//top
for(; $b_top < $h1; ++$b_top) {
for($x = 0; $x < $w1; ++$x) {
if(imagecolorat($img, $x, $b_top) != $hex) {
break 2;
}
}
}
// stop if all pixels are trimmed
if ($b_top == $b_btm) {
$b_top = 0;
$code = 2;
break 1;
}
// bottom
for(; $b_btm >= 0; --$b_btm) {
for($x = 0; $x < $w1; ++$x) {
if(imagecolorat($img, $x, $b_btm-1) != $hex) {
break 2;
}
}
}
// left
for(; $b_lft < $w1; ++$b_lft) {
for($y = $b_top; $y <= $b_btm; ++$y) {
if(imagecolorat($img, $b_lft, $y) != $hex) {
break 2;
}
}
}
// right
for(; $b_rt >= 0; --$b_rt) {
for($y = $b_top; $y <= $b_btm; ++$y) {
if(imagecolorat($img, $b_rt-1, $y) != $hex) {
break 2;
}
}
}
$w2 = $b_rt - $b_lft;
$h2 = $b_btm - $b_top;
$code = ($w2 < $w1 || $h2 < $h1) ? 1 : 0;
} while (0);
// result codes:
// 0 = Trim Zero Pixels
// 1 = Trim Some Pixels
// 2 = Trim All Pixels
return array(
'#' => $code, // result code
'l' => $b_lft, // left
't' => $b_top, // top
'r' => $b_rt, // right
'b' => $b_btm, // bottom
'w' => $w2, // new width
'h' => $h2, // new height
'w1' => $w1, // original width
'h1' => $h1, // original height
);
}
?>