好的,我前段时间做了一个项目,它确实做到了这一点,但它独立于谷歌地图,即使我用它来创建动态地图标记。这是整个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" />
高温高压