Sha256: c94b69622b087c70f7571de9bef5d178c7ee97d580428ebfcc1e3a0e5d51c07f

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

#! /usr/local/bin/ruby -w

require 'RMagick'

# This example demonstrates the mask attribute. The mask image must
# be the same size as the image being masked. Since this mask image does
# not have an alpha channel, the intensity of each pixel is used to define the
# mask. White pixels are more intense than black pixels, so the area of the
# image masked by white pixels will remain unchanged, while the area of the
# image masked by black pixels is affected by any transformations.

# In this example the mask is simply the words "Flower Hat" in black text
# positioned near the bottom of the white clip mask image.

img = Magick::Image.read("images/Flower_Hat.jpg").first
q = Magick::Image.new(img.columns, img.rows)

gc = Magick::Draw.new
gc.annotate(q, 0, 0, 0, 0, "Flower Hat") do
    gc.gravity = Magick::SouthGravity
    gc.font_family = "Helvetica"
    gc.pointsize = 36
    gc.font_weight = Magick::BoldWeight
end

# Set the matte attribute to false, indicating the absence of an alpha channel
# in the mask image. Assign the mask image to the mask= attribute of the image 
# being masked.

q.matte = false
img.mask = q

# Use the #level method to darken the image under the black part of the mask.

img = img.level(0, Magick::MaxRGB, 0.50)
img.write('mask.jpg')

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rmagick-1.15.0 doc/ex/mask.rb
rmagick-1.14.0 doc/ex/mask.rb
rmagick-1.14.1 doc/ex/mask.rb
rmagick-1.15.1 doc/ex/mask.rb
rmagick-1.15.2 doc/ex/mask.rb
rmagick-1.15.3 doc/ex/mask.rb
rmagick-1.15.4 doc/ex/mask.rb
rmagick-1.15.7 doc/ex/mask.rb
rmagick-1.15.8 doc/ex/mask.rb
rmagick-1.15.6 doc/ex/mask.rb
rmagick-1.15.5 doc/ex/mask.rb
rmagick-1.15.9 doc/ex/mask.rb