Thread: Flashcard
View Single Post
Old 10-24-2018, 07:02 PM   #2
frostschutz
Linux User
frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.
 
frostschutz's Avatar
 
Posts: 2,282
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
Here's how I create flashcard images. (this is very specific to the data I exported from my Anki kanji deck, but the idea in general would work for other things, too)

First you write an SVG file and style it up the way you want:

Code:
<svg width="1080" height="1440">
  <style>
    .kanji { font-family: "EPSON 教科書体M";
             font-size: 900px;
    }
    .reading1 { font-family: "EPSON 教科書体M";
               font-size: 50px;
    }
    .reading2 { font-family: "EPSON 教科書体M";
               font-size: 50px;
    }
    .meaning1 { font-family: "Linux Libertine Display O";
                font-size: 50px;
                font-style: italic;
    }
    .meaning2 { font-family: "Linux Libertine Display O";
                font-size: 50px;
    }
    .graphem { font-family: "Linux Libertine Display O";
               font-size: 40px;
    }
  </style>
  <text class="kanji" x="50%" y="54%" alignment-baseline="middle" text-anchor="middle">KANJI</text>
  <text class="reading1" x="50%" y="66%" alignment-baseline="middle" text-anchor="middle">READING1</text>
  <text class="reading2" x="50%" y="71%" alignment-baseline="middle" text-anchor="middle">READING2</text>
  <text class="meaning1" x="50%" y="80%" alignment-baseline="middle" text-anchor="middle">MEANING1</text>
  <text class="meaning2" x="50%" y="85%" alignment-baseline="middle" text-anchor="middle">MEANING2</text>
  <text class="graphem" x="50%" y="95%" alignment-baseline="middle" text-anchor="middle">GRAPHEM</text>
</svg>
Then you shell script the heck out of it:

Code:
#!/bin/bash

while read line
do
    kanji=$(printf "%s" "$line" | cut -f1)
    meaning=$(printf "%s" "$line" | cut -f2)
    reading=$(printf "%s" "$line" | cut -f3)
    graphem=$(printf "%s" "$line" | cut -f4)

    reading1=${reading%'<br>'*}
    reading2=""

    if [ "$reading1" != "$reading" ]
    then
        reading2=${reading#*'<br>'}
    fi

    meaning1=${meaning%'<br>'*}

    if [ "$meaning1" != "$meaning" ]
    then
        meaning2=${meaning#*'<br>'}
    else
        meaning1=""
        meaning2=$meaning
    fi

    echo $kanji , $reading1, $reading2 , $meaning1, $meaning2 , $graphem

    # generate question cards
    sed -r -e "s@KANJI@${kanji}@g" \
           -e 's@(READING[12]|MEANING[12]|GRAPHEM)@@g' \
           kanji.svg > question.svg
    inkscape --export-png=question/"$kanji".png question.svg > /dev/null &

    # generate answer cards
    sed -r -e "s@KANJI@@g" \
           -e "s@READING1@${reading1}@g" \
           -e "s@READING2@${reading2}@g" \
           -e "s@MEANING1@${meaning1}@g" \
           -e "s@MEANING2@${meaning2}@g" \
           -e "s@GRAPHEM@${graphem}@g" \
           kanji.svg > answer.svg
    inkscape --export-png=answer/"$kanji".png answer.svg > /dev/null &

    wait
    rm question.svg answer.svg

    # optimize
    ( convert -flatten question/"$kanji".png +dither -colors 2 png8:question/"$kanji".convert.png
      optipng -quiet question/"$kanji".convert.png
      mv question/"$kanji".convert.png question/"$kanji".png
    ) &

    ( convert answer/"$kanji".png +dither -colors 2 png8:answer/"$kanji".convert.png
      optipng -quiet answer/"$kanji".convert.png
      mv answer/"$kanji".convert.png answer/"$kanji".png
    ) &

    # wait # optimize can go into the next loop
done < kanji.txt

wait
And that's about it.
Attached Thumbnails
Click image for larger version

Name:	question-森.png
Views:	2364
Size:	8.9 KB
ID:	167256   Click image for larger version

Name:	answer-森.png
Views:	843
Size:	3.7 KB
ID:	167257   Click image for larger version

Name:	easy.png
Views:	763
Size:	2.4 KB
ID:	167258   Click image for larger version

Name:	hard.png
Views:	753
Size:	2.7 KB
ID:	167259  

Last edited by frostschutz; 10-28-2018 at 05:33 AM.
frostschutz is offline   Reply With Quote