Class: RComposite::LayerMask

Inherits:
Layer
  • Object
show all
Defined in:
lib/rcomposite/layermask.rb

Instance Attribute Summary

Attributes inherited from Layer

#image, #offset_x, #offset_y

Instance Method Summary collapse

Methods inherited from Layer

#height, #initialize, #join_set, #layer_mask, #leave_set, #merge_down, #mode, #offset, #opacity, #rotate, #save_as, #width

Constructor Details

This class inherits a constructor from RComposite::Layer

Instance Method Details

#apply(layer) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/rcomposite/layermask.rb', line 3

def apply(layer)
  # apply layer mask to layer before merging down
  fill = Magick::GradientFill.new(0,0,0,0, '#000', '#000')
  mask = Magick::Image.new(layer.width, layer.height, fill)
  mask.composite!(@image, @offset_x, @offset_y, Magick::OverCompositeOp)
  
  alpha_channel = layer.image.channel(Magick::AlphaChannel).negate
  alpha_channel.composite!(mask, 0, 0, Magick::MultiplyCompositeOp)
  alpha_channel.matte = false
  layer.image.composite!(alpha_channel, 0, 0, Magick::CopyOpacityCompositeOp)
end