Last active
September 27, 2018 14:26
-
-
Save beaulac/a9ca6971ba1dd9fff33a3390ccb0574d to your computer and use it in GitHub Desktop.
Replace fuzzy single color in sRGB transparent PNG
This file contains hidden or 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
#!/usr/bin/env bash | |
FILE=$(realpath ${1}); | |
OLD=$2; | |
NEW=$3; | |
# Default fuzz: 25% | |
FUZZ=${4:-25}; | |
######################## | |
# 1. Flatten & color-replace original into clone | |
# 2. Extract alpha channel from original image into clone | |
# 3. Remove original, composite flat + alpha into output. | |
######################## | |
convert ${FILE} \ | |
\( -clone 0 -alpha off -set colorspace sRGB -fuzz ${FUZZ}% -fill "${NEW}" -opaque "${OLD}" \) \ | |
\( -clone 0 -alpha extract -set colorspace sRGB \) \ | |
-delete 0 -compose copy_opacity -composite ${FILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment