File: pattern_fill.rb

package info (click to toggle)
librmagick-ruby 1.13.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,700 kB
  • ctags: 1,466
  • sloc: ansic: 13,688; ruby: 8,953; makefile: 40; sh: 32
file content (38 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# 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
    $stderr.puts "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.display
exit