Shell script Quasar Framework Icons

Shell script Quasar Framework Icons

Mit dem folgenden Shell script werden alle notwendigen Icons für das Quasar Framework in den richtigen Größen und Formaten mit der Hilfe von ImageMagick erstellt.

#!/bin/sh

PATH="/bin:/usr/bin"

script="`basename \"$0\"`"

srcfile="`realpath -e \"$1\" 2>/dev/null`"

if [ -z "$srcfile" ] ; then
	echo "$script: file not found \"$1\"" >&2
	exit 1
fi

iconsdir="`cd \"$2\" 2>/dev/null && pwd`"

if [ -z "$iconsdir" ] ; then
	echo "$script: directory not found \"$2\"" >&2
	exit 1
fi

if [ -z "`which convert 2>/dev/null`" ] ; then
	echo "$script: convert command from ImageMagick not found" >&2
	exit 1
fi

doconvert() {
	prefix="$1"
	s="$2"
	output="$iconsdir/${prefix}-${s}x${s}.png"
	if [ -n "$3" ] ; then
		output="$iconsdir/$3"
	fi
	if [ -e "$output" ] ; then
		echo -n "Overwrite \"$output\"? (Y/n) "
		read -n1 a
		if [ -n "$a" ] ; then echo "" ; fi
		if [ "X$a" = "Xn" ] || [ "X$a" = "XN" ] ; then
			return
		fi
	fi
	convert "$srcfile" -resize "x${s}" -transparent white "$output"
	if [ "$?" -ne 0 ] ; then
		echo "$script: failed convert \"$srcfile\" -resize \"x${s}\" \"$output\"" >&2
	fi
}

icoconvert() {
	output="$iconsdir/favicon.ico"
	if [ -e "$output" ] ; then
		echo -n "Overwrite \"$output\"? (Y/n) "
		read -n1 a
		if [ -n "$a" ] ; then echo "" ; fi
		if [ "X$a" = "Xn" ] || [ "X$a" = "XN" ] ; then
			return
		fi
	fi
	for s in 16 32 ; do
		output="$iconsdir/output-${s}x${s}.ico"
		if [ -e "$output" ] ; then
			echo -n "Overwrite \"$output\"? (Y/n) "
			read -n1 a
			if [ -n "$a" ] ; then echo "" ; fi
			if [ "X$a" = "Xn" ] || [ "X$a" = "XN" ] ; then
				continue
			fi
		fi
		convert "$srcfile" -resize "x$s" -gravity center -crop "${s}x${s}+0+0" -flatten -colors 256 -transparent white "$output"
		if [ "$?" -ne 0 ] ; then
			echo "$script: failed convert \"$srcfile\" -resize \"x$s\" -gravity center -crop \"${s}x${s}+0+0\" -flatten -colors 256 \"$output\"" >&2
		fi
	done
	output="$iconsdir/favicon.ico"
	if [ -e "$output" ] ; then
		echo -n "Overwrite \"$output\"? (Y/n) "
		read -n1 a
		if [ -n "$a" ] ; then echo "" ; fi
		if [ "X$a" = "Xn" ] || [ "X$a" = "XN" ] ; then
			for s in 16 32 ; do
				output="$iconsdir/output-${s}x${s}.ico"
				rm "$output" 2>/dev/null
			done	
			return
		fi
	fi
	convert "$iconsdir/output-16x16.ico" "$iconsdir/output-32x32.ico" -transparent white "$output"
	if [ "$?" -ne 0 ] ; then
		echo "$script: failed convert \"$iconsdir/output-16x16.ico\" \"$iconsdir/output-32x32.ico\" \"$output\"" >&2
	fi
	for s in 16 32 ; do
		output="$iconsdir/output-${s}x${s}.ico"
		rm "$output" 2>/dev/null
	done	
}

for s in 120 152 167 180 ; do
	doconvert "apple-icon" "$s"
done

icoconvert
for s in 16 32 96 ; do
	doconvert "favicon" "$s"
done

for s in 128 192 256 384 512 ; do
	doconvert "icon" "$s"
done

doconvert "ms-icon" "144"

doconvert "app-logo" "128"

output="`realpath $iconsdir/../app-logo-128x128.png`"
echo -n "Copy to \"$output\"? (Y/n) "
read -n1 a
if [ -n "$a" ] ; then echo "" ; fi
if [ "X$a" != "Xn" ] && [ "X$a" != "XN" ] ; then
	if [ -e "$output" ] ; then
		echo -n "Overwrite \"$output\"? (Y/n) "
		read -n1 a
		if [ -n "$a" ] ; then echo "" ; fi
		if [ "X$a" != "Xn" ] && [ "X$a" != "XN" ] ; then
			cp "$iconsdir/app-logo-128x128.png" "$output"
		fi
	fi
fi

output="$iconsdir/safari-pinned-tab.svg"
if [ -e "$output" ] ; then
	echo -n "Overwrite \"$output\"? (Y/n) "
	read -n1 a
	if [ -n "$a" ] ; then echo "" ; fi
	if [ "X$a" = "Xn" ] || [ "X$a" = "XN" ] ; then
		exit 0
	fi
fi
cp -a "$srcfile" "$output"