Search code examples
ruby-on-railstransparentcompositeminimagick

How to get a transparent background for my logo using Minimagick composite?


Here is my code:

process :watermark   

def watermark
   second_image = MiniMagick::Image.open("https://s3.amazonaws.com/....logo.png")
   manipulate! do |img|
   result = img.composite(second_image) do |c|
     c.compose "Over"    # OverCompositeOp
     c.gravity "Southeast" 
   end
    result
   end
 end

The problem is that the second image shows up as a square or a rectangle and does not show up with a transparent background.

How do I get my logo to composite on top of the images with a transparent background?

EDIT

I tried the following code

def watermark
  def second_image
    second_image = MiniMagick::Image.open("https://s3.amazonaws.com/...logo.png") do { "white" => transparent }
    second_image.save
  end  
  manipulate! do |img|
  result = img.composite(second_image) do |c|
     c.compose "Over"    # OverCompositeOp
     c.gravity "Southeast" # copy second_image onto first_image from (20, 20)
  end
  result
  end
 end
end

which didnt work and resulted in second_image not being composited on the upload and returned only the upload.

Edit 2

My image was not actually transparent, :/


Solution

  • Have a look at this forum for your answer. http://www.imagemagick.org/discourse-server/viewtopic.php?t=20262