Sha256: fb3e875be8c9917fc37874a9def1df6cee74e95457116d7d11541a05ff183ba4

Contents?: true

Size: 1.21 KB

Versions: 20

Compression:

Stored size: 1.21 KB

Contents

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

require 'RMagick'

points = [145, 65, 174,151, 264,151, 192,205,
          218,291, 145,240,  72,291,  98,205,
           26,151, 116,151]

pr = Magick::Draw.new

# Define a clip-path.
# The name of the clip-path is "example"
pr.define_clip_path('example') {
    pr.polygon(*points)
    }

# Enable the clip-path
pr.clip_path('example')

# Composite the Flower Hat image over
# the background using the clip-path
girl = Magick::ImageList.new
girl.read("images/Flower_Hat.jpg")

cols = rows = nil

# Our final image is about 290 pixels wide, so here
# we widen our picture to fit. The change_geometry
# method will adjust the height proportionately.

girl.change_geometry("290") do |c,r|
    pr.composite(0,0, c, r, girl)
    cols = c
    rows = r
end

# Create a canvas to draw on, a bit bigger than the star.
canvas = Magick::Image.new(cols, rows)

star = Magick::Draw.new
star.stroke('black')
star.fill('black')
star.polygon(*points)
star.draw(canvas)
canvas = canvas.blur_image(0, 20)

# Draw the star over the background
pr.draw(canvas)

# Crop away all the solid white border pixels.
crop = canvas.bounding_box
canvas.crop!(crop.x, crop.y, crop.width, crop.height)

canvas.write("clip_path.gif")

exit

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rmagick-1.10.0 doc/ex/clip_path.rb
rmagick-1.10.1 doc/ex/clip_path.rb
rmagick-1.13.0 doc/ex/clip_path.rb
rmagick-1.11.0 doc/ex/clip_path.rb
rmagick-1.11.1 doc/ex/clip_path.rb
rmagick-1.12.0 doc/ex/clip_path.rb
rmagick-1.14.0 doc/ex/clip_path.rb
rmagick-1.14.1 doc/ex/clip_path.rb
rmagick-1.8.1 doc/ex/clip_path.rb
rmagick-1.7.1 doc/ex/clip_path.rb
rmagick-1.7.2 doc/ex/clip_path.rb
rmagick-1.7.3 doc/ex/clip_path.rb
rmagick-1.7.4 doc/ex/clip_path.rb
rmagick-1.8.0 doc/ex/clip_path.rb
rmagick-1.8.2 doc/ex/clip_path.rb
rmagick-1.8.3 doc/ex/clip_path.rb
rmagick-1.9.0 doc/ex/clip_path.rb
rmagick-1.9.1 doc/ex/clip_path.rb
rmagick-1.9.2 doc/ex/clip_path.rb
rmagick-1.9.3 doc/ex/clip_path.rb