A view is a rectangle in an image. Within the view pixels
can be addressed by specifying their
coordinates. The i, j index values can identify a single pixel or
multiple pixels. Pixels can be accessed or modified
individually or collectively. Pixel channels (that
is, the red, green, blue, and opacity components) can be
accessed or modified individually or collectively. The
sync method stores modified pixels
back into the image.
Image::View.new(img, x, y, width, height) -> aView
The easiest way to use an
is to create it with the Image#view method, which provides a
block-scoped view and automatic sync'ing. You probably won't
want to create a view by calling
It is an error to specify a view that exceeds the boundaries of the image.
view[i][j] -> aPixel or anArray
Return one or more pixels in the view. If i and j are each
a single integer value, returns a single pixel. For any other
indexes, returns an array of one or more pixels. If any index
exceeds the boundaries of the view, raises
The i index identifies a set of rows in the view. The j index identifies a set of columns in the view. The pixels that are returned are the intersection of these two sets. The indexes can be:
jis omitted, all the columns are used.
lengthrows or columns starting with
startis negative, starts at the bottom row or right column of the view.
eachby returning a sequence of objects that can be converted to integers. An array with integer values or a range of integers are two examples.
# Get the 2nd pixel in the 4th row of the view. pixel = view # returns a pixel # Returns an array with only one value pixels = view[][] # Get all the pixels in the 4th row pixels = view # Use arrays to specify a non-contiguous set of rows and columns pixels = view[[1,3,5]][[2,4,6]] # Use ranges to specify a contigous set of rows and columns pixels = view[1..5][2..6]
[i][j].red -> anInteger or
[i][j].green -> anInteger or anArray
[i][j].blue -> anInteger or anArray
[i][j].opacity -> anInteger or anArray
If the indexes identify a single pixel, these methods
return the value of the red, green, blue, or opacity channel
of that pixel. If the indexes identify more than one pixel,
these methods return an array of values. See
 for a description of possible index
