/[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

Contents of /m/menu.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Fri Jun 29 11:12:59 2001 UTC (22 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +1 -0 lines
File MIME type: text/plain
lc filenames

1 #! /usr/local/bin/perl -w
2
3 use strict;
4 use DBI;
5 use Image::Magick;
6
7 use constant TYPE_NONE => scalar 2;
8 use constant TYPE_BULLET => scalar 3;
9 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 {
17 my ($text, $type, $file) = @_;
18 $type ||= TYPE_NONE;
19 $file ||= $text;
20 $file =~ s/[^a-zA-Z0-9\-]/_/g;
21 $file = lc($file);
22 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;
28 $image->Set('size' => "${w}x${h}");
29 $image->Read('xc:#283880');
30 if ($type == TYPE_BULLET) {
31 $image->Annotate('text' => $text, 'geometry' => '+17+10',
32 'font' => "\@arialbd.ttf", 'pointsize' => 11,
33 'fill' => '#ffffff', 'align' => 'left');
34 # $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',
39 'fill' => '#00D000', 'antialias' => 1, 'points' =>
40 '7,4 10,7');
41 } else {
42 if ($type == TYPE_LINE) {
43 $image->Draw('primitive' => 'line',
44 'stroke' => '#00FF00', 'fill' => '#00FF00',
45 'antialias' => 1, 'points' => '1,'.($h-2).' 63,'.($h-2));
46 my ($br, $bg, $bb) = (0x00, 0xFF, 0x00);
47 my ($er, $eg, $eb) = (0x28, 0x38, 0x80);
48 my $range = $w - 64;
49 for (my $i = 0; $i < $range; $i++) {
50 my $j = $i + 64;
51 my $color = sprintf("#%02X%02X%02X",
52 $br + (($er - $br) / $range) * $i,
53 $bg + (($eg - $bg) / $range) * $i,
54 $bb + (($eb - $bb) / $range) * $i
55 );
56 $image->Draw('primitive' => 'point',
57 'stroke' => $color,
58 'fill' => $color,
59 'antialias' => 1,
60 '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 }
68 print " -> " unless ($file eq "-");
69 $file .= ".gif" unless ($file eq "-");
70 $image->Write('filename' => "gif:$file", 'colors' => 256,
71 'interlace' => "none", 'compress' => 'lzw');
72 print "$file\n" unless ($file eq "-");
73 return "$file";
74 }
75
76 #print "Content-Type: image/gif\n\n";
77 #dump_gif("NOVOSTI", TYPE_LINE, "-");
78 #exit $?;
79
80 my $dbh = DBI->connect("DBI:Pg:dbname=plivasi", "", "") ||
81 die $DBI::errstr;
82 my $sth = $dbh->prepare("SELECT section,item,url,level,num FROM menu") ||
83 die $dbh->errstr();
84 $sth->execute() || die $sth->errstr();
85 while (my @arr = $sth->fetchrow_array()) {
86 my $sql="UPDATE menu SET file='".dump_gif($arr[1], $arr[3])."',w=$w,h=$h WHERE num=$arr[4]";
87 $dbh->do($sql);
88 }
89 $sth->finish;
90 $dbh->disconnect;
91 exit $?;
92

  ViewVC Help
Powered by ViewVC 1.1.26