aboutsummaryrefslogtreecommitdiff
path: root/mkdemotiv.pl
blob: 67aea69437cb6110b4fb7a4bcd394bdabb46a414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env perl

# Demotivator generator by Antoine Amarilli (2011)
# License: public domain.

if ($#ARGV != 3)
{
  print "mkdemotiv -- automatical demotivator generation\n";
  print "usage: mkdemotiv input text1 text2 output\n";
  print "input and output are paths to image input/output files\n";
  print "requires imagemagick and inkscape\n";
  exit 1;
}

my ($image, $text1, $text2, $output) = @ARGV;
my ($owidth, $oheight) = split('x', (split(' ', `identify $image`))[2]);

my $width = 800.;
my $height = 800. * (1. * $oheight / $owidth);

my $w = 110 + 110 + $width;
my $wrect = 10 + 10 + $width;
my $hrect = 10 + 10 + $height;
my $wtext = 20 + 20 + $width;
my $ytext1 = 70 + $height + 10;
my $ytext2 = $ytext1 + 100;
my $h = $ytext2 + 60;


#TODO add big first and last letter, bar underneath, multiline
$svg = <<END;
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<svg
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   version="1.2"
   width="$w"
   height="$h"
   id="svg2">
  <g id="layer">
    <rect
       width="$w"
       height="$h"
       ry="0"
       x="0"
       y="0"
       id="background"
       style="fill:#000000" />
    <rect
       width="$wrect"
       height="$hrect"
       x="100"
       y="60"
       id="white"
       style="fill:#ffffff" />
    <image
       xlink:href="$image"
       id="image"
       width="$width"
       height="$height"
       y="70"
       x="110" />
    <flowRoot id="root1" xml:space="preserve" style="font-family:FreeSerif; text-align:center">
      <flowRegion id="region1">
        <rect
           width="$wtext"
           height="240"
           x="70"
           y="$ytext1"
           id="rect1" />
      </flowRegion>
      <flowPara id="para1" style="font-size:90px;fill:#ffffff">$text1</flowPara>
    </flowRoot>
    <flowRoot id="root2" xml:space="preserve" style="font-family:FreeSerif; text-align:center">
      <flowRegion id="region2">
        <rect
           width="$wtext"
           height="110"
           x="70"
           y="$ytext2"
           id="rect2" />
      </flowRegion>
      <flowPara id="para2" style="font-size:32px;fill:#ffffff">$text2</flowPara>
    </flowRoot>
  </g>
</svg>
END

my $tmp1 = `mktemp`;
chop $tmp1;
#TODO ugly
open(F, "| inkscape /dev/stdin --export-png=/dev/stdout > $tmp1.png");
print F $svg;
close (F);
`convert $tmp1.png $output`