好的,我前段時間做過一個項目,完全是這樣,但它獨立於谷歌地圖,儘管我用它來創建動態地圖標記。這裏是整個PHP函數:
<?php
function createImage($number, $color) {
$blank = "/var/www/rbc/dashboard/images/".$color."-0.png";
//$image = @imagecreatefrompng($blank);
$image = LoadPNG($blank);
// pick color for the text
$fontcolor = imagecolorallocate($image, 255, 255, 255);
$font = 2;
$fontsize = 8;
$width = imagefontwidth($font) * strlen($number) ;
$height = imagefontheight($font) ;
$x = (imagesx($image) - $width)/2;
$y = 5;
//white background
$backgroundColor = imagecolorallocate ($image, 255, 255, 255);
//white text
$textColor = imagecolorallocate($image, 255, 255, 255);
// preserves the transparency
imagesavealpha($image, true);
imagealphablending($image, false);
imagestring($image, $font, $x, $y, $number, $textColor);
// tell the browser that the content is an image
header('Content-type: image/png');
// output image to the browser
imagepng($image);
// delete the image resource
imagedestroy($image);
}
function LoadPNG($imgname) {
/* Attempt to open */
$im = imagecreatefrompng($imgname);
/* See if it failed */
if(!$im) {
/* Create a blank image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
if(!isset($_GET['color'])) {
$_GET['color'] = "blue";
}
if(!isset($_GET['number'])) {
$_GET['number'] = "99";
}
createImage($_GET['number'], $_GET['color']);
?>
您與<img src="image.php?color=red&number=2" />
心連心顯示
什麼,你的 「動態圖標」 意思?該術語可以用幾種不同的方式來解釋。 –
我的意思是動態生成的圖標,而不是靜態的。例如,如果您希望使用帶有數字的圖標標記,而不是逐個創建它們,則只需使用以下內容:http://chart.apis.google.com/chart?chst = d_bubble_text_small_withshadow&chld = bbbr | 01 | F15524 | FFFFFF –