mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

mkdemotiv.pl (2438B)


      1 #!/usr/bin/env perl
      2 
      3 # Demotivator generator by Antoine Amarilli (2011)
      4 # License: public domain.
      5 
      6 if ($#ARGV != 3)
      7 {
      8   print "mkdemotiv -- automatical demotivator generation\n";
      9   print "usage: mkdemotiv input text1 text2 output\n";
     10   print "input and output are paths to image input/output files\n";
     11   print "requires imagemagick and inkscape\n";
     12   exit 1;
     13 }
     14 
     15 my ($image, $text1, $text2, $output) = @ARGV;
     16 my ($owidth, $oheight) = split('x', (split(' ', `identify $image`))[2]);
     17 
     18 my $width = 800.;
     19 my $height = 800. * (1. * $oheight / $owidth);
     20 
     21 my $w = 110 + 110 + $width;
     22 my $wrect = 10 + 10 + $width;
     23 my $hrect = 10 + 10 + $height;
     24 my $wtext = 20 + 20 + $width;
     25 my $ytext1 = 70 + $height + 10;
     26 my $ytext2 = $ytext1 + 100;
     27 my $h = $ytext2 + 60;
     28 
     29 
     30 #TODO add big first and last letter, bar underneath, multiline
     31 $svg = <<END;
     32 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
     33 
     34 <svg
     35    xmlns:svg="http://www.w3.org/2000/svg"
     36    xmlns="http://www.w3.org/2000/svg"
     37    xmlns:xlink="http://www.w3.org/1999/xlink"
     38    version="1.2"
     39    width="$w"
     40    height="$h"
     41    id="svg2">
     42   <g id="layer">
     43     <rect
     44        width="$w"
     45        height="$h"
     46        ry="0"
     47        x="0"
     48        y="0"
     49        id="background"
     50        style="fill:#000000" />
     51     <rect
     52        width="$wrect"
     53        height="$hrect"
     54        x="100"
     55        y="60"
     56        id="white"
     57        style="fill:#ffffff" />
     58     <image
     59        xlink:href="$image"
     60        id="image"
     61        width="$width"
     62        height="$height"
     63        y="70"
     64        x="110" />
     65     <flowRoot id="root1" xml:space="preserve" style="font-family:FreeSerif; text-align:center">
     66       <flowRegion id="region1">
     67         <rect
     68            width="$wtext"
     69            height="240"
     70            x="70"
     71            y="$ytext1"
     72            id="rect1" />
     73       </flowRegion>
     74       <flowPara id="para1" style="font-size:90px;fill:#ffffff">$text1</flowPara>
     75     </flowRoot>
     76     <flowRoot id="root2" xml:space="preserve" style="font-family:FreeSerif; text-align:center">
     77       <flowRegion id="region2">
     78         <rect
     79            width="$wtext"
     80            height="110"
     81            x="70"
     82            y="$ytext2"
     83            id="rect2" />
     84       </flowRegion>
     85       <flowPara id="para2" style="font-size:32px;fill:#ffffff">$text2</flowPara>
     86     </flowRoot>
     87   </g>
     88 </svg>
     89 END
     90 
     91 my $tmp1 = `mktemp`;
     92 chop $tmp1;
     93 #TODO ugly
     94 open(F, "| inkscape /dev/stdin --export-png=/dev/stdout > $tmp1.png");
     95 print F $svg;
     96 close (F);
     97 `convert $tmp1.png $output`
     98