GD Graphix
Google heeft weer iets leuks gemaakt: Google Trends
Nu wil ik zelf ook een soort grafiek-systeem maken, alleen als ik zoiets doe, dan word het zo 'pixelerig'. Nu vind ik dat Google Trends dit totaal niet is.
Heeft iemand enig idee hoe Google dit gemaakt heeft of hoe ik dit in PHP GD zou kunnen doen?
Alvast bedankt,
Miloan
Code (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
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
<?php
/**
* function imageSmoothAlphaLine() - version 1.0
* Draws a smooth line with alpha-functionality
*
* @param ident the image to draw on
* @param integer x1
* @param integer y1
* @param integer x2
* @param integer y2
* @param integer red (0 to 255)
* @param integer green (0 to 255)
* @param integer blue (0 to 255)
* @param integer alpha (0 to 127)
*
* @access public
*
* @author DASPRiD <[email protected]>
*/
function imageSmoothAlphaLine ($image, $x1, $y1, $x2, $y2, $r, $g, $b, $alpha=0) {
$icr = $r;
$icg = $g;
$icb = $b;
$dcol = imagecolorallocatealpha($image, $icr, $icg, $icb, $alpha);
if ($y1 == $y2 || $x1 == $x2)
imageline($image, $x1, $y2, $x1, $y2, $dcol);
else {
$m = ($y2 - $y1) / ($x2 - $x1);
$b = $y1 - $m * $x1;
if (abs ($m) <2) {
$x = min($x1, $x2);
$endx = max($x1, $x2) + 1;
while ($x < $endx) {
$y = $m * $x + $b;
$ya = ($y == floor($y) ? 1: $y - floor($y));
$yb = ceil($y) - $y;
$trgb = ImageColorAt($image, $x, floor($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, $x, floor($y), imagecolorallocatealpha($image, ($tcr * $ya + $icr * $yb), ($tcg * $ya + $icg * $yb), ($tcb * $ya + $icb * $yb), $alpha));
$trgb = ImageColorAt($image, $x, ceil($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, $x, ceil($y), imagecolorallocatealpha($image, ($tcr * $yb + $icr * $ya), ($tcg * $yb + $icg * $ya), ($tcb * $yb + $icb * $ya), $alpha));
$x++;
}
} else {
$y = min($y1, $y2);
$endy = max($y1, $y2) + 1;
while ($y < $endy) {
$x = ($y - $b) / $m;
$xa = ($x == floor($x) ? 1: $x - floor($x));
$xb = ceil($x) - $x;
$trgb = ImageColorAt($image, floor($x), $y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, floor($x), $y, imagecolorallocatealpha($image, ($tcr * $xa + $icr * $xb), ($tcg * $xa + $icg * $xb), ($tcb * $xa + $icb * $xb), $alpha));
$trgb = ImageColorAt($image, ceil($x), $y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel ($image, ceil($x), $y, imagecolorallocatealpha($image, ($tcr * $xb + $icr * $xa), ($tcg * $xb + $icg * $xa), ($tcb * $xb + $icb * $xa), $alpha));
$y ++;
}
}
}
} // end of 'imageSmoothAlphaLine()' function
?>
/**
* function imageSmoothAlphaLine() - version 1.0
* Draws a smooth line with alpha-functionality
*
* @param ident the image to draw on
* @param integer x1
* @param integer y1
* @param integer x2
* @param integer y2
* @param integer red (0 to 255)
* @param integer green (0 to 255)
* @param integer blue (0 to 255)
* @param integer alpha (0 to 127)
*
* @access public
*
* @author DASPRiD <[email protected]>
*/
function imageSmoothAlphaLine ($image, $x1, $y1, $x2, $y2, $r, $g, $b, $alpha=0) {
$icr = $r;
$icg = $g;
$icb = $b;
$dcol = imagecolorallocatealpha($image, $icr, $icg, $icb, $alpha);
if ($y1 == $y2 || $x1 == $x2)
imageline($image, $x1, $y2, $x1, $y2, $dcol);
else {
$m = ($y2 - $y1) / ($x2 - $x1);
$b = $y1 - $m * $x1;
if (abs ($m) <2) {
$x = min($x1, $x2);
$endx = max($x1, $x2) + 1;
while ($x < $endx) {
$y = $m * $x + $b;
$ya = ($y == floor($y) ? 1: $y - floor($y));
$yb = ceil($y) - $y;
$trgb = ImageColorAt($image, $x, floor($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, $x, floor($y), imagecolorallocatealpha($image, ($tcr * $ya + $icr * $yb), ($tcg * $ya + $icg * $yb), ($tcb * $ya + $icb * $yb), $alpha));
$trgb = ImageColorAt($image, $x, ceil($y));
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, $x, ceil($y), imagecolorallocatealpha($image, ($tcr * $yb + $icr * $ya), ($tcg * $yb + $icg * $ya), ($tcb * $yb + $icb * $ya), $alpha));
$x++;
}
} else {
$y = min($y1, $y2);
$endy = max($y1, $y2) + 1;
while ($y < $endy) {
$x = ($y - $b) / $m;
$xa = ($x == floor($x) ? 1: $x - floor($x));
$xb = ceil($x) - $x;
$trgb = ImageColorAt($image, floor($x), $y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel($image, floor($x), $y, imagecolorallocatealpha($image, ($tcr * $xa + $icr * $xb), ($tcg * $xa + $icg * $xb), ($tcb * $xa + $icb * $xb), $alpha));
$trgb = ImageColorAt($image, ceil($x), $y);
$tcr = ($trgb >> 16) & 0xFF;
$tcg = ($trgb >> 8) & 0xFF;
$tcb = $trgb & 0xFF;
imagesetpixel ($image, ceil($x), $y, imagecolorallocatealpha($image, ($tcr * $xb + $icr * $xa), ($tcg * $xb + $icg * $xa), ($tcb * $xb + $icb * $xa), $alpha));
$y ++;
}
}
}
} // end of 'imageSmoothAlphaLine()' function
?>
Het kost alleen veel resources en het resultaat is niet zo mooi als google. Misschien is google charts een idee? http://code.google.com/intl/nl/apis/chart/