Sha256: 57b11cdc16b368bea2113f767b041c627147ff568e5e2996bb63a8a5bec8707b

Contents?: true

Size: 1.21 KB

Versions: 24

Compression:

Stored size: 1.21 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.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

24 entries across 24 versions & 2 rubygems

Version Path
rmagick-2.13.3 doc/ex/mask.rb
rmagick-2.13.3.rc1 doc/ex/mask.rb
rmagick-2.13.2 doc/ex/mask.rb
rdp-rmagick-0.0.0 doc/ex/mask.rb
rmagick-2.13.1 doc/ex/mask.rb
rmagick-2.12.2 doc/ex/mask.rb
rmagick-2.12.1 doc/ex/mask.rb
rmagick-2.12.0 doc/ex/mask.rb
rmagick-2.11.1 doc/ex/mask.rb
rmagick-2.10.0 doc/ex/mask.rb
rmagick-2.11.0 doc/ex/mask.rb
rmagick-2.3.0 doc/ex/mask.rb
rmagick-2.6.0 doc/ex/mask.rb
rmagick-2.4.0 doc/ex/mask.rb
rmagick-2.5.0 doc/ex/mask.rb
rmagick-2.5.1 doc/ex/mask.rb
rmagick-2.5.2 doc/ex/mask.rb
rmagick-2.7.0 doc/ex/mask.rb
rmagick-2.7.1 doc/ex/mask.rb
rmagick-2.7.2 doc/ex/mask.rb