-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathasc-to-gif.sh
executable file
·51 lines (42 loc) · 1.15 KB
/
asc-to-gif.sh
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
#!/usr/bin/env bash
# Check requirements
hash qrencode 2>/dev/null || { echo >&2 "Aborting: qrencode not installed"; exit 1; }
# Check argument
if [ $# -ne 2 ]; then
echo "Usage: $0 <ascii armor key filename> <gif filename>"
exit 1
fi
asc_filename=$1
if [ ! -f ${asc_filename} ]; then
echo "Error: ${asc_filename} not found"
exit 1
fi
# Settings
gif_filename=$2
gif_delay=100
qrcode_size=1732
qrcode_version=30
# Split the file
rm -f ${asc_filename}.split*
split -b ${qrcode_size} ${asc_filename} ${asc_filename}.split
# Generate png
for f in ${asc_filename}.split*; do
qrencode -v ${qrcode_version} -o $f.png < $f
rm $f
done
if hash zbarimg 2>/dev/null; then
# Check png
> ${asc_filename}.scanned
for f in ${asc_filename}.split*; do
printf %s "$(zbarimg --raw -q $f)" >> ${asc_filename}.scanned
done
printf %s "$(cat ${asc_filename})" | diff ${asc_filename}.scanned -
rm ${asc_filename}.scanned
else
echo "Skip testing: zbarimg not installed"
fi
# Convert to gif
convert -delay ${gif_delay} ${asc_filename}.split* ${gif_filename}
echo "Generated: ${gif_filename}"
# Clean up png
rm ${asc_filename}.split*