summaryrefslogtreecommitdiffstats
path: root/tools/image_text
blob: b14eaabec9cb66083fb4e685c100f6a3633ae469 (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
#!/bin/bash
#
# Date:    2009-12-04
# Author:  Ole Kristian Lien
# License: GNU General Public License
#
# Make a text-image (intro-outro)
#
# lang. Bli kvitt counter.

EXT=`echo "$1"|awk -F . '{print $NF}'`
NAME=`basename $1 .$EXT`

FONT="/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf"
SIZE=`./video_resolution $1`
COUNTER=$2
BGCOLOR=$3

COUNT1=`echo $4 | wc -c`
COUNT2=`echo $5 | wc -c`

SIZE1="0"
SIZE2="0"

if [ $COUNT1 -ge "30" ] ; then
	SIZE1="30"
	SIZE2=`echo $SIZE1-10|bc`
#	echo "Size1: $SIZE1 - Size2: $SIZE2"
elif [ $COUNT1 -ge "25" ] ; then
	SIZE1="40"
	SIZE2=`echo $SIZE1-10|bc`
#	echo "Size1: $SIZE1 - Size2: $SIZE2"
elif [ $COUNT1 -ge "20" ] ; then
	SIZE1="50"
	SIZE2=`echo $SIZE1-20|bc`
#	echo "Size1: $SIZE1 - Size2: $SIZE2"
else
	SIZE1="60"
	if [ $COUNT2 -ge "25" ] ; then
		SIZE2=`echo $SIZE1-30|bc`
	else
		SIZE2=`echo $SIZE1-20|bc`
	fi

#	echo "Size1: $SIZE1 - Size2: $SIZE2"
fi

if [ -z "$4" ]; then
	echo "Usage: $0 <video-file> <counter> <bg-color> <text1> [<text2>]"
	exit 1
fi

if [ ! -f $FONT ]; then
	echo "Font $FONT does not exists"
	exit 1
fi

if [ $BGCOLOR == "white" ]; then
	FGCOLOR="black"
elif [ $BGCOLOR == "black" ]; then
	FGCOLOR="white"
else
	echo "Only black or white is allowed"
	exit 1
fi

if [ $# -gt 4 ]; then
	convert -font $FONT -size $SIZE xc:$BGCOLOR \
	-fill $FGCOLOR -gravity center -pointsize $SIZE1 -draw "text 0,0 '${4}'" \
	-fill $FGCOLOR -gravity center -pointsize $SIZE2 -draw "text 0,60 '${5}'" \
	-append $NAME-$COUNTER.png
else
	convert -font $FONT -size $SIZE xc:$BGCOLOR \
	-fill $FGCOLOR -gravity center -pointsize $SIZE1 -draw "text 0,0 '${4}'" \
	-append $NAME-$COUNTER.png
fi