Last active
October 9, 2019 15:17
-
-
Save RNDcpp/a6db18f7d1adf4037de058ad1f1158fb to your computer and use it in GitHub Desktop.
写真をイラスト背景風にするフィルタ.sh
This file contains 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
# USAGE conv.sh [input] [output] [width] [height] | |
# widthとheightは大きめ(2000以上)の方がいい感じになる | |
# リサイズします | |
convert $1 -resize ${3}x${4}! target.png | |
# 油彩フィルタを重ねがけします | |
convert target.png -modulate 160,180 -colors 400 -paint 2 -paint 2 -paint 2 -blur 3x4 paint.png | |
# ぼかした後の画像からエッジ画像を取り出します | |
convert paint.png -type GrayScale -blur 2x4 -edge 1 -colors 50 -threshold 10% -negate -fill "#111144" -opaque black -blur 2x2 edge.png | |
# ぼかす前の画像からエッジ画像を取り出します | |
convert target.png -type GrayScale -blur 2x4 -edge 2 -colors 50 -threshold 10% -negate -fill "#111144" -opaque black -blur 2x2 edge2.png | |
# 影の部分だけ取り出します | |
convert target.png -type GrayScale -fuzz 50% -threshold 50% -fill "#C7E5FF" -opaque black -blur 2x2 contrast.png | |
# 影の部分を青色のグラデーションで塗りつぶします | |
convert -size ${3}x${4} gradient:white-#6A9DCA gradient.png | |
# ぼかした画像、エッジ画像、影の画像を合成するために透明度を調整します | |
convert contrast.png -channel alpha -fx "0.4" contrast.png | |
convert edge.png -channel alpha -fx "0.8" edge.png | |
convert edge2.png -channel alpha -fx "0.4" edge2.png | |
convert gradient.png -channel alpha -fx "0.4" gradient.png | |
# それぞれの画像を重ねます | |
convert paint.png contrast.png -compose multiply -composite tmp.png | |
# 影画像はオーバーレイで合成します | |
convert tmp.png gradient.png -compose overlay -composite tmp.png | |
convert tmp.png edge2.png -compose multiply -composite tmp.png | |
convert tmp.png edge.png -compose multiply -composite tmp.png | |
#結果を出力します | |
convert tmp.png $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment