Imported Upstream version 1.4.1
[routino] / web / www / routino / icons / create-icons.pl
1 #!/usr/bin/perl
2 #
3 # Routino icons Perl script
4 #
5 # Part of the Routino routing software.
6 #
7 # This file Copyright 2008-2010 Andrew M. Bishop
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU Affero General Public License for more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 use Graphics::Magick;
24
25 # Markers for routing
26
27 @names=("red","grey");
28 @borders=("black","grey");
29 @letters=("red","grey");
30
31 foreach $character ('0'..'9','home')
32   {
33    foreach $colour (0..$#names)
34      {
35       $image=Graphics::Magick->new;
36       $image->Set(size => "63x75");
37
38       $image->ReadImage('xc:white');
39       $image->Transparent('white');
40
41       $image->Draw(primitive => polygon, points => '1,32 32,73 61,32 32,10',
42                    stroke => $borders[$colour], fill => 'white', strokewidth => 6,
43                    antialias => 'false');
44
45       $image->Draw(primitive => arc,     points => '1,1 61,61 -180,0',
46                    stroke => $borders[$colour], fill => 'white', strokewidth => 6,
47                    antialias => 'false');
48
49       if($character eq 'home')
50         {
51          $home=Graphics::Magick->new;
52
53          $home->ReadImage("home.png");
54
55          $home->Opaque(fill => $names[$colour], color => 'black');
56
57          $image->Composite(image => $home, compose => Over,
58                            x => 32-$home->Get('width')/2, y => 26-$home->Get('height')/2);
59         }
60       else
61         {
62          ($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) = 
63            $image->QueryFontMetrics(text => $character, font => 'Helvetica', pointsize => '36');
64
65          $image->Annotate(text => $character, font => 'Helvetica', pointsize => '36',
66                           stroke => $letters[$colour], fill => $letters[$colour],
67                           x => 32, y => 32-$descender, align => Center,
68                           antialias => 'false');
69         }
70
71       $image->Resize(width => 21, height => 25);
72
73       $image->Write("marker-$character-$names[$colour].png");
74
75       undef $image;
76      }
77   }
78
79 # Balls for visualiser descriptions
80
81 @colours=("#FFFFFF",
82           "#FF0000",
83           "#FFFF00",
84           "#00FF00",
85           "#8B4513",
86           "#00BFFF",
87           "#FF69B4",
88           "#000000",
89           "#000000",
90           "#000000");
91
92 foreach $colour (0..9)
93   {
94    $image=Graphics::Magick->new;
95    $image->Set(size => "9x9");
96
97    $image->ReadImage('xc:white');
98    $image->Transparent('white');
99
100    $image->Draw(primitive => circle, points => '4,4 4,8',
101                 fill => $colours[$colour], stroke => $colours[$colour],
102                 antialias => 'false');
103
104    $image->Write("ball-$colour.png");
105
106    undef $image;
107   }
108
109 # Limit signs
110
111 foreach $limit (1..160)
112   {
113    &draw_limit($limit);
114   }
115
116 foreach $limit (10..200)
117   {
118    &draw_limit(sprintf "%.1f",$limit/10);
119   }
120
121 &draw_limit("no");
122
123 unlink "limit-0.png";
124 link "limit-no.png","limit-0.png";
125
126 unlink "limit-0.0.png";
127 link "limit-no.png","limit-0.0.png";
128
129 sub draw_limit
130   {
131    ($limit)=@_;
132
133    $image=Graphics::Magick->new;
134    $image->Set(size => "57x57");
135
136    $image->ReadImage('xc:white');
137    $image->Transparent('white');
138
139    $image->Draw(primitive => circle, points => '28,28 28,55',
140                 stroke => 'red', fill => 'white', strokewidth => 3,
141                 antialias => 'false');
142
143    ($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) =
144      $image->QueryFontMetrics(text => "$limit", font => 'Helvetica', pointsize => '22');
145
146    $image->Annotate(text => "$limit", font => 'Helvetica', pointsize => '22',
147                     stroke => 'black', fill => 'black',
148                     x => 28, y => 28-$descender, align => Center,
149                     antialias => 'false');
150
151    $image->Resize(width => 19, height => 19);
152
153    $image->Write("limit-$limit.png");
154
155    undef $image;
156   }