A trick could be to manipulate the PNG image with PHP, if this is an option. The following script takes 4 parameters: the image source, the amount of red, green and blue.
image.php script:
$src = $_GET['src'];
$r = $_GET['r'];
$g = $_GET['g'];
$b = $_GET['b'];
$image = @imagecreatefrompng($src);
// Create a new true color image with the same size
$w = imagesx($image);
$h = imagesy($image);
$color = imagecreatetruecolor($w, $h);
// Fill the new image with desired color
$bg = imagecolorallocate($color, $r, $g, $b);
imagefill($color, 0, 0, $bg);
// Copy original transparent image onto the new image
imagecopy($color, $image, 0, 0, 0, 0, $w, $h);
// Serve the image
header("Content-type: image/png");
imagepng($color);
imagedestroy($color);
In javascript, call image.php with the desired parameters:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(0, 0),
map: map,
icon: 'path/to/image.php?src=http://maps.google.com/mapfiles/marker.png&r=100&g=125&b=255'
});
Original image:
Output image:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…