Sha256: 42f5d1fe47826c1226d35fbff07ba64f486a73f91e8626dbb23e0a05592fb35e

Contents?: true

Size: 983 Bytes

Versions: 6

Compression:

Stored size: 983 Bytes

Contents

# Demonstrate ImageMagick's new (5.5.7-3 and later) built-in patterns.
# Create a Fill class that can be reused to fill in new Image backgrounds.

# Usage: pattern_fill.rb <name-of-pattern>
# Try 'checkerboard' or 'verticalsaw'

require 'rmagick'
include Magick

puts <<END_INFO

This example demonstrates the PATTERN: image format, which is
new in ImageMagick 5.5.7. Specify the name of any of the
supported patterns as an argument. For example, try "checkerboard".

END_INFO

class PatternFill < Magick::TextureFill
  def initialize(name = 'bricks')
    @pat_img = Magick::Image.read("pattern:#{name}").first
    super(@pat_img)
  end
end

if ARGV[0]
  pattern = ARGV[0]
else
  warn 'Defaulting to checkerboard pattern.'
  pattern = 'checkerboard'
end

# Create a sample image that is 100x bigger than the pattern.
attrs = Image.ping("pattern:#{pattern}").first

tryit = Image.new(10 * attrs.columns, 10 * attrs.rows, PatternFill.new(pattern))
tryit.write('pattern_fill.gif')
exit

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rmagick-4.1.0.rc2 examples/pattern_fill.rb
rmagick-4.1.0.rc1 examples/pattern_fill.rb
rmagick-4.0.0 examples/pattern_fill.rb
rmagick-3.2.0 examples/pattern_fill.rb
rmagick-3.1.0 examples/pattern_fill.rb
rmagick-3.0.0 examples/pattern_fill.rb