13 GD::Image->trueColor(1);
15 my $img = GD::Image->new('snmp-bg.png');
16 #my $img = GD::Image->new(100,100);
19 my $dbh = nms::db_connect();
21 my $sgetpoll = $dbh->prepare('select switch,(select temp from temppoll where switches.switch=temppoll.switch AND temp != 0 order by id desc limit 1) AS temp,placement from switches natural join placements');
23 my $black = $img->colorAllocate(0,0,0);
24 my $white = $img->colorAllocate(255,255,255);
25 my $green = $img->colorAllocate(0,255,0);
26 my $blue = $img->colorAllocate(0,0,255);
33 my $color = &getcolor($avrgtemp);
35 open (OUT, "> /tmp/outtemps");
36 for (my $i = 0; $i < $steps; $i++) {
37 my $diff = $maxtemp - $mintemp;
38 my $temp = $mintemp + ($maxtemp - $mintemp) * ((($diff / $steps) * $i)/$diff);
39 $img->line(5, $i, 45, $i, &getcolor2($temp));
43 $img->string(gdMediumBoldFont, 50, 0, "Freezing!", $black);
44 $img->string(gdMediumBoldFont, 50, $steps - 11, "Too hot!", $black);
45 $img->string(gdMediumBoldFont, 50, 12, "$mintemp C", $black);
46 $img->string(gdMediumBoldFont, 50, $steps - 22, "$maxtemp C", $black);
48 #$img->string(gdMediumBoldFont, 600, 200, "Freezing!$mintemp", $black);
49 #$img->string(gdMediumBoldFont, 600, 210, "$mintemp C", $black);
50 #$img->string(gdMediumBoldFont, 600, 220 + $maxtemp, "Too hot! $maxtemp", $black);
51 #$img->string(gdMediumBoldFont, 600, 210 + $maxtemp, "$maxtemp C", $black);
55 while (my $ref = $sgetpoll->fetchrow_hashref()) {
56 next if (!defined($ref->{'temp'}));
58 $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
59 $avrgtemp = $ref->{'temp'};
62 my $roundtemp = sprintf ("%.0f", $avrgtemp);
63 $color = getcolor($avrgtemp);
64 $img->filledRectangle($px - 0, $py - 17, $px + 12, $py + 5, $white);
65 $img->stringUp(gdGiantFont,$px - 1,$py - 1,"$roundtemp",$blue);
66 $img->rectangle($px, $py, $px + 10,$py + 10,$black);
67 $img->filledRectangle($px + 1, $py + 1, $px + 9, $py + 9,$color);
70 print $cgi->header(-type=>'image/png');
76 my $t = ($temp - $mintemp) / ($maxtemp - $mintemp);
80 my $colorred = 255 * $t;
81 my $colorblue = 255 - $colorred;
83 return $img->colorResolve($colorred, 0, $colorblue);
89 my $t = ($temp - $mintemp) / ($maxtemp - $mintemp);
93 my $colorred = 255 * $t;
94 my $colorblue = 255 - $colorred;
96 return $img->colorResolve($colorred, 0, $colorblue);