qubes.GetImageRGBA 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. set -e
  2. read filename
  3. if [[ "${filename}" = xdgicon:* ]]; then
  4. # get biggest icon from hicolor theme
  5. filename="${filename#*:}.png"
  6. candidate=
  7. for dir in /usr/share/icons/{hicolor/,}; do
  8. candidate=$(find -L "${dir}" -type f -name "${filename}")
  9. if [[ -n "${candidate}" ]]; then
  10. candidate=$(echo "${candidate}" | xargs ls --sort=size | head -1)
  11. break
  12. fi
  13. done
  14. [[ -n "${candidate}" ]]
  15. filename="${candidate}"
  16. elif [[ "${filename}" = "-" ]] || [[ "${filename}" = *":-" ]]; then
  17. tmpfile="$(mktemp /tmp/qimg-XXXXXXXX)"
  18. cat > "${tmpfile}"
  19. if [[ "$filename" = *":-" ]]; then
  20. tmpfile="${filename%:*}:${tmpfile}"
  21. fi
  22. filename="${tmpfile}"
  23. elif ! [[ -r "${filename}" ]]; then
  24. exit 1
  25. fi
  26. # identify in F18 (6.7) adds implicit '\n' to format,
  27. # whereas identify in F20 (6.8) does not
  28. identify -format '%w %h\n' "$filename" | sed -e '/^$/d'
  29. convert -depth 8 "$filename" rgba:-
  30. [[ -n "${tmpfile}" ]] && rm -f ${tmpfile} || true
  31. # vim: ft=sh ts=4 sw=4 et