Created
January 23, 2025 00:30
-
-
Save ralph/28e55b74483517dc06f0a2602850f131 to your computer and use it in GitHub Desktop.
Create square or 4x5 images with black or white frame borders using VIPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment