commit 07da1486e66f9847d47f82964000a92e0f7a3547 parent 33c257aa68932aeba01b93d33f401adbaf985e89 Author: Alex Balgavy <alex@balgavy.eu> Date: Mon, 3 May 2021 17:52:44 +0200 removebg: remove white background from images Diffstat:
A | scripts/removebg | | | 21 | +++++++++++++++++++++ |
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/scripts/removebg b/scripts/removebg @@ -0,0 +1,21 @@ +#!/bin/sh +die() { + echo "$1" >&2 + exit 1 +} + +# Preliminary checks +command -v convert >/dev/null 2>&1 || die "imagemagick not found." +[ $# -ge 2 ] || die "Usage: $0 input.ext output.ext" +[ -f "$1" ] || die "File $1 not found." +[ -f "$2" ] && { + printf "File %s exists, overwrite? [y/N] " "$2" + read -r conf; case "$conf" in + Y*|y*) ;; + *) exit 0 ;; + esac +} + +fuzz="${3:-15%}" +convert -trim -transparent white -fuzz "$fuzz" "$1" "$2" +printf "Saved as %s\nIf the result looks bad, pass a fuzz percentage as the last argument." "$2"