/
image.php
69 lines (59 loc) · 1.27 KB
/
image.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
<?php
require_once "Tools/cuber.php";
require_once "Records/cube.php";
function GetWholeImage()
{
$W = 180;
$H = 130;
$im = imagecreatefromjpeg('http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=220230&type=card');
$dest = imagecreatetruecolor($W, $H);
imagecopy($dest, $im, 0, 0, 20, 40, $W, $H);
header('Content-type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($im);
}
function a($x, $a)
{
return (int)(
255 - ( (255 - $x ) * $a )
);
}
function GetPartialImage($url)
{
$W = 150;
$H = 130;
$F = 80;
$STEP = 1.0 / $F;
$im = imagecreatefromjpeg($url);
$dest = imagecreatetruecolor($W, $H);
imagecopy($dest, $im, 0, 0, 35, 40, $W, $H);
$a = 1;
for( $y = $H - $F; $y < $H; $y++ )
{
for ( $x = 0; $x < $W; $x++ )
{
$i = imagecolorat($dest, $x, $y);
$c = imagecolorsforindex($dest, $i);
$c = imagecolorallocate($dest,
a($c['red'], $a),
a($c['green'], $a),
a($c['blue'], $a)
);
imagesetpixel($dest, $x, $y, $c);
}
$a -= $STEP;
}
header('Content-type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($im);
}
$cube = $_GET["cube"];
$s = DB::zdb()->select()
->from(Cube::$TABLE, array("image"))
->where("id = ?", $cube);
$u = DB::zdb()->fetchOne($s);
if ( $u )
GetPartialImage($u);
?>