source: trunk/image-generation/cgi-bin/make-classifier-images.cgi@ 13536

Last change on this file since 13536 was 13536, checked in by mdewsnip, 17 years ago

Initial revision

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1#!/usr/bin/perl -w
2
3use CGI qw(:standard);
4
5my $image_generation_code_directory = "/research/mdewsnip/greenstone/image-generation";
6my $images_directory = "/home/mdewsnip/public_html/greenstone/temp-images";
7my $images_directory_url = "http://www.cs.waikato.ac.nz/~mdewsnip/greenstone/temp-images";
8
9print "Content-Type: text/html; charset=utf-8\n\n";
10print start_html("Greenstone classifier image generation");
11print "<h2>Greenstone classifier image generation</h2>";
12print hr();
13
14# Language code and macrofile name
15my $language = param("l") || "en.english";
16
17# Macro name (ASCII characters only)
18my $macro_name = param("macro");
19$macro_name =~ tr/a-zA-Z0-9//cd;
20
21# Image filename (ASCII characters only)
22my $image_name = param("image");
23$image_name =~ tr/a-zA-Z0-9//cd;
24
25my $text_unicode = param("text");
26if (defined $macro_name && $macro_name ne "" && defined $image_name && $image_name ne "" && defined $text_unicode && $text_unicode ne "") {
27 my $language_code = (split(/\./, $language))[0];
28 my $macrofile_name = (split(/\./, $language))[1];
29
30 my $language_modifier = "";
31 my $language_modifier_one = "";
32 my $image_directory = "";
33 my $translate_this = "";
34 unless ($language_code eq "en") {
35 $language_modifier = "[l=$language_code]";
36 $language_modifier_one = "l=$language_code,";
37 $image_directory = "$language_code/";
38 $translate_this = "# <b>Translate this!</b>";
39 }
40
41 # Write a temporary macrofile containing the text for the images
42 $text_unicode_raw = $text_unicode; # May contain "\n" to split the green_title text
43 $text_unicode =~ s/\\n/ /g; # Replace any "\n" with " " for standard use
44 open(MACROFILE, ">$image_generation_code_directory/web-images.dm") || (print "Error: Could not open web-images.dm for writing.", end_html() && die);
45 print MACROFILE "\#\# \"" . $text_unicode . "\" \#\# nav_bar_button \#\# t$image_name \#\#\n\n";
46 print MACROFILE "\#\# \"" . $text_unicode_raw . "\" \#\# green_title \#\# h_$image_name \#\#\n\n";
47 close(MACROFILE);
48
49 # Use ImageMagick via image generation scripts to make the images
50 `cd ..; source setup.bash; cd $image_generation_code_directory; make-images.pl -language_symbol $language_code -image_dir $images_directory web-images.dm; rm web-images.*`;
51
52 # Get width of nav_bar_buttons
53 my $nav_bar_button_width = 87;
54 my $nav_bar_button_identification = `identify $images_directory/t${image_name}on.gif 2>&1`;
55 if ($nav_bar_button_identification =~ /t${image_name}on.gif \w+ (\d+)x(\d+)/) {
56 $nav_bar_button_width = $1;
57 }
58
59 # Get width of green_titles
60 my $green_title_width = 200;
61 my $green_title_identification = `identify $images_directory/h_$image_name.gif 2>&1`;
62 if ($green_title_identification =~ /h_$image_name.gif \w+ (\d+)x(\d+)/) {
63 $green_title_width = $1;
64 }
65
66 # Output result HTML
67 print "<p>Greenstone classifier images with text \"" . $text_unicode_raw . "\":";
68 print "<p><a href=\"$images_directory_url/t${image_name}on.gif\"><img src=\"$images_directory_url/t${image_name}on.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
69 print "<p><a href=\"$images_directory_url/t${image_name}of.gif\"><img src=\"$images_directory_url/t${image_name}of.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
70 print "<p><a href=\"$images_directory_url/t${image_name}gr.gif\"><img src=\"$images_directory_url/t${image_name}gr.gif\" border=\"0\" width=\"$nav_bar_button_width\" height=\"17\"></a>";
71 print "<p><a href=\"$images_directory_url/h_$image_name.gif\" style=\"color: #000000\"><img src=\"$images_directory_url/h_$image_name.gif\" border=\"1\" width=\"$green_title_width\" height=\"57\"></a>";
72 print "<p>\n";
73 print "These images should be put in the images/$image_directory folder of your Greenstone installation.\n";
74 print "<p>\n";
75 print "To get Greenstone to use the new images, some macros must be defined. Copy all the following text and paste it into the extra.dm file in Greenstone's \"macros\" directory:\n";
76 print "<p>\n";
77 print "<tt>\n";
78
79 # base.dm macros
80 print "# <i>The following macros usually live in base.dm</i>\n";
81 print "<br>package Global\n";
82 print "<br>\n";
83 print "<br>_" . $macro_name . "width_ $language_modifier {_widtht" . $image_name . "x_ }\n";
84 print "<br>_image" . $macro_name . "_ $language_modifier {_gsimage_(_httpbrowse" . $macro_name . "_,_httpicont" . $image_name . "of_,_httpicont" . $image_name . "on_,$text_unicode,_textimage" . $macro_name . "_)}\n";
85 print "<br>_icontab" . $macro_name . "green_ $language_modifier {&lt;img src=\"_httpicont" . $image_name . "gr_\" width=_widtht" . $image_name . "x_ border=0&gt;}\n";
86 print "<br>_icontab" . $macro_name . "green_ [$language_modifier_one" . "v=1] {_texticontab" . $macro_name . "green_ }\n";
87 print "<p>\n";
88
89 # document.dm macros
90 print "# <i>The following macros usually live in document.dm</i>\n";
91 print "<br>package document\n";
92 print "<br>\n";
93 print "<br>_text" . $macro_name . "page_ $language_modifier {_texticonh" . $image_name . "_}\n";
94 print "<br>_icon" . $macro_name . "page_ $language_modifier {&lt;img src=\"_httpiconh" . $image_name . "_\" width=\"_widthh" . $image_name . "_\" height=\"_heighth" . $image_name . "_\"&gt;}\n";
95 print "<br>_icon" . $macro_name . "page_ [$language_modifier_one" . "v=1] {&lt;h2&gt;_texticonh" . $image_name . "_&lt;/h2&gt;}\n";
96 print "<p>\n";
97
98 # <language>.dm macros
99 print "# <i>The following macros usually live in $macrofile_name.dm</i>\n";
100 print "<br>package Global\n";
101 print "<br>\n";
102 print "<br>_textimage" . $macro_name . "_ $language_modifier {Browse by " . $text_unicode . "} $translate_this\n";
103 print "<br>_texticontab" . $macro_name . "green_ $language_modifier {\u$text_unicode}\n";
104 print "<br>\n";
105 print "<br>## \"$text_unicode\" ## nav_bar_button ## t" . $image_name . " ##\n";
106 print "<br>_httpicont" . $image_name . "gr_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "gr.gif}\n";
107 print "<br>_httpicont" . $image_name . "of_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "of.gif}\n";
108 print "<br>_httpicont" . $image_name . "on_ $language_modifier {_httpimg_/$image_directory" . "t" . $image_name . "on.gif}\n";
109 print "<br>_widtht" . $image_name . "x_ $language_modifier {$nav_bar_button_width}\n";
110
111 print "<br>\n";
112 print "<br>package document\n";
113 print "<br>\n";
114 print "<br>_texticonh" . $image_name . "_ $language_modifier {\u$text_unicode}\n";
115 print "<br>\n";
116 print "<br>## \"$text_unicode\" ## green_title ## h_" . $image_name . " ##\n";
117 print "<br>_httpiconh" . $image_name . "_ $language_modifier {_httpimg_/$image_directory" . "h_" . $image_name . ".gif}\n";
118 print "<br>_widthh" . $image_name . "_ $language_modifier {$green_title_width}\n";
119 print "<br>_heighth" . $image_name . "_ $language_modifier {57}\n";
120
121 print "<br>\n";
122 print "<br>package help\n";
123 print "<br>\n";
124 print "<br>_text" . $macro_name . "short_ $language_modifier {access publications by $text_unicode} $translate_this\n";
125 print "<br>_text" . $macro_name . "long_ $language_modifier {&lt;p&gt;You can &lt;i&gt;access publications by $text_unicode&lt;/i&gt; by pressing the &lt;i&gt;" . $text_unicode . "&lt;/i&gt; button. This brings up a list of " . $text_unicode . ". } $translate_this\n";
126 print "<br>\n";
127
128 print "</tt>\n";
129}
130else {
131 print "<p>Error: parameter not defined.";
132}
133
134print end_html();
Note: See TracBrowser for help on using the repository browser.