RMagick掩蔽——不同背景不同的结果 - RMagick Masking - different background different result

- 此内容更新于:2016-02-02
主题:

我有2t恤图片一样,颜色是黑色和粉色。我想混合与android的标志。黑色t恤上的结果是很好。但在粉红色的,android是明亮的图像。这是我的代码,这是结果所以我怎么能让android图像像当黑色t恤。我的代码,我应该改变?

原文:

I have 2 t-shirt images, the color are black and pink. i want to blend it with android logo. on the black t-shirt the result was great. but on the pink one, android image is to bright.

here's my code

    tshirt = Magick::Image.read("/Volumes/Work/rmagick/cacat.png").first

    canvas = Magick::Image.new(tshirt.rows, tshirt.columns) do |c|
        c.background_color = "none"
    end

    img = Magick::Image.read("/Volumes/Work/rmagick/android_logo2.png").first
    img = img.resize_to_fit(250)

    # # contour
    contour = img.composite!(canvas, Magick::CenterGravity, Magick::InCompositeOp)
    img = Magick::Image.read("/Volumes/Work/rmagick/android_logo2.png").first
    img = img.resize_to_fit(250)

    contour = contour.composite!(img, Magick::CenterGravity, Magick::AddCompositeOp)

    tshirt = tshirt.composite!(contour, 295,250, Magick::PlusCompositeOp)

    tshirt.write('/Volumes/Work/jadi.png')

and here's the result

black

pink

so how can i make android image is like when it on the black t-shirt. which of my code that i should change ?

网友:我不会说Ruby,但尝试改变其他东西——也许有或在其名称。

(原文:I don't speak Ruby, but try changing Magick::PlusCompositeOp for something else - maybe something with Overlay or Blend in its name.)

楼主:它的好,如果你只有imagemagick命令。

(原文:its okay if you have only imagemagick commands.)

解决方案:
你可以混合模式的列表:所以,你可以看看哪一个适合您的需求:
原文:

You can get a list of the blending modes with:

identify -list compose

So, you can do this and see which one suits your needs:

#!/bin/bash
for blend in $(identify -list compose|grep -v Blur ); do 
  convert -gravity center -label "$blend" tshirt.png android.png -compose $blend -composite miff:-
done | montage - -tile 5x result.png

enter image description here