I use this code to auto generate slides from a .txt file where I wrote captions this way:
CAPTION 1
CAPTION 2
...
CAPTION N
This is the script I use
#!/bin/bash
i=0
# loop through files
while IFS= read -r p; do
# if it's not an empty line
if ! [ -z "$p"]; then
# echo line
echo "$p";
convert -background none -font Trebuchet-MS -fill white -pointsize 60 -gravity center -draw "text 0,300 'pango:$p'" slide_template.png slides/slide-$i.png
i=$((i+1))
fi;
# pass input
done <$@
slide_template.png is simply an empty (transparent) 1920x1080 png.
I pass my .txt file this way:
$ sh my_script.sh my_file.txt
And it generates my slides in /slides.
Now I'd like to use some format code into my slides, like
MY <b>CAPTION</b> 1
MY <i>CAPTION</i> 2
...
MY CAPTION N
But I can't understand how to use pango in my previous code. I need to reposition my caption line centered, 300 pixels from the bottom.
If I use:
convert -background none -font Trebuchet-MS -fill white -pointsize 60 -gravity center -draw "text 0,300 '$p'" slide_template.png slides/slide-$i.png
I get:
If I use this line:
convert -background none -font Trebuchet-MS -fill white -pointsize 60 -gravity center pango:"$p" slide_template.png slides/slide-$i.png
I get TWO files (why?), where the first one is correctly parsed but cropped to the text size:
And the second one is the background. Filenames this way are slide-0-0.png and slide-0-1.png
Solved: I need to pipe one image to another.
The first contains the formatted code, the second overlays the piped data onto the background.
#!/bin/bash
i=0
# loop through files
while IFS= read -r p; do
# if it's not an empty line
if ! [ -z "$p"]; then
convert -background none -font Trebuchet-MS -fill white -pointsize 60 -gravity center -size 1920x300 pango:"$p" png:- | convert slide_template.png png:- -geometry +0+800 -composite slides/slide-$i.png
i=$((i+1))
fi;
# pass input
done <$@