image-info 440 B

123456789101112131415161718192021222324
  1. #!/bin/sh --
  2. set -ue
  3. : "${1:?}" "${2:?}" "${3:?}"
  4. gcd() {
  5. while [ "${2:?}" -ne 0 ]; do
  6. set -- "${2:?}" "$(( ${1:?} % ${2:?} ))"
  7. done
  8. echo "${1:?}"
  9. }
  10. gcd="$(gcd "${2}" "${3}")"
  11. aspect="$(( ${2} / gcd )):$(( ${3} / gcd ))"
  12. s=" " # field separator
  13. filename="${1##*/}"
  14. geometry="${2}x${3}"
  15. filesize="$(du -h -- "${1}")"
  16. filesize="${filesize%$(printf %b '\t')*}"
  17. printf %s "${filesize% *}${s}${geometry}${s}${aspect}${s}${filename}"