Generate QR codes for game websites as last game image
[stouyapi.git] / bin / create-qr.sh
diff --git a/bin/create-qr.sh b/bin/create-qr.sh
new file mode 100755 (executable)
index 0000000..e0fc6ab
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Create an image that contains a QR code for the given website
+# together with the URL as readable text
+set -e
+
+if [ "$#" -lt 2 ]; then
+    echo "Usage: create-qr.sh https://example.org outfile.png" > /dev/stderr
+    exit 1
+fi
+
+if ! command -v convert > /dev/null; then
+    echo "convert (imagemagick) is not installed" > /dev/stderr
+    exit 2
+fi
+
+if ! command -v exiftool > /dev/null; then
+    echo "exiftool is not installed" > /dev/stderr
+    exit 2
+fi
+
+if ! command -v qrencode > /dev/null; then
+    echo "qrencode is not installed" > /dev/stderr
+    exit 2
+fi
+
+url="$1"
+filename="$2"
+
+qrencode -s 20 -o tmp-qr.png "$url"
+
+convert\
+    -filter point -resize 1260x580\
+    -background white\
+    tmp-qr.png\
+    -size 1260x120\
+    -fill black\
+    -gravity south\
+    label:"$url"\
+    -append\
+    -bordercolor white\
+    -border 10\
+    "$filename"
+
+rm tmp-qr.png
+
+exiftool\
+    -quiet\
+    -ignoreMinorErrors\
+    -PNG:Software=stouyapi\
+    -PNG:Title="$url"\
+    "$filename"