2014-01-30 16:30:17 +01:00
|
|
|
set -e
|
|
|
|
read filename
|
|
|
|
|
2015-09-06 21:05:01 +02:00
|
|
|
ICON_MAXSIZE=512
|
2014-02-04 00:22:26 +01:00
|
|
|
|
2015-09-06 21:05:01 +02:00
|
|
|
if [ "${filename%%:*}" = xdgicon ]; then
|
|
|
|
filename="$(/usr/lib/qubes/xdg-icon "${filename#*:}" "$ICON_MAXSIZE")"
|
2016-03-29 16:38:04 +02:00
|
|
|
forcemaxsize="$ICON_MAXSIZE"
|
2014-01-30 16:30:17 +01:00
|
|
|
|
2015-09-06 21:05:01 +02:00
|
|
|
[ -n "${filename}" ]
|
2015-02-05 03:14:41 +01:00
|
|
|
elif [ "${filename}" = "-" ] || [ "${filename##*:}" = "-" ]; then
|
2014-01-30 16:30:17 +01:00
|
|
|
tmpfile="$(mktemp /tmp/qimg-XXXXXXXX)"
|
|
|
|
cat > "${tmpfile}"
|
2015-02-05 03:14:41 +01:00
|
|
|
if [ "${filename##*:}" = "-" ]; then
|
2015-09-06 11:07:57 +02:00
|
|
|
filename="${filename%:*}:${tmpfile}"
|
|
|
|
else
|
|
|
|
filename="${tmpfile}"
|
2014-01-30 16:30:17 +01:00
|
|
|
fi
|
2015-02-05 03:14:41 +01:00
|
|
|
elif ! [ -r "${filename}" ]; then
|
2014-01-30 16:30:17 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-09-06 21:05:01 +02:00
|
|
|
s="$(identify -format '%w %h %m' "$filename")"
|
|
|
|
w="$(echo "$s"|cut -d " " -f 1)"
|
|
|
|
h="$(echo "$s"|cut -d " " -f 2)"
|
|
|
|
m="$(echo "$s"|cut -d " " -f 3)"
|
|
|
|
if [ "$m" = SVG ]; then
|
|
|
|
tmpfile2="$(mktemp /tmp/qimg-XXXXXXXX.png)"
|
2016-03-29 16:38:04 +02:00
|
|
|
rsvg-convert -o "$tmpfile2" "$filename"
|
|
|
|
# downscale the image if necessary
|
|
|
|
if [ -n "$forcemaxsize" -a \
|
|
|
|
\( "$w" -gt "$forcemaxsize" -o "$h" -gt "$forcemaxsize" \) ]; then
|
|
|
|
convert "$tmpfile2" -scale "${forcemaxsize}x${forcemaxsize}" "$tmpfile2"
|
|
|
|
# read the size again, because icon may not be a square
|
|
|
|
s="$(identify -format '%w %h' "$tmpfile2")"
|
|
|
|
w="$(echo "$s"|cut -d " " -f 1)"
|
|
|
|
h="$(echo "$s"|cut -d " " -f 2)"
|
|
|
|
fi
|
2015-09-06 21:05:01 +02:00
|
|
|
filename="$tmpfile2"
|
|
|
|
fi
|
|
|
|
echo "$w $h"
|
|
|
|
convert -depth 8 -size "${w}x${h}" "$filename" rgba:-
|
2014-01-30 16:30:17 +01:00
|
|
|
|
2015-09-06 11:07:57 +02:00
|
|
|
[ -n "${tmpfile}" ] && rm -f "${tmpfile}" || true
|
2015-09-06 21:05:01 +02:00
|
|
|
[ -n "${tmpfile2}" ] && rm -f "${tmpfile2}" || true
|
2014-01-30 16:30:17 +01:00
|
|
|
|
|
|
|
# vim: ft=sh ts=4 sw=4 et
|