Skip to content

Instantly share code, notes, and snippets.

@ralph
Created January 23, 2025 00:30
Show Gist options
  • Select an option

  • Save ralph/28e55b74483517dc06f0a2602850f131 to your computer and use it in GitHub Desktop.

Select an option

Save ralph/28e55b74483517dc06f0a2602850f131 to your computer and use it in GitHub Desktop.

Revisions

  1. ralph created this gist Jan 23, 2025.
    58 changes: 58 additions & 0 deletions vips-processing.zsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    # Examples:
    # squarify_white 2023-10-11.jpg
    # 4x5ify_white *.heic

    4x5ify() {
    for file in "${@:3}"; do
    if [[ "${file}" == *-4x5-* ]]; then
    continue
    fi
    if [[ $(vipsheader -f height ${file}) != 2580 ]]; then
    vipsthumbnail "${file}" -s 2580x2580 -o temp.v
    target=temp.v
    else
    target="${file}"
    fi
    vips gravity $target "${file:t:r}${2}.${file:t:e}" centre 2160 2700 --background "${1}"
    if [[ "${target}" == temp.v ]]; then
    rm temp.v
    fi
    done
    }
    squarify() {
    for file in "${@:3}"; do
    if [[ "${file}" == *-square-* ]]; then
    continue
    fi
    if [[ $(vipsheader -f width ${file}) != 2040 ]]; then
    vipsthumbnail "${file}" -s 2040x2040 -o temp.v
    target=temp.v
    else
    target="${file}"
    fi
    vips gravity $target "${file:t:r}${2}.${file:t:e}" centre 2160 2160 --background "${1}"
    if [[ "${target}" == temp.v ]]; then
    rm temp.v
    fi
    done
    }
    squarify_white() {
    squarify "255" "-square-white" "$@"
    }
    squarify_black() {
    squarify "0" "-square-black" "$@"
    }
    squarify_both() {
    squarify_black "$@"
    squarify_white "$@"
    }
    4x5ify_white() {
    4x5ify "255" "-4x5-white" "$@"
    }
    4x5ify_black() {
    4x5ify "0" "-4x5-black" "$@"
    }
    4x5ify_both() {
    4x5ify_black "$@"
    4x5ify_white "$@"
    }