require 'RMagick'
include Magick
# 画像を2値化して切り取り
img1 = ImageList.new("sample5.jpg")
img2 = img1.threshold(QuantumRange*0.84)
img3 = img2.transparent("white");
img4 = ImageList.new("sample5.jpg")
img4.alpha = ActivateAlphaChannel
img5 = img4.composite(img3, 0, 0, DstInCompositeOp);
# 影付け
img5.background_color = "black"
img6 = img5.shadow(3, 3, 3, 0.4)
img7 = img6.composite(img5, 0, 0, OverCompositeOp);
# 白背景と合成
bg = Image.new(img7.columns, img7.rows){
self.background_color='white'
}
img8 = bg.composite(img7, 0, 0, OverCompositeOp);
img8.write("sample501a.png")
exit
元画像(sample5.jpg)

出力画像(
sample501a.png
)
動作環境
ruby1.8.6-26/RMagick-2.3.0-ImageMagick-6.4.0-2-Q8
関連項目
ImageMagickで閾値を使用して切り取った画像に影付けする
No comments:
Post a Comment