3

I'm trying to rotate an image before composing it ontop of another, using RMagick with ruby. I can compose the overlaid image but when I try to rotate the image parts of the background are removed, like so...

enter image description here

Im not sure which CompositeOperator I should be using, or if this is the wrong approach all together?

image = Magick::Image.read("img.jpg").first         
overlay = Magick::Image.read("./overlay.png").first
overlay.rotate!(9)
image.composite!(overlay, 100, 50, Magick::OverCompositeOp)
image.to_blob
michael
  • 1,202
  • 5
  • 23
  • 34

2 Answers2

3

Before rotating set your background to none:

overlay.background_color = "none"

Other possible methods to use after the rotation:

img.transparent_chroma(low, high, opacity=TransparentOpacity, invert=false)
img.transparent(color, opacity=TransparentOpacity)

so in your case:

overlay.transparent!("white")
Sean Vikoren
  • 1,084
  • 1
  • 13
  • 24