qubes.GetImageRGBA 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. set -e
  2. read filename
  3. ICON_MAXSIZE=512
  4. if [ "${filename%%:*}" = xdgicon ]; then
  5. filename="$(/usr/lib/qubes/xdg-icon "${filename#*:}" "$ICON_MAXSIZE")"
  6. forcesize="$ICON_MAXSIZE"
  7. [ -n "${filename}" ]
  8. elif [ "${filename}" = "-" ] || [ "${filename##*:}" = "-" ]; then
  9. tmpfile="$(mktemp /tmp/qimg-XXXXXXXX)"
  10. cat > "${tmpfile}"
  11. if [ "${filename##*:}" = "-" ]; then
  12. filename="${filename%:*}:${tmpfile}"
  13. else
  14. filename="${tmpfile}"
  15. fi
  16. elif ! [ -r "${filename}" ]; then
  17. exit 1
  18. fi
  19. s="$(identify -format '%w %h %m' "$filename")"
  20. w="$(echo "$s"|cut -d " " -f 1)"
  21. h="$(echo "$s"|cut -d " " -f 2)"
  22. m="$(echo "$s"|cut -d " " -f 3)"
  23. if [ "$m" = SVG ]; then
  24. if [ -n "$forcesize" ]; then
  25. w="$forcesize"
  26. h="$forcesize"
  27. fi
  28. tmpfile2="$(mktemp /tmp/qimg-XXXXXXXX.png)"
  29. rsvg-convert -w "$w" -h "$h" -o "$tmpfile2" "$filename"
  30. filename="$tmpfile2"
  31. fi
  32. echo "$w $h"
  33. convert -depth 8 -size "${w}x${h}" "$filename" rgba:-
  34. [ -n "${tmpfile}" ] && rm -f "${tmpfile}" || true
  35. [ -n "${tmpfile2}" ] && rm -f "${tmpfile2}" || true
  36. # vim: ft=sh ts=4 sw=4 et