13 my $script_path = $ENV{'SCRIPT_FILENAME'} ? dirname($ENV{'SCRIPT_FILENAME'}) : dirname($0);
15 my $sz_fname = $script_path . '/meme-sizes.lst';
17 open FILE, $sz_fname or die $!;
19 while (my $line = <FILE>) {
22 my ($width, $height, $fname) = split(/ /, $line, 3);
23 $sizes{$fname} = [$width, $height];
29 # params: img, width, height, text
31 my $svg_template=<<SVG;
32 <?xml version='1.0' encoding='UTF-8'?>
34 xmlns='http://www.w3.org/2000/svg'
35 xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1'
36 viewBox='0 0 %2\$d %3\$d'>
37 <style type="text/css">text{font-family:'Impact';fill:white;stroke:black;stroke-width:2px;text-anchor:middle}</style>
38 <image xlink:href='%1\$s' x='0' y='0'
39 width='%2\$d' height='%3\$d'/>
43 # template: y-pos, font-size, text
44 my $txt_template=<<TXT;
45 <text x='50%%' y='%1\$d%%' font-size='%2\$d'
49 while (my $q = new CGI::Fast) {
50 my $img = $q->param('m') || (keys %sizes)[0];
51 if (!defined $sizes{$img}) {
52 print $q->header(-status=>404),
53 $q->start_html("Unknown meme base"),
54 $q->h1("Unknown meme base!");
55 print "<p>Sorry, <tt>'" . encode_entities($img) . "'</tt> is not a known meme base. ".
56 "You want one of the following instead:</p><ul>";
57 foreach (keys %sizes) {
58 print "<li><tt>" . encode_entities($_) . "</tt></li>";
61 # foreach (keys %ENV) {
62 # print "<p>$_=$ENV{$_}</p>"
69 -type => 'image/svg+xml',
73 my ($width, $height) = @{$sizes{$img}};
75 my $sep = $q->param('s') || '/'; # line separator
77 my @t = $q->param('t') || ('TEST TOP//TEST BOTTOM');
82 foreach (split /\Q$sep\E/) {
87 $divisions = @lines if @lines > $divisions;
89 my $fontsize = int($height/$divisions + 0.5);
90 my $offset = int(100/$divisions + 0.5);
91 my $fillers = grep { $_ eq '' } @lines;
92 my $real_lines = @lines - $fillers;
93 my $filler_size = $fillers ? int((98 - $offset*$real_lines)/$fillers) : 0;
103 $txt .= sprintf($txt_template, $dy, $fontsize, $_);
106 printf($svg_template, $img, $width, $height, $txt);