From c4e03e9b5ec2b9301a98d0663887864d216889f5 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Thu, 13 Mar 2025 19:04:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(img-scripts)=20Add=20downsize-for-?= =?UTF-8?q?web=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- img-scripts/README.org | 15 +++++ img-scripts/downsize-for-web.sh | 59 +++++++++++++++++++ .../social-media-framing.sh | 0 social-media-framing/README.org | 7 --- 4 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 img-scripts/README.org create mode 100755 img-scripts/downsize-for-web.sh rename {social-media-framing => img-scripts}/social-media-framing.sh (100%) delete mode 100644 social-media-framing/README.org diff --git a/img-scripts/README.org b/img-scripts/README.org new file mode 100644 index 0000000..914143a --- /dev/null +++ b/img-scripts/README.org @@ -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. diff --git a/img-scripts/downsize-for-web.sh b/img-scripts/downsize-for-web.sh new file mode 100755 index 0000000..6f3e296 --- /dev/null +++ b/img-scripts/downsize-for-web.sh @@ -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 "$final" ]]; 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." diff --git a/social-media-framing/social-media-framing.sh b/img-scripts/social-media-framing.sh similarity index 100% rename from social-media-framing/social-media-framing.sh rename to img-scripts/social-media-framing.sh diff --git a/social-media-framing/README.org b/social-media-framing/README.org deleted file mode 100644 index 6ce4972..0000000 --- a/social-media-framing/README.org +++ /dev/null @@ -1,7 +0,0 @@ -#+title: Social Media Framing - -A little bash script using [[https://imagemagick.org][ImageMagick]] and [[https://exiftool.org/][exiftool]] for 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=)