add posterize-image script
This commit is contained in:
parent
f293dfbec0
commit
64e8558dc4
1 changed files with 84 additions and 0 deletions
84
default/bin/posterize-image.sh
Executable file
84
default/bin/posterize-image.sh
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
#!/bin/bash
|
||||
|
||||
hex='d7afaf'
|
||||
hex_alt='111317'
|
||||
invert_flag=''
|
||||
dithering='FloydSteinberg'
|
||||
contrast='10'
|
||||
morph_level='7'
|
||||
threshold='50'
|
||||
|
||||
help() {
|
||||
executable_path=$(basename "${0}")
|
||||
printf "Usage: %s {FLAGS} [FILE]\n\
|
||||
ARGUMENTS:\n\
|
||||
-h display this help menu\n\
|
||||
-c [20] contrast level\n\
|
||||
-m [1] morph edge level\n\
|
||||
-t [20] threshold \n\
|
||||
-p [d7afaf] Primary hex color\n\
|
||||
-s [111317] Secondary hex color\n\
|
||||
-n Disable dithering\n\
|
||||
FILE Full path to original image file\n" "${executable_path}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
while getopts "hc:m:t:p:s:in" flag 2>/dev/null; do
|
||||
case "${flag}" in
|
||||
h)
|
||||
help
|
||||
;;
|
||||
c)
|
||||
contrast="${OPTARG}"
|
||||
;;
|
||||
m)
|
||||
morph_level="${OPTARG}"
|
||||
;;
|
||||
t)
|
||||
threshold="${OPTARG}"
|
||||
;;
|
||||
p)
|
||||
hex="${OPTARG//#/}"
|
||||
;;
|
||||
s)
|
||||
hex_alt="${OPTARG//#/}"
|
||||
;;
|
||||
i)
|
||||
invert_flag='-negate'
|
||||
;;
|
||||
n)
|
||||
dithering='None'
|
||||
;;
|
||||
*)
|
||||
printf "[ERROR] Invalid flag: %s\n\n" "${flag}"
|
||||
help
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
file="${1}"
|
||||
|
||||
if [[ -z ${file} || ! -f "${file}" ]]; then
|
||||
printf '[ERROR] Please provide an image file!\n\n'
|
||||
help
|
||||
fi
|
||||
|
||||
hex="${hex//#/}"
|
||||
hex_alt="${hex_alt//#/}"
|
||||
|
||||
printf "primary color: #%s\nsecondary color: #%s\nfile: %s\n" "${hex}" "${hex_alt}" "${file}"
|
||||
|
||||
new_filename=$(basename "${file}")
|
||||
|
||||
#convert -size 1x1 "xc:#${hex}" "xc:#${hex_alt}" -append txt:- | convert "${file}" ${invert_flag} -dither "${dithering}" -remap txt:- "${new_filename}-posterized-$(date +%Y-%m-%d_%H-%M-%S).jpg"
|
||||
convert -size 1x1 "xc:#${hex}" "xc:#${hex_alt}" -append -colorspace rgb txt:- | convert "${file}" -set colorspace Gray ${invert_flag} -contrast-stretch "${contrast}%" -dither "${dithering}" -threshold "${threshold}%" -morphology EdgeIn "Diamond:${morph_level}" -remap txt:- "${new_filename}-posterized-$(date +%Y-%m-%d_%H-%M-%S).jpg"
|
||||
|
||||
#convert "${1}" -contrast-stretch 7% -set colorspace Gray -separate -average +level-colors "#111317","#d7afaf" "$(basename ${1})-recolored-$(date +%Y-%m-%d_%H-%M-%S).jpg"
|
||||
|
||||
#convert "${1}" -linear-stretch 90% -fill black -colorize 5% -set colorspace Gray -separate -average +level-colors "#111317","#d7afaf" "$(basename ${1})-recolored-$(date +%Y-%m-%d_%H-%M-%S).jpg"
|
||||
#convert "${1}" -contrast-stretch 5% -fill black -colorize 5% -set colorspace Gray -separate -average +level-colors "#111317","#d7afaf" "$(basename ${1})-recolored-$(date +%Y-%m-%d_%H-%M-%S).jpg"
|
||||
|
||||
#convert "${1}" -contrast-stretch 25% -fill black -colorize 25% -set colorspace Gray -separate -average +level-colors "#111317","#d7afaf" "$(basename ${1})-recolored-$(date +%Y-%m-%d_%H-%M-%S).jpg"
|
||||
#convert "${1}" -contrast-stretch 100% -fill black -colorize 25% -set colorspace Gray -separate -average +level-colors "#111317","#d7afaf" "$(basename ${1})-recolored-$(date +%Y-%m-%d_%H-%M-%S).jpg"
|
||||
Loading…
Add table
Reference in a new issue