Skip to content

Commit f345ca0

Browse files
committed
qubes.GetImageRGBA: fix SVG conversion for images without explicit dimensions
SVGs without explicit width/height cause gm identify to report 0x0. Pass those dimensions to rsvg-convert only when they are non-zero; otherwise let rsvg-convert render at the SVG's natural size. Re-read the actual dimensions from the rendered PNG afterwards so the forcemaxsize downscale check and the final gm convert use correct values. Replace echo+cut with read -r for dimension parsing throughout.
1 parent 0a67a77 commit f345ca0

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

qubes-rpc/qubes.GetImageRGBA

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@ 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+
gm identify -format '%w %h %m' "$filename" | read -r w h m
2825
if [ "$m" = SVG ]; then
2926
tmpfile2="$(mktemp /tmp/qimg-XXXXXXXX.png)"
30-
rsvg-convert -w "$w" -h "$h" -o "$tmpfile2" "$filename"
27+
if [ -n "$w" ] && [ "$w" -gt 0 ] && [ -n "$h" ] && [ "$h" -gt 0 ]; then
28+
rsvg-convert -w "$w" -h "$h" -o "$tmpfile2" "$filename"
29+
else
30+
rsvg-convert -o "$tmpfile2" "$filename"
31+
# re-read dimensions from the rendered PNG since SVG had no explicit size
32+
gm identify -format '%w %h' -- "$tmpfile2" | read -r w h
33+
fi
3134
# downscale the image if necessary
3235
if [ -n "$forcemaxsize" ] && \
3336
{ [ "$w" -gt "$forcemaxsize" ] || [ "$h" -gt "$forcemaxsize" ]; }; then
3437
gm convert "$tmpfile2" -scale "${forcemaxsize}x${forcemaxsize}" "$tmpfile2"
3538
fi
3639
# 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)"
40+
gm identify -format '%w %h' -- "$tmpfile2" | read -r w h
4041
filename="$tmpfile2"
4142
fi
4243
echo "$w $h"

0 commit comments

Comments
 (0)