Skip to content

Commit 0bb693c

Browse files
committed
qubes.GetImageRGBA: fix SVG conversion for images without explicit dimensions
1 parent 0a67a77 commit 0bb693c

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

qubes-rpc/qubes.GetImageRGBA

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,29 @@ elif ! [ -r "${filename}" ]; then
2121
exit 1
2222
fi
2323

24-
s="$(gm identify -format '%w %h %m' "$filename")"
25-
w="$(echo "$s"|cut -d " " -f 1)"
26-
h="$(echo "$s"|cut -d " " -f 2)"
27-
m="$(echo "$s"|cut -d " " -f 3)"
24+
read -r w h m << EOF
25+
$(gm identify -format '%w %h %m' "$filename")
26+
EOF
2827
if [ "$m" = SVG ]; then
2928
tmpfile2="$(mktemp /tmp/qimg-XXXXXXXX.png)"
30-
rsvg-convert -w "$w" -h "$h" -o "$tmpfile2" "$filename"
29+
if [ -n "$w" ] && [ "$w" -gt 0 ] && [ -n "$h" ] && [ "$h" -gt 0 ]; then
30+
rsvg-convert -w "$w" -h "$h" -o "$tmpfile2" "$filename"
31+
else
32+
rsvg-convert -o "$tmpfile2" "$filename"
33+
# re-read dimensions from the rendered PNG since SVG had no explicit size
34+
read -r w h << EOF
35+
$(gm identify -format '%w %h' "$tmpfile2")
36+
EOF
37+
fi
3138
# downscale the image if necessary
3239
if [ -n "$forcemaxsize" ] && \
3340
{ [ "$w" -gt "$forcemaxsize" ] || [ "$h" -gt "$forcemaxsize" ]; }; then
3441
gm convert "$tmpfile2" -scale "${forcemaxsize}x${forcemaxsize}" "$tmpfile2"
3542
fi
3643
# read the size again, because icon may not be a square or could have changed with convert
37-
s="$(gm identify -format '%w %h' "$tmpfile2")"
38-
w="$(echo "$s"|cut -d " " -f 1)"
39-
h="$(echo "$s"|cut -d " " -f 2)"
44+
read -r w h << EOF
45+
$(gm identify -format '%w %h' "$tmpfile2")
46+
EOF
4047
filename="$tmpfile2"
4148
fi
4249
echo "$w $h"

0 commit comments

Comments
 (0)