Search code examples
rubyimagemagickrmagickimage-masking

RMagick Masking - different background different result


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 ?


Solution

  • 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