Sha256: dd8f05162dda76c3688c3dfe1b490b6865d8220fa66ea77d6dd367fe6bcffb30

Contents?: true

Size: 975 Bytes

Versions: 4

Compression:

Stored size: 975 Bytes

Contents

#!/usr/bin/env ruby -w

require 'rmagick'

img = Magick::Image.new(200, 200)
img.compression = Magick::LZWCompression

bg = Magick::Image.read('plasma:fractal') { self.size = '200x200' }
bg[0].alpha(Magick::DeactivateAlphaChannel)

gc = Magick::Draw.new
gc.stroke_width(2)
gc.stroke('black')
gc.fill('white')
gc.roundrectangle(0, 0, 199, 199, 8, 8)

gc.fill('black')
gc.circle(100, 45, 100, 25)
gc.circle(45, 100,  25, 100)
gc.circle(100, 155, 100, 175)
gc.circle(155, 100, 175, 100)

gc.draw(img)

img.write('matte_replace_before.gif')

# Set the border color. Set the fuzz attribute so that
# the matte fill will fill the aliased pixels around
# the edges of the black circles.
img.border_color = 'black'
img.fuzz = 10
img = img.matte_replace(100, 45)

# Composite the image over a nice bright background
# so that the transparent pixels will be obvious.
img = bg[0].composite(img, Magick::CenterGravity, Magick::OverCompositeOp)

img.write('matte_replace_after.gif')
exit

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rmagick-4.1.0.rc2 doc/ex/matte_replace.rb
rmagick-4.1.0.rc1 doc/ex/matte_replace.rb
rmagick-4.0.0 doc/ex/matte_replace.rb
rmagick-3.2.0 doc/ex/matte_replace.rb