<- Prev | Contents | Next ->

# Fill classes

### Table Of Contents

- class HatchFill
- class GradientFill
- class TextureFill

#### What is a Fill class?

The Image#new and ImageList#new_image methods accept a fill object as an optional third argument. A fill object is an instance of a Fill class. Fill classes are designed to support custom background fills. Each Fill class defines only two methods, initialize and fill. The initialize method is called from the application to create an instance of the fill class. It accepts any arguments and does whatever is necessary to create the fill. The fill method is called from the initialize method of the new image object, after the image is completely initialized. The fill method gets the image as its only argument and sends whatever methods are necessary to the image to fill the image's background.

RMagick supplies three Fill classes, HatchFill, GradientFill, and TextureFill. These classes are explained below. The HatchFill class is intended as an example of how to write a Fill class and is written in pure Ruby. You can read it in RMagick.rb.

class HatchFill

### class methods

new | Magick::HatchFill.new(background_color, hatch_color='white', dist=10) -> aHatchFill
Description | Creates a cross-hatched fill.

Arguments

background_color
  The image background color.
hatch_color
  The color of the cross-hatch lines.
dist
  The distance between cross-hatch lines, in pixels.

Returns | A new HatchFill object
Example |
class GradientFill

### class methods

new | Magick::GradientFill.new(x1, y1, x2, y2, start_color, end_color) -> aGradientFill

Description

Creates a gradient fill. The `x1, y1`, and `x2, y2` arguments describe either a line or a point. If x1 != x2 or y1 != y2, then the arguments describe the starting line for the gradient. The gradient will start with `start_color` at the starting line and gradually transform to `end_color` as the distance increases from the starting line.

If x1 == x2 and y1 == y2, the gradient radiates from the specified point, gradually transforming from `start_color` to `end_color`.

The line or point does not have to lie within the image bounds.

Arguments

x1, y1
  One of the starting line end-points.
x2, y2
  The other end-point on the starting line.
start_color
  The color at the starting line.
end_color
  The color to which the gradient transforms.

Returns | A new GradientFill object
Example |
class TextureFill

### class methods

new | Magick::TextureFill.new(texture_image) -> aTextureFill
Description | Creates a texture fill. The texture is tiled to fill the image.
Arguments | The texture to be used as the background. May be an image or imagelist. If `texture` is an imagelist, uses the current image.
Returns | A new TextureFill object
Example |

<- Prev | Contents | Next ->