]> git.sesse.net Git - nms/blob - web/stempmap-ptn.pl
Merge.
[nms] / web / stempmap-ptn.pl
1 #!/usr/bin/perl
2 use lib '../include';
3 use nms;
4 #
5 #
6
7 use CGI;
8 use GD;
9 use DBI;
10 use strict;
11 use warnings;
12
13 my $img = GD::Image->new('stemp-bg5.png');
14 my $cgi = CGI->new;
15
16 my $dbh = nms::db_connect();
17
18 my $black = $img->colorAllocate(0,0,0);
19 my $white = $img->colorAllocate(255,255,255);
20 my $green = $img->colorAllocate(0,255,0);
21 my $blue = $img->colorAllocate(0,0,255);
22
23 my $avrgtemp = 54;
24 my $mintemp = 10.0;
25 my $maxtemp = 80.0;
26
27 my $color = &getcolor($avrgtemp);
28
29 for (my $i = $mintemp; $i <= $maxtemp; $i++) {
30         $img->line(600, 220 + $i - $mintemp, 645, 220 + $i - $mintemp, &getcolor($i));
31 }
32
33 $img->string(gdMediumBoldFont, 600, 200, "Freezing!$mintemp", $black);
34 $img->string(gdMediumBoldFont, 600, 210, "$mintemp C", $black);
35 $img->string(gdMediumBoldFont, 600, 220 + $maxtemp, "Too hot! $maxtemp", $black);
36 $img->string(gdMediumBoldFont, 600, 210 + $maxtemp, "$maxtemp C", $black);
37
38 my $px = 5;
39 my $py = 30;
40
41 #$img->stringUp(gdGiantFont,$px,$py - 2,"$avrgtemp",$white);
42 $img->filledRectangle($px - 0, $py - 17, $px + 12, $py + 5, $white);
43 $img->stringUp(gdLargeFont,$px - 4,$py - 1,"$avrgtemp",$blue);
44 $img->rectangle($px, $py, $px + 7,$py + 7,$black);
45 $img->filledRectangle($px + 1, $py + 1, $px + 6, $py + 6,$color);
46
47 print $cgi->header(-type=>'image/png');
48 print $img->png;
49
50 sub getcolor {
51         my ($temp) = @_;
52
53         my $percent = ($temp - $mintemp) / ($maxtemp - $mintemp);
54         my $colorred = 255 * $percent;
55         my $colorblue = 255 - $colorred;
56
57         return $img->colorAllocate($colorred, $colorblue, 0);
58 }