Skip to content

Instantly share code, notes, and snippets.

@GuangTianLi
Last active December 22, 2020 02:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save GuangTianLi/565724378522b86b6eafeb5fcb73397f to your computer and use it in GitHub Desktop.
Save GuangTianLi/565724378522b86b6eafeb5fcb73397f to your computer and use it in GitHub Desktop.
combine
#!/usr/bin/bash
echo "processing $1 and $2"
PNG0=$1 ## png0 <----- first image should be the BLACKEST
PNG1=$2 ## png1 <----- second image should be the WHITEST
#PNG2=$3 ## png2 <----- third - todo - this could be an opaque fg with tranparent bg
bg_size=`identify -format '%wx%h' "$1"`
#echo "bg is $bg_size"
magick convert $PNG1 -resize $bg_size $PNG1
magick convert $PNG0 -channel RGBA -matte -colorspace gray -normalize -ordered-dither o8x8 gray_$PNG0
magick convert $PNG1 -channel RGBA -matte -colorspace gray -normalize -ordered-dither o8x8 gray_$PNG1
# set transparencies
magick convert gray_$PNG0 -fuzz 20% -transparent white t_$PNG0
magick convert gray_$PNG1 -fuzz 20% -transparent black t_$PNG1
# set white to transparency
magick composite -dissolve 30x30 -gravity South "t_$PNG1" "t_$PNG0" -alpha Set combined.png
rm $PNG0 $PNG1 gray_$PNG0 gray_$PNG1 t_$PNG0 t_$PNG1
@GuangTianLi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment