Class: Magick::Draw

### Home Classes Methods

### In Files

- lib/rmagick_internal.rb
- ext/RMagick/rmmain.c

### Parent

Object

### Methods

- #affine
- #arc
- #bezier
- #circle
- #clip_path
- #clip_rule
- #clip_units
- #color
- #decorate
- #define_clip_path
- #ellipse
- #encoding
- #fill
- #fill_color
- #fill_opacity
- #fill_pattern
- #fill_rule
- #font
- #font_family
- #font_size
- #font_stretch
- #font_style
- #font_weight
- #gravity
- #interline_spacing
- #interword_spacing
- #kerning
- #line
- #matte
- #opacity
- #path
- #pattern
- #point
- #pointsize
- #polygon
- #polyline
- #pop
- #push
- #rectangle
- #rotate
- #roundrectangle
- #scale
- #skewx
- #skewy
- #stroke
- #stroke_antialias
- #stroke_color
- #stroke_dasharray
- #stroke_dashoffset
- #stroke_linecap
- #stroke_linejoin
- #stroke_miterlimit
- #stroke_opacity
- #stroke_pattern
- #stroke_width
- #text
- #text_align
- #text_anchor
- #text_antialias
- #text_undercolor
- #translate

### Files

- Makefile

### Class/Module Index

Quicksearch

- Magick
- Magick::DestroyedImageError
- Magick::Draw
- Magick::Enum
- Magick::FatalImageMagickError
- Magick::Geometry
- Magick::GeometryValue
- Magick::GradientFill
- Magick::HatchFill
- Magick::IPTC
- Magick::IPTC::Application
- Magick::IPTC::Envelope
- Magick::IPTC::ObjectData
- Magick::IPTC::Post_ObjectData_Descriptor
- Magick::IPTC::Pre_ObjectData_Descriptor
- Magick::Image
- Magick::Image::DrawOptions
- Magick::Image::Info
- Magick::Image::PolaroidOptions
- Magick::Image::View
- Magick::Image::View::Pixels
- Magick::Image::View::Rows
- Magick::ImageList
- Magick::ImageList::Montage
- Magick::ImageMagickError
- Magick::OptionalMethodArguments
- Magick::Pixel
- Magick::RVG
- Magick::RVG::Circle
- Magick::RVG::ClipPath
- Magick::RVG::Describable
- Magick::RVG::Duplicatable
- Magick::RVG::Ellipse
- Magick::RVG::Embellishable
- Magick::RVG::Group
- Magick::RVG::Image
- Magick::RVG::ImageConstructors
- Magick::RVG::Line
- Magick::RVG::Path
- Magick::RVG::PathData
- Magick::RVG::Pattern
- Magick::RVG::PolyShape
- Magick::RVG::Polygon
- Magick::RVG::Polyline
- Magick::RVG::PreserveAspectRatio
- Magick::RVG::Rect
- Magick::RVG::ShapeConstructors
- Magick::RVG::Stretchable
- Magick::RVG::StructureConstructors
- Magick::RVG::Stylable
- Magick::RVG::Text
- Magick::RVG::TextBase
- Magick::RVG::TextConstructors
- Magick::RVG::Transformable
- Magick::RVG::Use
- Magick::RVG::UseConstructors
- Magick::RVG::Utility
- Magick::RVG::Utility::DefaultTextStrategy
- Magick::RVG::Utility::GraphicContext
- Magick::RVG::Utility::LRTextStrategy
- Magick::RVG::Utility::RLTextStrategy
- Magick::RVG::Utility::TBTextStrategy
- Magick::RVG::Utility::TextAttributes
- Magick::RVG::Utility::TextStrategy
- Magick::SolidFill
- Magick::TextureFill
- Object

No matching classes.

# Magick::Draw

### Constants

ALIGN_TYPE_NAMES

  Thse hashes are used to map Magick constant values to the strings used in the primitives.

ANCHOR_TYPE_NAMES
DECORATION_TYPE_NAMES
FONT_WEIGHT_NAMES
GRAVITY_NAMES
PAINT_METHOD_NAMES
STRETCH_TYPE_NAMES
STYLE_TYPE_NAMES

### Public Instance Methods

affine(sx, rx, ry, sy, tx, ty) click to toggle source

Apply coordinate transformations to support scaling (s), rotation (r), and translation (t). Angles are specified in radians.

    # File lib/rmagick_internal.rb, line 220
    def affine(sx, rx, ry, sy, tx, ty)
        primitive "affine " + sprintf("%g,%g,%g,%g,%g,%g", sx, rx, ry, sy, tx, ty)
    end

arc(startX, startY, endX, endY, startDegrees, endDegrees) click to toggle source

Draw an arc.

    # File lib/rmagick_internal.rb, line 225
    def arc(startX, startY, endX, endY, startDegrees, endDegrees)
        primitive "arc " + sprintf("%g,%g %g,%g %g,%g",
                    startX, startY, endX, endY, startDegrees, endDegrees)
    end

bezier(*points) click to toggle source

Draw a bezier curve.

    # File lib/rmagick_internal.rb, line 231
    def bezier(*points)
        if points.length == 0
            Kernel.raise ArgumentError, "no points specified"
        elsif points.length % 2 != 0
            Kernel.raise ArgumentError, "odd number of arguments specified"
        end
        primitive "bezier " + points.join(',')
    end

circle(originX, originY, perimX, perimY) click to toggle source

Draw a circle

    # File lib/rmagick_internal.rb, line 241
    def circle(originX, originY, perimX, perimY)
        primitive "circle " + sprintf("%g,%g %g,%g", originX, originY, perimX, perimY)
    end

clip_path(name) click to toggle source

Invoke a clip-path defined by def_clip_path.

    # File lib/rmagick_internal.rb, line 246
    def clip_path(name)
        primitive "clip-path #{name}"
    end

clip_rule(rule) click to toggle source

Define the clipping rule.

    # File lib/rmagick_internal.rb, line 251
    def clip_rule(rule)
        if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
            Kernel.raise ArgumentError, "Unknown clipping rule #{rule}"
        end
        primitive "clip-rule #{rule}"
    end

clip_units(unit) click to toggle source

Define the clip units

    # File lib/rmagick_internal.rb, line 259
    def clip_units(unit)
        if ( not ["userspace", "userspaceonuse", "objectboundingbox"].include?(unit.downcase) )
            Kernel.raise ArgumentError, "Unknown clip unit #{unit}"
        end
        primitive "clip-units #{unit}"
    end

color(x, y, method) click to toggle source

Set color in image according to specified colorization rule. Rule is one of point, replace, floodfill, filltoborder,reset

    # File lib/rmagick_internal.rb, line 268
    def color(x, y, method)
        if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
            Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}"
        end
        primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}"
    end

decorate(decoration) click to toggle source

Specify EITHER the text decoration (none, underline, overline, line-through) OR the text solid background color (any color name or spec)

    # File lib/rmagick_internal.rb, line 277
    def decorate(decoration)
        if ( DECORATION_TYPE_NAMES.has_key?(decoration.to_i) )
            primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}"
        else
            primitive "decorate #{enquote(decoration)}"
        end
    end

define_clip_path(name) click to toggle source

Define a clip-path. A clip-path is a sequence of primitives bracketed by the "push clip-path <name>" and "pop clip-path" primitives. Upon advice from the IM guys, we also bracket the clip-path primitives with "push(pop) defs" and "push (pop) graphic-context".

    # File lib/rmagick_internal.rb, line 290
    def define_clip_path(name)
        begin
            push('defs')
            push('clip-path', name)
            push('graphic-context')
            yield
        ensure
            pop('graphic-context')
            pop('clip-path')
            pop('defs')
        end
    end

ellipse(originX, originY, width, height, arcStart, arcEnd) click to toggle source

Draw an ellipse

    # File lib/rmagick_internal.rb, line 304
    def ellipse(originX, originY, width, height, arcStart, arcEnd)
        primitive "ellipse " + sprintf("%g,%g %g,%g %g,%g",
                        originX, originY, width, height, arcStart, arcEnd)
    end

encoding(encoding) click to toggle source

Let anything through, but the only defined argument is "UTF-8". All others are apparently ignored.

    # File lib/rmagick_internal.rb, line 311
    def encoding(encoding)
        primitive "encoding #{encoding}"
    end

fill(colorspec) click to toggle source

Specify object fill, a color name or pattern name

    # File lib/rmagick_internal.rb, line 316
    def fill(colorspec)
        primitive "fill #{enquote(colorspec)}"
    end

Also aliased as: fill_color, fill_pattern
fill_color(colorspec) click to toggle source
Alias for: fill
fill_opacity(opacity) click to toggle source

Specify fill opacity (use "xx%" to indicate percentage)

    # File lib/rmagick_internal.rb, line 323
    def fill_opacity(opacity)
        primitive "fill-opacity #{opacity}"
    end

fill_pattern(colorspec) click to toggle source
Alias for: fill
fill_rule(rule) click to toggle source

    # File lib/rmagick_internal.rb, line 327
    def fill_rule(rule)
        if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
            Kernel.raise ArgumentError, "Unknown fill rule #{rule}"
        end
        primitive "fill-rule #{rule}"
    end

font(name) click to toggle source

Specify text drawing font

    # File lib/rmagick_internal.rb, line 335
    def font(name)
        primitive "font \'#{name}\'"
    end

font_family(name) click to toggle source

    # File lib/rmagick_internal.rb, line 339
    def font_family(name)
        primitive "font-family \'#{name}\'"
    end

font_size(points) click to toggle source
Alias for: pointsize
font_stretch(stretch) click to toggle source

    # File lib/rmagick_internal.rb, line 343
    def font_stretch(stretch)
        if ( not STRETCH_TYPE_NAMES.has_key?(stretch.to_i) )
            Kernel.raise ArgumentError, "Unknown stretch type"
        end
        primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}"
    end

font_style(style) click to toggle source

    # File lib/rmagick_internal.rb, line 350
    def font_style(style)
        if ( not STYLE_TYPE_NAMES.has_key?(style.to_i) )
            Kernel.raise ArgumentError, "Unknown style type"
        end
        primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}"
    end

font_weight(weight) click to toggle source

The font weight argument can be either a font weight constant or [100,200,...,900]

    # File lib/rmagick_internal.rb, line 359
    def font_weight(weight)
        if ( FONT_WEIGHT_NAMES.has_key?(weight.to_i) )
            primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}"
        else
            primitive "font-weight #{weight}"
        end
    end

gravity(grav) click to toggle source

Specify the text positioning gravity, one of: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast

    # File lib/rmagick_internal.rb, line 369
    def gravity(grav)
        if ( not GRAVITY_NAMES.has_key?(grav.to_i) )
            Kernel.raise ArgumentError, "Unknown text positioning gravity"
        end
        primitive "gravity #{GRAVITY_NAMES[grav.to_i]}"
    end

interline_spacing(space) click to toggle source

IM 6.5.5-8 and later

    # File lib/rmagick_internal.rb, line 377
    def interline_spacing(space)
        begin
            Float(space)
        rescue ArgumentError
            Kernel.raise ArgumentError, "invalid value for interline_spacing"
        rescue TypeError
            Kernel.raise TypeError, "can't convert #{space.class} into Float"
        end
        primitive "interline-spacing #{space}"
    end

interword_spacing(space) click to toggle source

IM 6.4.8-3 and later

    # File lib/rmagick_internal.rb, line 389
    def interword_spacing(space)
        begin
            Float(space)
        rescue ArgumentError
            Kernel.raise ArgumentError, "invalid value for interword_spacing"
        rescue TypeError
            Kernel.raise TypeError, "can't convert #{space.class} into Float"
        end
        primitive "interword-spacing #{space}"
    end

kerning(space) click to toggle source

IM 6.4.8-3 and later

    # File lib/rmagick_internal.rb, line 401
    def kerning(space)
        begin
            Float(space)
        rescue ArgumentError
            Kernel.raise ArgumentError, "invalid value for kerning"
        rescue TypeError
            Kernel.raise TypeError, "can't convert #{space.class} into Float"
        end
        primitive "kerning #{space}"
    end

line(startX, startY, endX, endY) click to toggle source

Draw a line

    # File lib/rmagick_internal.rb, line 413
    def line(startX, startY, endX, endY)
        primitive "line " + sprintf("%g,%g %g,%g", startX, startY, endX, endY)
    end

matte(x, y, method) click to toggle source

Set matte (make transparent) in image according to the specified colorization rule

    # File lib/rmagick_internal.rb, line 419
    def matte(x, y, method)
        if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
            Kernel.raise ArgumentError, "Unknown paint method"
        end
        primitive "matte #{x},#{y} #{PAINT_METHOD_NAMES[method.to_i]}"
    end

opacity(opacity) click to toggle source

Specify drawing fill and stroke opacities. If the value is a string ending with a %, the number will be multiplied by 0.01.

    # File lib/rmagick_internal.rb, line 428
    def opacity(opacity)
        if (Numeric === opacity)
            if (opacity < 0 || opacity > 1.0)
                Kernel.raise ArgumentError, "opacity must be >= 0 and <= 1.0"
            end
        end
        primitive "opacity #{opacity}"
    end

path(cmds) click to toggle source

Draw using SVG-compatible path drawing commands. Note that the primitive requires that the commands be surrounded by quotes or apostrophes. Here we simply use apostrophes.

    # File lib/rmagick_internal.rb, line 440
    def path(cmds)
        primitive "path '" + cmds + "'"
    end

pattern(name, x, y, width, height) click to toggle source

Define a pattern. In the block, call primitive methods to draw the pattern. Reference the pattern by using its name as the argument to the 'fill' or 'stroke' methods

    # File lib/rmagick_internal.rb, line 447
    def pattern(name, x, y, width, height)
        begin
            push('defs')
            push("pattern #{name} #{x} #{y} #{width} #{height}")
            push('graphic-context')
            yield
        ensure
            pop('graphic-context')
            pop('pattern')
            pop('defs')
        end
    end

point(x, y) click to toggle source

Set point to fill color.

    # File lib/rmagick_internal.rb, line 461
    def point(x, y)
        primitive "point #{x},#{y}"
    end

pointsize(points) click to toggle source

Specify the font size in points. Yes, the primitive is "font-size" but in other places this value is called the "pointsize". Give it both names.

    # File lib/rmagick_internal.rb, line 467
    def pointsize(points)
        primitive "font-size #{points}"
    end

Also aliased as: font_size
polygon(*points) click to toggle source

Draw a polygon

    # File lib/rmagick_internal.rb, line 473
    def polygon(*points)
        if points.length == 0
            Kernel.raise ArgumentError, "no points specified"
        elsif points.length % 2 != 0
            Kernel.raise ArgumentError, "odd number of points specified"
        end
        primitive "polygon " + points.join(',')
    end

polyline(*points) click to toggle source

Draw a polyline

    # File lib/rmagick_internal.rb, line 483
    def polyline(*points)
        if points.length == 0
            Kernel.raise ArgumentError, "no points specified"
        elsif points.length % 2 != 0
            Kernel.raise ArgumentError, "odd number of points specified"
        end
        primitive "polyline " + points.join(',')
    end

pop(*what) click to toggle source

Return to the previously-saved set of whatever pop('graphic-context') (the default if no arguments) pop('defs') pop('gradient') pop('pattern')

    # File lib/rmagick_internal.rb, line 498
    def pop(*what)
        if what.length == 0
            primitive "pop graphic-context"
        else
            # to_s allows a Symbol to be used instead of a String
            primitive "pop " + what.map {|w| w.to_s}.join(' ')
        end
    end

push(*what) click to toggle source

Push the current set of drawing options. Also you can use push('graphic-context') (the default if no arguments) push('defs') push('gradient') push('pattern')

    # File lib/rmagick_internal.rb, line 512
    def push(*what)
        if what.length == 0
            primitive "push graphic-context"
        else
            # to_s allows a Symbol to be used instead of a String
            primitive "push " + what.map {|w| w.to_s}.join(' ')
        end
    end

rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y) click to toggle source

Draw a rectangle

    # File lib/rmagick_internal.rb, line 522
    def rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
        primitive "rectangle " + sprintf("%g,%g %g,%g",
                upper_left_x, upper_left_y, lower_right_x, lower_right_y)
    end

rotate(angle) click to toggle source

Specify coordinate space rotation. "angle" is measured in degrees

    # File lib/rmagick_internal.rb, line 528
    def rotate(angle)
        primitive "rotate #{angle}"
    end

roundrectangle(center_x, center_y, width, height, corner_width, corner_height) click to toggle source

Draw a rectangle with rounded corners

    # File lib/rmagick_internal.rb, line 533
    def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)
        primitive "roundrectangle " + sprintf("%g,%g,%g,%g,%g,%g",
            center_x, center_y, width, height, corner_width, corner_height)
    end

scale(x, y) click to toggle source

Specify scaling to be applied to coordinate space on subsequent drawing commands.

    # File lib/rmagick_internal.rb, line 539
    def scale(x, y)
        primitive "scale #{x},#{y}"
    end

skewx(angle) click to toggle source

    # File lib/rmagick_internal.rb, line 543
    def skewx(angle)
        primitive "skewX #{angle}"
    end

skewy(angle) click to toggle source

    # File lib/rmagick_internal.rb, line 547
    def skewy(angle)
        primitive "skewY #{angle}"
    end

stroke(colorspec) click to toggle source

Specify the object stroke, a color name or pattern name.

    # File lib/rmagick_internal.rb, line 552
    def stroke(colorspec)
        primitive "stroke #{enquote(colorspec)}"
    end

Also aliased as: stroke_color, stroke_pattern
stroke_antialias(bool) click to toggle source

Specify if stroke should be antialiased or not

    # File lib/rmagick_internal.rb, line 559
    def stroke_antialias(bool)
        bool = bool ? '1' : '0'
        primitive "stroke-antialias #{bool}"
    end

stroke_color(colorspec) click to toggle source
Alias for: stroke
stroke_dasharray(*list) click to toggle source

Specify a stroke dash pattern

    # File lib/rmagick_internal.rb, line 565
    def stroke_dasharray(*list)
        if list.length == 0
            primitive "stroke-dasharray none"
        else
            list.each { |x|
                if x <= 0 then
                    Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)"
                end
            }
            primitive "stroke-dasharray #{list.join(',')}"
        end
    end

stroke_dashoffset(value=0) click to toggle source

Specify the initial offset in the dash pattern

    # File lib/rmagick_internal.rb, line 579
    def stroke_dashoffset(value=0)
        primitive "stroke-dashoffset #{value}"
    end

stroke_linecap(value) click to toggle source

    # File lib/rmagick_internal.rb, line 583
    def stroke_linecap(value)
        if ( not ["butt", "round", "square"].include?(value.downcase) )
            Kernel.raise ArgumentError, "Unknown linecap type: #{value}"
        end
        primitive "stroke-linecap #{value}"
    end

stroke_linejoin(value) click to toggle source

    # File lib/rmagick_internal.rb, line 590
    def stroke_linejoin(value)
        if ( not ["round", "miter", "bevel"].include?(value.downcase) )
            Kernel.raise ArgumentError, "Unknown linejoin type: #{value}"
        end
        primitive "stroke-linejoin #{value}"
    end

stroke_miterlimit(value) click to toggle source

    # File lib/rmagick_internal.rb, line 597
    def stroke_miterlimit(value)
        if (value < 1)
            Kernel.raise ArgumentError, "miterlimit must be >= 1"
        end
        primitive "stroke-miterlimit #{value}"
    end

stroke_opacity(value) click to toggle source

Specify opacity of stroke drawing color

    (use "xx%" to indicate percentage)

    # File lib/rmagick_internal.rb, line 606
    def stroke_opacity(value)
        primitive "stroke-opacity #{value}"
    end

stroke_pattern(colorspec) click to toggle source
Alias for: stroke
stroke_width(pixels) click to toggle source

Specify stroke (outline) width in pixels.

    # File lib/rmagick_internal.rb, line 611
    def stroke_width(pixels)
        primitive "stroke-width #{pixels}"
    end

text(x, y, text) click to toggle source

Draw text at position x,y. Add quotes to text that is not already quoted.

    # File lib/rmagick_internal.rb, line 616
    def text(x, y, text)
        if text.to_s.empty?
            Kernel.raise ArgumentError, "missing text argument"
        end
        if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
            ; # text already quoted
        elsif !text['\']
            text = '\'+text+'\'
        elsif !text['"']
            text = '"'+text+'"'
        elsif !(text['{'] || text['}'])
            text = '{'+text+'}'
        else
            # escape existing braces, surround with braces
            text = '{' +  text.gsub(/[}]/) { |b| '\' + b } + '}'
        end
        primitive "text #{x},#{y} #{text}"
    end

text_align(alignment) click to toggle source

Specify text alignment relative to a given point

    # File lib/rmagick_internal.rb, line 636
    def text_align(alignment)
        if ( not ALIGN_TYPE_NAMES.has_key?(alignment.to_i) )
            Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}"
        end
        primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
    end

text_anchor(anchor) click to toggle source

SVG-compatible version of text_align

    # File lib/rmagick_internal.rb, line 644
    def text_anchor(anchor)
        if ( not ANCHOR_TYPE_NAMES.has_key?(anchor.to_i) )
            Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}"
        end
        primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}"
    end

text_antialias(boolean) click to toggle source

Specify if rendered text is to be antialiased.

    # File lib/rmagick_internal.rb, line 652
    def text_antialias(boolean)
        boolean = boolean ? '1' : '0'
        primitive "text-antialias #{boolean}"
    end

text_undercolor(color) click to toggle source

Specify color underneath text

    # File lib/rmagick_internal.rb, line 658
    def text_undercolor(color)
        primitive "text-undercolor #{enquote(color)}"
    end

translate(x, y) click to toggle source

Specify center of coordinate space to use for subsequent drawing commands.

    # File lib/rmagick_internal.rb, line 664
    def translate(x, y)
        primitive "translate #{x},#{y}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.