# Get the value of the green channel of # the top-left pixel in the view. view = Pixel(0,128,255) g = view.green # returns 128 # Get the maximum value of the red channel # for all the pixels in the top row of the view. m = view.red.max
view[i][j] = rvalue
The indexes are the same as
[i][j].red = anInteger ->
[i][j].green = anInteger ->
[i][j].blue = anInteger ->
[i][j].opacity = anInteger ->
Assigns anInteger to the red, green, blue, or opacity channel of the pixel or pixels identified by the indexes.
# Set the red channel of all the pixels in the 2nd # row of the view to MaxRGB view.red = MaxRGB # Set the green channel of the pixel at  to # half that of its left-hand neighbor. view.green = view.green * 0.5
If any of the pixels in the view have been modified, this method stores them in the image. If no pixels have been modified, this method has no effect.
true, forces the view pixels to be stored in the image even if none have been modified.
trueif the pixels were stored in the image either because the
Any modification to a pixel in the view causes the
dirty attribute to be set to
You can (although normally you don't need to) set
dirty=true to force
sync to store
the pixels in the image, or set
sync from storing the pixels.
x -> anInteger
y -> anInteger
width -> anInteger
height -> anInteger
The x, y, width, and height arguments specified when the view was created.
The Geometry class contains the same information as an ×Magick geometry string. Geometry objects are interchangable with geometry strings.
Geometry.new(width=nil, height=nil, x=nil, y=nil, flag=nil) -> aGeometry
Constructs a new
A geometry string has the general form
"WxH+x+y[!@%<>]. In a
|PercentGeometry||%||Normally the attributes are treated as pixels. Use
this flag when the
|AspectGeometry||!||Use this flag when you want to force the new image to
have exactly the size specified by the the
|LessGeometry||<||Use this flag when you want to change the size of the image only if both its width and height are smaller the values specified by those attributes. The image size is changed proportionally.|
|GreaterGeometry||>||Use this flag when you want to change the size of the image if either its width and height exceed the values specified by those attributes. The image size is changed proportionally.|
|AreaGeometry||@||This flag is useful only with a single
If any attribute is omitted the default is nil or 0.
g = Magick::Geometry.new(100,200,nil,nil,Magick::AspectGeometry)
Geometry.from_s(string) -> aGeometry
Constructs a new
Geometry object from a
geometry.to_s() -> aString
Returns the string equivalent of the
A pixel describes the smallest individually addressable part of an image. In the RBG colorspace, a pixel's color is described by its intensity in the red, green, and blue channels. Its opacity is described by its intensity in the opacity (also called alpha, or matte) channel. In the CMYK colorspace a pixel's color is described by its intensity in the cyan, magenta, yellow and black (K) channels. Intensity is a value between 0 and MaxRGB.
Usually, RMagick methods operate on entire images or on groups of pixels that have been selected by their position or color. Some methods, such as pixel_color and view, operate on individual pixels or even on the RGBA (or CMYK) components thereof.
Pixel.new(red, green, blue, opacity) -> aPixel
Constructs a pixel object from the specified red, green, blue, and opacity intensities. The intensity is a number between 0 and MaxRGB.
Pixel.from_color(color_name) -> aPixel
Constructs a new Pixel object from the color name. Raises ArgumentError if the name is unknown.
Pixel.from_HSL([hue, saturation, luminosity]) -> aPixel
Constructs a pixel object from the specified array of 3 values: hue, saturation, and luminosity.
pixel1 <=> pixel2 -> -1, 0, or 1
Returns -1, 0, or 1 depending on if pixel1 is "less than," equal, or "greater than" the pixel2.
Since there is no way to rank order pixels, and thus determine if one pixel is "greater than" or "less than" another, this method uses an arbitrary algorithm that ensures these two conditions:
-1, 0, or 1
Returns true if the argument is the same color as pixel.
pixel.intensity() -> anInteger
Returns the intensity of the pixel. The intensity is computed as 0.299*R+0.587*G+0.114*B.
Returns the color name corresponding the the pixel values. If there is no such named color in the specified color standard, returns a string in the form "#RRGGBBOO" or, if the depth is 16, "#RRRRGGGGBBBBOOOO".
to_colorto search for a color name in any of the 3 defined color standards.
Compare this method to Image#to_color, in which the matte and depth values are taken from an image.
pixel.to_HSL -> anArray
Converts the RGB representation of the pixel to hue, saturation, and luminosity values.
An array of the form
These classes are created by the Struct class and are used
to create objects used as attribute and argument values in
other RMagick classes. Like all the classes created by
Struct, these classes define both getter and setter methods
for their attributes. That is, for an attribute x
x= methods are
define additional constructors and conversion methods.
AffineMatrix.new(sx, rx, ry, sy, tx, ty) -> anAffineMatrix
Chromaticity.new(red_primary, green_primary, blue_primary, white_point) -> aChromaticity
A Chromaticity object represents chromaticity values for the Image#chromaticity attribute.
The attribute values are Primary objects.
Point.new(x, y) -> aPoint
The value of the
pixels_per_em attribute in
the TypeMetric struct returned by Draw#get_type_metrics is a
Primary.new(x, y, z) -> aPrimary
See class Chromaticity.
Rectangle.new(width, height, x, y) -> aRectangle
Segment.new(x1, y1, x2, y2) -> aSegment
The value of the
bounds attribute in the
x1, y1, x2, y2
The Image#new and ImageList#new_image methods accept
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
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
gets the image as its only argument and sends whatever
methods are necessary to the image to fill the image's
RMagick supplies three Fill classes,
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.
GradientFill.new(x1, y1, x2, y2, start_color, end_color) -> aGradientFill
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.
HatchFill.new(background_color, hatch_color='white', dist=10) -> aHatchFill
Creates a cross-hatched fill.
TextureFill.new(texture_image) -> aTextureFill
When an ×Magick function returns an error condition,
RMagick raises an