qubes-core-agent-linux/qubes-rpc/qubes.GetImageRGBA
Marek Marczykowski-Górecki 2bfbfadc84
qubes.GetImageRGBA: fix handling '-' path without explicit type
There was a bug that interpreted '-' as file type. But convert don't
know how to handle '-' file type, so refused to proceed.

Fixes QubesOS/qubes-issues#3085

(cherry picked from commit ec83df64e3)
2018-02-10 22:20:29 +01:00

49 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
set -e
read filename
ICON_MAXSIZE=512
if [ "${filename%%:*}" = xdgicon ]; then
filename="$(/usr/lib/qubes/xdg-icon "${filename#*:}" "$ICON_MAXSIZE")"
forcemaxsize="$ICON_MAXSIZE"
[ -n "${filename}" ]
elif [ "${filename}" = "-" ] || [ "${filename##*:}" = "-" ]; then
tmpfile="$(mktemp /tmp/qimg-XXXXXXXX)"
cat > "${tmpfile}"
if [ "${filename%:*}" != "-" ]; then
filename="${filename%:*}:${tmpfile}"
else
filename="${tmpfile}"
fi
elif ! [ -r "${filename}" ]; then
exit 1
fi
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)"
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
filename="$tmpfile2"
fi
echo "$w $h"
convert -depth 8 -size "${w}x${h}" "$filename" rgba:-
[ -n "${tmpfile}" ] && rm -f "${tmpfile}" || true
[ -n "${tmpfile2}" ] && rm -f "${tmpfile2}" || true
# vim: ft=sh ts=4 sw=4 et