11 my %sizes; # meme base image sizes
12 my %acros; # meme base acronyms (BLB => bad-luck-brian.jpg)
14 my $script_path = $ENV{'SCRIPT_FILENAME'} ? dirname($ENV{'SCRIPT_FILENAME'}) : dirname($0);
16 my $sz_fname = $script_path . '/meme-sizes.lst';
18 open FILE, $sz_fname or die $!;
20 while (my $line = <FILE>) {
23 my ($width, $height, $fname) = split(/ /, $line, 3);
24 $sizes{$fname} = [$width, $height];
26 # Find a potential short form (acronym for multiword, no extension otherwise)
29 # remove article for the purpose of the shrotening; we don't care if it's
30 # in the middle of a word because we only care about initials anyway
31 # FIXME this actually fails in the case of XXXthe-XXX, let's care about that
32 # when we actually come across it
36 $acro = join('', map { uc(substr($_, 0, 1)) } split(/-/, $the ));
38 $acro = (split(/\./, $the))[0]
40 if (!defined $acros{$acro}) {
41 $acros{$acro} = $fname;
43 print STDERR "Trying to redefined acronym $acro from $acros{$acro} to ${fname}\n";
50 # params: img, width, height, text
52 my $svg_template=<<SVG;
53 <?xml version='1.0' encoding='UTF-8'?>
55 xmlns='http://www.w3.org/2000/svg'
56 xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1'
57 viewBox='0 0 %2\$d %3\$d'>
58 <style type="text/css">text{font-family:'Impact';fill:white;stroke:black;stroke-width:2px;text-anchor:middle}</style>
59 <image xlink:href='%1\$s' x='0' y='0'
60 width='%2\$d' height='%3\$d'/>
64 # template: y-pos, font-size, text
65 my $txt_template=<<TXT;
66 <text x='50%%' y='%1\$d%%' font-size='%2\$d'
70 while (my $q = new CGI::Fast) {
71 my $img = $q->param('m') || (keys %sizes)[0];
72 if (!defined $sizes{$img}) {
73 if (!defined $acros{$img}) {
74 print $q->header(-status=>404),
75 $q->start_html("Unknown meme base"),
76 $q->h1("Unknown meme base!");
77 print "<p>Sorry, <tt>'" . encode_entities($img) . "'</tt> is not a known meme base. ".
78 "You want one of the following instead:</p><ul>";
79 my %revacros = reverse %acros;
80 foreach (keys %sizes) {
81 print "<li><tt>" . encode_entities($_) . "</tt>";
82 print " (<tt>" . encode_entities($revacros{$_}) . "</tt>)" if defined $revacros{$_};
86 # foreach (keys %ENV) {
87 # print "<p>$_=$ENV{$_}</p>"
97 -type => 'image/svg+xml',
101 my ($width, $height) = @{$sizes{$img}};
103 my $sep = $q->param('s') || '/'; # line separator
105 my @t = $q->param('t') || ('TEST TOP//TEST BOTTOM');
110 foreach (split /\Q$sep\E/) {
115 $divisions = @lines if @lines > $divisions;
117 my $fontsize = int($height/$divisions + 0.5);
118 my $offset = int(100/$divisions + 0.5);
119 my $fillers = grep { $_ eq '' } @lines;
120 my $real_lines = @lines - $fillers;
121 my $filler_size = $fillers ? int((98 - $offset*$real_lines)/$fillers) : 0;
131 $txt .= sprintf($txt_template, $dy, $fontsize, $_);
134 printf($svg_template, $img, $width, $height, $txt);