summarylogtreecommitdiffstats
path: root/xbr.sh
diff options
context:
space:
mode:
Diffstat (limited to 'xbr.sh')
-rwxr-xr-xxbr.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/xbr.sh b/xbr.sh
new file mode 100755
index 000000000000..6a4045874401
--- /dev/null
+++ b/xbr.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+usage() {
+ echo "Usage: xbr [-s scaleBy] input output"
+ exit 1
+}
+
+scale=4
+
+while getopts ":s:" option; do
+ case $option in
+ s)
+ if [ "$scale" -ne 2 ] && [ "$scale" -ne 3 ] && [ "$scale" -ne 4 ]; then
+ echo "Only scale factors of 2, 3 and 4 are supported"
+ fi
+ scale="$OPTARG"
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ ;;
+ :)
+ echo "xbr: option requires an argument -- '$OPTARG'"
+ usage
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+inputfile="$1"
+outputfile="$2"
+
+if [ -z "$inputfile" ] || [ -z "$outputfile" ]; then
+ usage
+fi
+
+filetype="$(identify -format "%m" "$inputfile" 2>&1)"
+input_exists="$?"
+
+if ! [ -s "$inputfile" ] || [ $input_exists -ne 0 ]; then
+ echo "ERROR: can't load '$inputfile'"
+ exit 1
+fi
+
+if ! [ "$filetype" = "PNG" ]; then
+ convert "$inputfile" "._temp_png.png"
+ inputfile="._temp_png.png"
+fi
+
+pixelscale "$inputfile" "$outputfile" "xbr${scale}x"
+
+if [ -e "._temp_png.png" ]; then
+ rm "._temp_png.png"
+fi