Ik wil voor mijn avatarscript dat het aantal keer dat de avatar geviewd is erop weergeven. Ik heb dat helemaal werkend gekregen op mijn eigen servertje, maar op mijn remote server werkt het niet, omdat daar een oudere versie van PHP draait, namelijk 4.2.x. Het blijkt dat imagecolorallocatealpha een versie hoger dan 4.3.2 wil zien. Nou vroeg ik me af of er een alternatief is om een transparant blokje met daarop tekst te tekenen m.b.v. PHP/GD. Ik heb wat zitten kloten met imagealphablending(), maar daar kwam niet veel soeps uit.
Dit is het stuk code dat mijn blokje weergeeft. Misschien dat iemand weet hoe het anders kan, zonder imagecolorallocatealpha?
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
| $background = imagecreatetruecolor($width, $height); switch ($mimeType) { case "image/jpeg": $foreground = imagecreatefromjpeg($folder.$image); break; case "image/png": $foreground = imagecreatefrompng ($folder.$image); break; case "image/gif": $foreground = imagecreatefromgif ($folder.$image); break; case "image/vnd.wap.wbmp": $foreground = imagecreatefromwbmp ($folder.$image); break; } imagecopyresampled($background, $foreground, 0, 0, 0, 0, $width, $height, $imgInfo[0], $imgInfo[1]); if (function_exists("imagecolorallocatealpha")) { $link = mysql_connect("host", "user", "pass"); $DB = mysql_select_db("database", $link); mysql_query("UPDATE avatar_view SET views = views + 1"); $aantal = mysql_result(mysql_query("SELECT views FROM avatar_view LIMIT 0,1"), 0); $aantal = putCommas($aantal); for ($i = 0; $i < $blockheight; $i++) { $color = ImageColorAllocateAlpha($background, 255, 255, 255, $i * ceil(127 / $blockheight - 1)); ImageLine($background, 0, $height - $i, $width - 1, $height - $i, $color); } $green = ImageColorAllocate($background, 0, 48, 0); $offset = ($width - (imagefontwidth(1) * strlen($aantal))) / 2; imagestring($background, 1, $offset, $height - ($blockheight - 2), $aantal, $green); } imagepng($background); |
Dit is het stuk code dat mijn blokje weergeeft. Misschien dat iemand weet hoe het anders kan, zonder imagecolorallocatealpha?
[ Voor 41% gewijzigd door NMe op 05-06-2004 15:21 . Reden: Code aangepast op overloopeffect ]
'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.