Google Maps Marker Generator with Dynamic Labels

7 views
Skip to first unread message

Bờm Khùng Việt Nam

unread,
Mar 17, 2013, 8:05:22 AM3/17/13
to bkvn...@googlegroups.com
<?php
/*
 * PHP script for generating labeled markers for Google Maps
 * http://vn4ever.com
 *
 * Creates a Google maps marker image with dynamic text; uses
 * an existing image as template, label text comes from querystring
 */


define("FONT_SIZE", 7);                             // font size in points
define("FONT_PATH", "c:/windows/fonts/tahoma.ttf"); // path to the TrueType font file
define("FONT_COLOR", 0x00000000);                   // font color -- the four bytes from left to right represent:
                                                   
// alpha -- 0x00 - 0x7F (solid through transparent)
                                                   
// red   -- 0x00 - 0xFF
                                                   
// green -- 0x00 - 0xFF
                                                   
// blue  -- 0x00 - 0xFF
$text = $_GET["text"];
$gdimage = imagecreatefrompng("marker.png");
imagesavealpha($gdimage, true);
list
(
$x0, $y0, , , $x1, $y1) = imagettfbbox(FONT_SIZE, 0, FONT_PATH, $text);
$imwide = imagesx($gdimage);
$imtall = imagesy($gdimage) - 14;                   // adjusted to exclude the "tail" of the marker
$bbwide = abs($x1 - $x0);
// Code by Vn4ever.Com
$bbtall = abs($y1 - $y0);
$tlx = ($imwide - $bbwide) >> 1;
$tly = ($imtall - $bbtall) >> 1;
imagettftext($gdimage, FONT_SIZE, 0, $tlx, $tly + $bbtall - $y0, FONT_COLOR, FONT_PATH, $text);
header("Content-Type: image/png");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 180) . " GMT");
imagepng($gdimage);
?>


Reply all
Reply to author
Forward
0 new messages