8 |
use constant TYPE_BULLET => scalar 3; |
use constant TYPE_BULLET => scalar 3; |
9 |
use constant TYPE_LINE => scalar 1; |
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 |
print "$text" unless ($file eq "-"); |
print "$text" unless ($file eq "-"); |
22 |
|
my $tmp=$text; |
23 |
|
my $nl=1; |
24 |
|
$tmp =~ s/\\n/$nl++/gie; |
25 |
|
$h=$h_base*$nl; |
26 |
my $image = Image::Magick->new; |
my $image = Image::Magick->new; |
27 |
$image->Set('size' => '125x13'); |
$image->Set('size' => "${w}x${h}"); |
28 |
$image->Read('xc:#283880'); |
$image->Read('xc:#283880'); |
29 |
if ($type == TYPE_BULLET) { |
if ($type == TYPE_BULLET) { |
30 |
$image->Annotate('text' => $text, 'geometry' => '+17+10', |
$image->Annotate('text' => $text, 'geometry' => '+17+10', |
38 |
'fill' => '#00D000', 'antialias' => 1, 'points' => |
'fill' => '#00D000', 'antialias' => 1, 'points' => |
39 |
'7,4 10,7'); |
'7,4 10,7'); |
40 |
} else { |
} else { |
|
$image->Annotate('text' => $text, 'geometry' => '+3+10', |
|
|
'font' => "\@arialbd.ttf", 'pointsize' => 11, |
|
|
'fill' => '#FFFFFF', 'align' => 'left'); |
|
|
# $image->Blur('radius' => 1); |
|
41 |
if ($type == TYPE_LINE) { |
if ($type == TYPE_LINE) { |
42 |
$image->Draw('primitive' => 'line', |
$image->Draw('primitive' => 'line', |
43 |
'stroke' => '#00FF00', 'fill' => '#00FF00', |
'stroke' => '#00FF00', 'fill' => '#00FF00', |
44 |
'antialias' => 1, 'points' => '1,11 63,11'); |
'antialias' => 1, 'points' => '1,'.($h-2).' 63,'.($h-2)); |
45 |
my ($br, $bg, $bb) = (0x00, 0xFF, 0x00); |
my ($br, $bg, $bb) = (0x00, 0xFF, 0x00); |
46 |
my ($er, $eg, $eb) = (0x28, 0x38, 0x80); |
my ($er, $eg, $eb) = (0x28, 0x38, 0x80); |
47 |
my $range = 125 - 64; |
my $range = $w - 64; |
48 |
for (my $i = 0; $i < $range; $i++) { |
for (my $i = 0; $i < $range; $i++) { |
49 |
my $j = $i + 64; |
my $j = $i + 64; |
50 |
my $color = sprintf("#%02X%02X%02X", |
my $color = sprintf("#%02X%02X%02X", |
56 |
'stroke' => $color, |
'stroke' => $color, |
57 |
'fill' => $color, |
'fill' => $color, |
58 |
'antialias' => 1, |
'antialias' => 1, |
59 |
'points' => "$j,11"); |
'points' => "$j,".($h-2)); |
60 |
} |
} |
61 |
} |
} |
62 |
|
$image->Annotate('text' => $text, 'geometry' => '+3+10', |
63 |
|
'font' => "\@arialbd.ttf", 'pointsize' => 11, |
64 |
|
'fill' => '#FFFFFF', 'align' => 'left'); |
65 |
|
# $image->Blur('radius' => 1); |
66 |
} |
} |
|
# $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); |
|
67 |
print " -> " unless ($file eq "-"); |
print " -> " unless ($file eq "-"); |
68 |
$file .= ".gif" unless ($file eq "-"); |
$file .= ".gif" unless ($file eq "-"); |
69 |
$image->Write('filename' => "gif:$file", 'colors' => 256, |
$image->Write('filename' => "gif:$file", 'colors' => 256, |
78 |
|
|
79 |
my $dbh = DBI->connect("DBI:Pg:dbname=plivasi", "", "") || |
my $dbh = DBI->connect("DBI:Pg:dbname=plivasi", "", "") || |
80 |
die $DBI::errstr; |
die $DBI::errstr; |
81 |
my $sth = $dbh->prepare("SELECT section,item,url,level FROM menu") || |
my $sth = $dbh->prepare("SELECT section,item,url,level,num FROM menu") || |
82 |
die $dbh->errstr(); |
die $dbh->errstr(); |
83 |
$sth->execute() || die $sth->errstr(); |
$sth->execute() || die $sth->errstr(); |
84 |
while (my @arr = $sth->fetchrow_array()) { |
while (my @arr = $sth->fetchrow_array()) { |
85 |
$dbh->do("UPDATE menu SET file='".dump_gif($arr[1], $arr[3])."' WHERE item='$arr[1]'"); |
my $sql="UPDATE menu SET file='".dump_gif($arr[1], $arr[3])."',w=$w,h=$h WHERE num=$arr[4]"; |
86 |
|
$dbh->do($sql); |
87 |
} |
} |
88 |
$sth->finish; |
$sth->finish; |
89 |
$dbh->disconnect; |
$dbh->disconnect; |
90 |
exit $?; |
exit $?; |
91 |
|
|