✨ (img-scripts) Add downsize-for-web script
This commit is contained in:
parent
120739bff3
commit
4bfbc50b90
4 changed files with 74 additions and 7 deletions
15
img-scripts/README.org
Normal file
15
img-scripts/README.org
Normal file
|
@ -0,0 +1,15 @@
|
|||
#+title: Image Helper Scripts
|
||||
|
||||
A collection of little bash scripts using [[https://imagemagick.org][ImageMagick]] and [[https://exiftool.org/][exiftool]] for adjusting images.
|
||||
|
||||
** social-media-framing
|
||||
|
||||
Preparing pictures for sharing on social networks. The image given as first argument is used as a source to create the following three variations:
|
||||
|
||||
- No changes, except a maximum resolution of 1920px at the longest edge (suffix =-regular=)
|
||||
- White border to make the image a 1920x1920px square (suffix =-square=)
|
||||
- White border to make the image a 1080x1920px portrait orientation "story" (suffix =-story=)
|
||||
|
||||
** downsize-for-web
|
||||
|
||||
Downsize given image (first argument) for web by converting it to WebP with a maximum resolution of 1920x1920px and a target size of about 350kb.
|
59
img-scripts/downsize-for-web.sh
Executable file
59
img-scripts/downsize-for-web.sh
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
BOLD="\033[1m"
|
||||
INFO="\033[0;30m\033[47m"
|
||||
WORK="\033[0;30m\033[44m"
|
||||
DONE="\033[0;30m\033[42m"
|
||||
FAIL="\033[0;30m\033[41m"
|
||||
NC="\033[0m"
|
||||
|
||||
log_info() {
|
||||
echo -e "${INFO} INFO ${NC} $1"
|
||||
}
|
||||
|
||||
log_work() {
|
||||
echo -e "${WORK} WORK ${NC} $1"
|
||||
}
|
||||
|
||||
log_done() {
|
||||
echo -e "${DONE} DONE ${NC} $1"
|
||||
}
|
||||
|
||||
log_fail() {
|
||||
echo -e "${FAIL} FAIL ${NC} $1"
|
||||
}
|
||||
|
||||
log_info "Welcome to the ${BOLD}downsize-for-web${NC} script."
|
||||
log_info "We're using the power of ${BOLD}imagemagick${NC} and ${BOLD}exiftool${NC}."
|
||||
|
||||
set +u
|
||||
if [[ -z "$1" ]]; then
|
||||
log_fail "Missing filename argument."
|
||||
exit 1
|
||||
fi
|
||||
set -u
|
||||
|
||||
if [[ ! -f "$1" ]]; then
|
||||
log_fail "File with filename $1 not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filename="$(basename "$1")"
|
||||
path="$(dirname "$1")/${filename%%.*}"
|
||||
output="$path""-web.webp"
|
||||
|
||||
if [[ -f "$output" ]]; then
|
||||
log_done "A downsized image is already available."
|
||||
exit
|
||||
fi
|
||||
|
||||
log_work "Downsizing image…"
|
||||
convert "$1" -resize "1920x1920>" -define webp:target-size=350000 "$output"
|
||||
|
||||
log_work "Fixing EXIF metadata"
|
||||
exiftool -q -tagsFromFile "$1" "$output"
|
||||
|
||||
exiftool -q -delete_original! "$(dirname "$1")"
|
||||
log_done "Finished creating downsized web image."
|
82
img-scripts/social-media-framing.sh
Executable file
82
img-scripts/social-media-framing.sh
Executable file
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
INFO="\033[0;30m\033[47m"
|
||||
START="\033[0;30m\033[44m"
|
||||
DONE="\033[0;30m\033[42m"
|
||||
ERROR="\033[0;30m\033[41m"
|
||||
NC="\033[0m"
|
||||
|
||||
log_info() {
|
||||
echo -e "${INFO} INFO ${NC} $1"
|
||||
}
|
||||
|
||||
log_start() {
|
||||
echo -e "${START} START ${NC} $1"
|
||||
}
|
||||
|
||||
log_done() {
|
||||
echo -e "${DONE} DONE ${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${ERROR} ERROR ${NC} $1"
|
||||
}
|
||||
|
||||
log_info "Welcome to the social media framing script."
|
||||
log_info "We're using the power of imagemagick and exiftool"
|
||||
|
||||
set +u
|
||||
if [[ -z "$1" ]]; then
|
||||
log_error "Missing filename argument."
|
||||
exit 1
|
||||
fi
|
||||
set -u
|
||||
|
||||
if [[ ! -f "$1" ]]; then
|
||||
log_error "File with filename $1 not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filename="$(basename "$1")"
|
||||
extension="${filename##*.}"
|
||||
path="$(dirname "$1")/${filename%%.*}"
|
||||
|
||||
regular="$path""-regular.""$extension"
|
||||
square="$path""-square.""$extension"
|
||||
story="$path""-story.""$extension"
|
||||
|
||||
if [[ ! -f "$regular" ]]; then
|
||||
log_start "Creating regular framing"
|
||||
magick "$1" -resize "1920x1920>" "$regular"
|
||||
log_start "Fixing EXIF metadata"
|
||||
exiftool -q -tagsFromFile "$1" "$regular"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$square" ]]; then
|
||||
log_start "Creating square framing"
|
||||
magick -define jpeg:size=1920x1920 "$1" \
|
||||
-thumbnail '1890x1890' \
|
||||
-gravity center \
|
||||
-crop 1920x1920+0+0\! \
|
||||
-flatten \
|
||||
"$square"
|
||||
log_start "Fixing EXIF metadata"
|
||||
exiftool -q -tagsFromFile "$1" "$square"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$story" ]]; then
|
||||
log_start "Creating story framing"
|
||||
magick -define jpeg:size=1080x1920 "$1" \
|
||||
-thumbnail '1050x1890' \
|
||||
-gravity center \
|
||||
-crop 1080x1920+0+0\! \
|
||||
-flatten \
|
||||
"$story"
|
||||
log_start "Fixing EXIF metadata"
|
||||
exiftool -q -tagsFromFile "$1" "$story"
|
||||
fi
|
||||
|
||||
exiftool -q -delete_original! "$(dirname "$1")"
|
||||
log_done "Finished creating framed images"
|
Loading…
Add table
Add a link
Reference in a new issue