/[pliva-si]/m/menu.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /m/menu.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by ravilov, Thu Jun 28 10:55:30 2001 UTC revision 1.5 by dpavlin, Fri Jun 29 11:12:59 2001 UTC
# Line 4  use strict; Line 4  use strict;
4  use DBI;  use DBI;
5  use Image::Magick;  use Image::Magick;
6    
7  use constant TYPE_NONE => scalar 0;  use constant TYPE_NONE => scalar 2;
8  use constant TYPE_BULLET => scalar 1;  use constant TYPE_BULLET => scalar 3;
9  use constant TYPE_LINE => scalar 2;  use constant TYPE_LINE => scalar 1;
10    
11    # size of menu image
12    my $w=125;
13    my $h_base=13;
14    my $h;
15    
16  sub dump_gif {  sub dump_gif {
17          my ($text, $type, $file) = @_;          my ($text, $type, $file) = @_;
18          $type ||= TYPE_NONE;          $type ||= TYPE_NONE;
19          $file ||= $text;          $file ||= $text;
20          $file =~ s/[^a-zA-Z0-9\-]/_/g;          $file =~ s/[^a-zA-Z0-9\-]/_/g;
21            $file = lc($file);
22          print "$text" unless ($file eq "-");          print "$text" unless ($file eq "-");
23            my $tmp=$text;
24            my $nl=1;
25            $tmp =~ s/\\n/$nl++/gie;
26            $h=$h_base*$nl;
27          my $image = Image::Magick->new;          my $image = Image::Magick->new;
28          $image->Set('size' => '125x13');          $image->Set('size' => "${w}x${h}");
29          $image->Read('xc:#283880');          $image->Read('xc:#283880');
30          if ($type == TYPE_BULLET) {          if ($type == TYPE_BULLET) {
31                  $image->Annotate('text' => $text, 'geometry' => '+17+1',                  $image->Annotate('text' => $text, 'geometry' => '+17+10',
32                          'font' => "\@arialbd.ttf", 'pointsize' => 11,                          'font' => "\@arialbd.ttf", 'pointsize' => 11,
33                          'pen' => '#FFFFFF', 'align' => 'left');                          'fill' => '#ffffff', 'align' => 'left');
34                  $image->Blur('radius' => 1);  #               $image->Annotate('text' => $text, 'geometry' => '+17+1',
35    #                       'font' => "\@arialbd.ttf", 'pointsize' => 11,
36    #                       'pen' => '#FFFFFF', 'align' => 'left');
37    #               $image->Blur('radius' => 0.1);
38                  $image->Draw('primitive' => 'rectangle', 'stroke' => '#00D000',                  $image->Draw('primitive' => 'rectangle', 'stroke' => '#00D000',
39                          'fill' => '#00D000', 'antialias' => 1, 'points' =>                          'fill' => '#00D000', 'antialias' => 1, 'points' =>
40                          '7,4 10,7');                          '7,4 10,7');
41          } else {          } else {
                 $image->Annotate('text' => $text, 'geometry' => '+3+0',  
                         'font' => "\@arialbd.ttf", 'pointsize' => 11,  
                         'pen' => '#FFFFFF', 'align' => 'left');  
                 $image->Blur('radius' => 1);  
42                  if ($type == TYPE_LINE) {                  if ($type == TYPE_LINE) {
43                          $image->Draw('primitive' => 'line',                          $image->Draw('primitive' => 'line',
44                                  'stroke' => '#00FF00', 'fill' => '#00FF00',                                  'stroke' => '#00FF00', 'fill' => '#00FF00',
45                                  'antialias' => 1, 'points' => '1,11 63,11');                                  'antialias' => 1, 'points' => '1,'.($h-2).' 63,'.($h-2));
46                          my ($br, $bg, $bb) = (0x00, 0xFF, 0x00);                          my ($br, $bg, $bb) = (0x00, 0xFF, 0x00);
47                          my ($er, $eg, $eb) = (0x28, 0x38, 0x80);                          my ($er, $eg, $eb) = (0x28, 0x38, 0x80);
48                          my $range = 125 - 64;                          my $range = $w - 64;
49                          for (my $i = 0; $i < $range; $i++) {                          for (my $i = 0; $i < $range; $i++) {
50                                  my $j = $i + 64;                                  my $j = $i + 64;
51                                  my $color = sprintf("#%02X%02X%02X",                                  my $color = sprintf("#%02X%02X%02X",
# Line 46  sub dump_gif { Line 55  sub dump_gif {
55                                  );                                  );
56                                  $image->Draw('primitive' => 'point',                                  $image->Draw('primitive' => 'point',
57                                          'stroke' => $color,                                          'stroke' => $color,
58                                            'fill' => $color,
59                                          'antialias' => 1,                                          'antialias' => 1,
60                                          'points' => "$j,11");                                          'points' => "$j,".($h-2));
61                          }                          }
62                  }                  }
63                    $image->Annotate('text' => $text, 'geometry' => '+3+10',
64                            'font' => "\@arialbd.ttf", 'pointsize' => 11,
65                            'fill' => '#FFFFFF', 'align' => 'left');
66    #               $image->Blur('radius' => 1);
67          }          }
         # $image->Resize('geometry' => '125x15',  
         #       'filter' => 'Lanczos', 'blur' => '1.8');  
         #$image->Scale('geometry' => '50%');  
         # $image->Draw('stroke' => '#CCCCCC', 'primitive' => 'line',  
         #       'points' => '0,14 118,14', 'linewidth' => 1);  
         # $image->Draw('stroke' => '#cccccc', 'primitive' => 'line',  
         #       'points' => '118,14 118,7', 'linewidth' => 2);  
68          print " -> " unless ($file eq "-");          print " -> " unless ($file eq "-");
69          $file .= ".gif" unless ($file eq "-");          $file .= ".gif" unless ($file eq "-");
70          $image->Write('filename' => "gif:$file", 'colors' => 256,          $image->Write('filename' => "gif:$file", 'colors' => 256,
# Line 66  sub dump_gif { Line 73  sub dump_gif {
73          return "$file";          return "$file";
74  }  }
75    
76  print "Content-Type: image/gif\n\n";  #print "Content-Type: image/gif\n\n";
77  dump_gif("NOVOSTI", TYPE_LINE, "-");  #dump_gif("NOVOSTI", TYPE_LINE, "-");
78  exit $?;  #exit $?;
79    
80  my $dbh = DBI->connect("DBI:Pg:dbname=corp", "", "") ||  my $dbh = DBI->connect("DBI:Pg:dbname=plivasi", "", "") ||
81          die $DBI::errstr;          die $DBI::errstr;
82  my $sth = $dbh->prepare("SELECT section,item,url FROM menu") ||  my $sth = $dbh->prepare("SELECT section,item,url,level,num FROM menu") ||
83          die $dbh->errstr();          die $dbh->errstr();
84  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
85  while (my @arr = $sth->fetchrow_array()) {  while (my @arr = $sth->fetchrow_array()) {
86          if (0) {          my $sql="UPDATE menu SET file='".dump_gif($arr[1], $arr[3])."',w=$w,h=$h WHERE num=$arr[4]";
87                  dump_gif($arr[1], TYPE_BULLET);          $dbh->do($sql);
         } else {  
                 $dbh->do("UPDATE menu SET file='".dump_gif($arr[1], TYPE_BULLET).  
                         "' WHERE item='$arr[1]'");  
         }  
88  }  }
89  $sth->finish;  $sth->finish;
90  $dbh->disconnect;  $dbh->disconnect;
91  exit $?;  exit $?;
92    

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.26