Skip to content

Instantly share code, notes, and snippets.

@fmnxl
Created June 12, 2020 10:49
Show Gist options
  • Save fmnxl/da848cc575ae7306407d9dfe912426f9 to your computer and use it in GitHub Desktop.
Save fmnxl/da848cc575ae7306407d9dfe912426f9 to your computer and use it in GitHub Desktop.
Generate duotone image using ImageMagick
#!/bin/sh
# A value between 0-1.0
strength=0.6
white="#e8a2c9"
black="#813722"
# https://unix.stackexchange.com/questions/40786/how-to-do-integer-float-calculations-in-bash-or-other-languages-frameworks/40897#40897
calc() { awk "BEGIN{print $*}"; }
strength_inv=$(calc 1-$strength)
magick input.jpg \
-fx "$strength * (luminance * #e8a2c9 + (1-luminance) * #813722) + $strength_inv * u" \
result.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment