Sha256: 34b49ab241fee96eef09c7d51efb755228bed3aedd61c94878f08e236838e41e

Contents?: true

Size: 1.06 KB

Versions: 13

Compression:

Stored size: 1.06 KB

Contents

#!/usr/bin/env ruby -w
require 'rmagick'

# Demonstrate the Image#transparent method.
# Change all black pixels in the image to transparent.

before = Magick::Image.new(200,200) do
  self.background_color = 'black'
end

circle = Magick::Draw.new
circle.fill('transparent')
circle.stroke('white')
circle.stroke_width(8)
circle.circle(100,100,180,100)
circle.fill('transparent')
circle.stroke('white')
circle.circle( 60,100, 40,100)
circle.circle(140,100,120,100)
circle.circle(100, 60,100, 40)
circle.circle(100,140,100,120)
circle.draw(before)

before.compression = Magick::LZWCompression
before.write('transparent_before.gif')

before.fuzz = 100
after = before.transparent('black', Magick::TransparentOpacity)

# Different way of reading an image - start with an imagelist.
# Use the plasma image as a background so we can see that
# the black pixels have been made transparent.
bg = Magick::ImageList.new
bg.read('plasma:purple-gold') { self.size = '200x200' }

after = bg.composite(after, Magick::CenterGravity, Magick::OverCompositeOp)
after.write('transparent_after.gif')
exit

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
rmagick-windows-2.16.5 doc/ex/transparent.rb
rmagick-windows-2.16.4 doc/ex/transparent.rb
rmagick-windows-2.16.3 doc/ex/transparent.rb
rmagick-windows-2.16.2 doc/ex/transparent.rb
rmagick-windows-2.16.1 doc/ex/transparent.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/rmagick-2.16.0/doc/ex/transparent.rb
rmagick-2.16.0 doc/ex/transparent.rb
rmagick-2.15.4 doc/ex/transparent.rb
rmagick-2.15.3 doc/ex/transparent.rb
rmagick-2.15.2 doc/ex/transparent.rb
rmagick-2.15.1 doc/ex/transparent.rb
rmagick-2.15.0 doc/ex/transparent.rb
rmagick-2.14.0 doc/ex/transparent.rb