[aprssig] LINUX PERL GD images on the fly
Andrew Rich vk4tec at people.net.auSun Aug 12 02:14:04 UTC 2007
- Previous message: [aprssig] DR-135TP - EJ-41U TNC / T2-135
- Next message: [aprssig] APRS New Initiative and the D710
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Those looking for an instant image creation solution for tracking may be interested in this. I take data and stream it into mysql. I then use PERL GD to create an image on the fly. Here is an example http://vk4tec.no-ip.org/cgi-bin/adsb_create_image.cgi And the code #!/usr/bin/perl -w use CGI; use GD; use DBI; $x=0; $y=0; my $query = new CGI; my $database_handler = DBI->connect("DBI:mysql:adsb:host=localhost","root",""); $query1="delete from data where latitude like '%000%'; "; $statement_handler=$database_handler->prepare ($query1); $statement_handler->execute; $query1="select min(latitude) from data "; $statement_handler=$database_handler->prepare ($query1); $statement_handler->execute; $min_lat = $statement_handler -> fetchrow() ; $query1="select min(longitude) from data"; $statement_handler=$database_handler->prepare ($query1); $statement_handler->execute; $min_lon = $statement_handler -> fetchrow() ; $query1="select max(latitude) from data "; $statement_handler=$database_handler->prepare ($query1); $statement_handler->execute; $max_lat = $statement_handler -> fetchrow() ; $query1="select max(longitude) from data"; $statement_handler=$database_handler->prepare ($query1); $statement_handler->execute; $max_lon = $statement_handler -> fetchrow() ; $diff_lat = $max_lat - $min_lat; $diff_lon = $max_lon - $min_lon; $lat_scale = 800 / $diff_lat; $lon_scale = 1200 / $diff_lon; binmode STDOUT; print $query->header("image/png"); my $im = new GD::Image(1200,800); my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0, 0, 0); my $red = $im->colorAllocate(255, 0, 0); my $blue = $im->colorAllocate(0, 0, 255); my $green = $im->colorAllocate(50, 200, 0); my $purple = $im->colorAllocate(200, 0, 255); my $orange = $im->colorAllocate(255, 200, 0); my $grey = $im->colorAllocate(80, 80, 80); my $light_blue = $im->colorAllocate(0,255,255); my $yellow = $im->colorAllocate(255,255,128); $im->filledRectangle(0, 0, 1200, 800, $grey); $query1="select distinct code from data"; $statement_handler=$database_handler->prepare ($query1); $statement_handler->execute; while (($code) = $statement_handler -> fetchrow()) { $query2="select abs(latitude),abs(longitude),altitude from data where code = '$code' order by seq desc limit 1"; $statement_handler2=$database_handler->prepare ($query2); $statement_handler2->execute; while (($lat,$lon,$alt) = $statement_handler2 -> fetchrow()) { $x = int(($lon - $min_lon) * $lon_scale); $y = int(($lat - $min_lat) * $lat_scale); $im->filledRectangle($x-2, $y-2, $x+2, $y+2, $green); $im->string(gdSmallFont, $x+23, $y-22, "$code", $light_blue); $im->line($x+2.5,$y-2.5,$x+15,$y-15, $green); $im->string(gdSmallFont, $x+23, $y-10, "$alt ft", $yellow); } } $query1="select seq,dtg,code,callsign,altitude,abs(latitude),abs(longitude) from data order by code"; $statement_handler=$database_handler->prepare ($query1); $statement_handler->execute; while (($seq,$dtg,$code,$callsign,$alt,$lat,$lon) = $statement_handler -> fetchrow()) { $data_count++; $x = int(($lon - $min_lon) * $lon_scale); $y = int(($lat - $min_lat) * $lat_scale); $im->setPixel($x,$y,$green); } $date2=time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($date2); if ($mday < 10) { $day = "0".$mday; } else { $day = $mday; } $month = $mon + 1; if ($month < 10) { $month = "0".$month; } if ($hour < 10) { $hour = "0".$hour; } if ($min < 10) { $min = "0".$min; } if ($sec < 10) { $sec = "0".$sec; } $year+=1900; $date1 = $day."/".$month."/".$year." ".$hour.":".$min.":".$sec; $im->string(gdLargeFont, 21, 10, "ADS-B Display $date1 - Andrew Rich 2007 - $data_count points from MySQL table ", $light_blue); $im->string(gdLargeFont, 21, 25, "$min_lat $max_lat $min_lon $max_lon ", $light_blue); print $im->png; $date2=(time()-(60*10)); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($date2); if ($mday < 10) { $day = "0".$mday; } else { $day = $mday; } $month = $mon + 1; if ($month < 10) { $month = "0".$month; } if ($hour < 10) { $hour = "0".$hour; } if ($min < 10) { $min = "0".$min; } if ($sec < 10) { $sec = "0".$sec; } $year+=1900; $date1 = $year."-".$month."-".$day." ".$hour.":".$min.":".$sec; $query="delete from data where dtg < '".$date1."'"; $statement_handler=$database_handler->prepare ($query); #$statement_handler->execute; ---------------------------------------------------------------------------- Andrew Rich VK4TEC vk4tec at people.net.au http://www.tech-software.net No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.13/947 - Release Date: 11/08/2007 2:29 PM -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.tapr.org/pipermail/aprssig/attachments/20070812/2dd30f1f/attachment.htm
- Previous message: [aprssig] DR-135TP - EJ-41U TNC / T2-135
- Next message: [aprssig] APRS New Initiative and the D710
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the aprssig mailing list
