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 |
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; |
27 |
$image->Set('size' => "${w}x${h}"); |
28 |
$image->Read('xc:#283880'); |
29 |
if ($type == TYPE_BULLET) { |
30 |
$image->Annotate('text' => $text, 'geometry' => '+17+10', |
31 |
'font' => "\@arialbd.ttf", 'pointsize' => 11, |
32 |
'fill' => '#ffffff', 'align' => 'left'); |
33 |
# $image->Annotate('text' => $text, 'geometry' => '+17+1', |
34 |
# 'font' => "\@arialbd.ttf", 'pointsize' => 11, |
35 |
# 'pen' => '#FFFFFF', 'align' => 'left'); |
36 |
# $image->Blur('radius' => 0.1); |
37 |
$image->Draw('primitive' => 'rectangle', 'stroke' => '#00D000', |
38 |
'fill' => '#00D000', 'antialias' => 1, 'points' => |
39 |
'7,4 10,7'); |
40 |
} else { |
41 |
if ($type == TYPE_LINE) { |
42 |
$image->Draw('primitive' => 'line', |
43 |
'stroke' => '#00FF00', 'fill' => '#00FF00', |
44 |
'antialias' => 1, 'points' => '1,'.($h-2).' 63,'.($h-2)); |
45 |
my ($br, $bg, $bb) = (0x00, 0xFF, 0x00); |
46 |
my ($er, $eg, $eb) = (0x28, 0x38, 0x80); |
47 |
my $range = $w - 64; |
48 |
for (my $i = 0; $i < $range; $i++) { |
49 |
my $j = $i + 64; |
50 |
my $color = sprintf("#%02X%02X%02X", |
51 |
$br + (($er - $br) / $range) * $i, |
52 |
$bg + (($eg - $bg) / $range) * $i, |
53 |
$bb + (($eb - $bb) / $range) * $i |
54 |
); |
55 |
$image->Draw('primitive' => 'point', |
56 |
'stroke' => $color, |
57 |
'fill' => $color, |
58 |
'antialias' => 1, |
59 |
'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 |
} |
67 |
print " -> " unless ($file eq "-"); |
68 |
$file .= ".gif" unless ($file eq "-"); |
69 |
$image->Write('filename' => "gif:$file", 'colors' => 256, |
70 |
'interlace' => "none", 'compress' => 'lzw'); |
71 |
print "$file\n" unless ($file eq "-"); |
72 |
return "$file"; |
73 |
} |
74 |
|
75 |
#print "Content-Type: image/gif\n\n"; |
76 |
#dump_gif("NOVOSTI", TYPE_LINE, "-"); |
77 |
#exit $?; |
78 |
|
79 |
my $dbh = DBI->connect("DBI:Pg:dbname=plivasi", "", "") || |
80 |
die $DBI::errstr; |
81 |
my $sth = $dbh->prepare("SELECT section,item,url,level,num FROM menu") || |
82 |
die $dbh->errstr(); |
83 |
$sth->execute() || die $sth->errstr(); |
84 |
while (my @arr = $sth->fetchrow_array()) { |
85 |
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; |
89 |
$dbh->disconnect; |
90 |
exit $?; |
91 |
|