class Image < Object (attribute methods)
mixes in Comparable

Table of Contents

attribute methods

attribute methods

background_color

img.background_color -> string
img.background_color = string or pixel -> string or pixel

Description

The image's background color. By default the background color is "white".

Argument

Either a color name or a Pixel object.

Returns

A color name or Pixel object.

base_columns

img.base_columns -> integer

Description

The number of columns in the image before any transformations. Get-only.

base_filename

img.base_filename -> string

Description

The image's original filename before any transformations. Get-only.

base_rows

img.base_rows -> integer

Description

The number of rows in the image before any transformations. Get-only.

bias

img.bias -> float
img.bias = float or string -> float or string

Description

Add bias when convolving an image

Argument

Either a number between 0.0 and 1.0 or a string in the form "NN%".

black_point_compensation

img.black_point_compensation -> true or false
img.black_point_compensation = true or false -> true or false

Description

Use black point compensation. Typically used in CMYK-to-RGB conversion along with image. rendering_intent=Magick::RelativeIntent

border_color

img.border_color -> string
img.border_color = string or pixel -> string or pixel

Description

The image's border color. The default border color is "#dfdfdf" (gray).

Argument

Either a color name or a Pixel object.

Returns

A color name.

bounding_box

img.bounding_box -> rectangle

Description

Returns the bounding box of an image canvas. Get-only.

Returns

A Rectangle object.

chromaticity

img.chromaticity -> chromaticity
img.chromaticity = chromaticity -> chromaticity

Description

The red, green, blue, and white-point chromaticity values..

Argument

A Chromaticity object.

Returns

A Chromaticity object.

class_type

img.class_type -> storage_class
img.class_type = storage_class -> storage_class

Description

The image's storage class. If DirectClass then the pixels contain valid RGB or CMYK colors. If PseudoClass then the image has a colormap referenced by the pixel's index member.

Argument

A ClassType constant.

Returns

A ClassType constant.

color_profile

img.color_profile -> string
img.color_profile = string -> string

Description

The ICC color profile.

Argument

A color profile is represented as a string. If the argument is nil instead of string then any ICC color profile present in the image is deleted.

The setter form of this attribute deletes any existing ICC color profile(s) before adding the new one. If you need to add both source and destination profiles use add_profile or profile!.

Returns

The current color profile, or nil if there is no profile.

See also

add_profile, delete_profile, each_profile, profile!

colors

img.colors -> integer

Description

The number of colors in the colormap. Only meaningful for PseudoClass images. Get-only.

colorspace

img.colorspace -> colorspace
img.colorspace = colorspace -> colorspace

Description

Image pixel interpretation. If the colorspace is RGBColorspace the pixels are red, green, blue. If alpha? is true, then red, green, blue, and opacity. If it is CMYKColorspace, the pixels are cyan, yellow, magenta, black. Otherwise the colorspace is ignored.

Argument

A ColorspaceType constant.

Returns

A ColorspaceType constant.

columns

img.columns -> integer

Description

The width of the image in pixels. Get-only.

compose

img.compose -> operator
img.compose = operator -> operator

Description

The image composite operator. The default is OverCompositeOp. See montage.

Argument

A composite operator constant.

Returns

A composite operator constant.

compression

img.compression -> type
img.compression = type -> type

Description

The image compression type. The default is the compression type of the specified image file.

Argument

A CompressionType constant.

Returns

A CompressionType constant.

delay

img.delay -> integer
img.delay = integer -> integer

Description

Number of ticks which must expire before displaying the next image in an animated sequence. The default number of ticks is 0. By default there are 100 ticks per second but this number can be changed via the ticks_per_second attribute.

Argument

An integer value between 0 and 65535, inclusive.

Returns

The current delay value.

density

img.density -> string
img.density = string or geometry -> string or geometry

Description

The vertical and horizontal resolution in pixels of the image. The default is "72x72".

Argument

The density may be expressed either as a string or a Geometry object. If a string, it is in the form "XxY", or simply "X". If "Y" is omitted it is set to "X". To specify the density with a Geometry object, set the width attribute to the x resolution and the height argument to the y resolution. If height is nil, width will be used as the y resolution as well.

Returns

The image density represented as a string.

See also

Also see x_resolution and y_resolution.

depth

img.depth -> integer

Description

The image depth (8, 16, or 32). Get-only.

directory

img.directory -> string

Description

Tile names from within an image montage. Only valid after calling montage or reading a MIFF file which contains a directory. Get-only.

Returns

A newline ("\n")-delimited list of the images in the montage.

dispose

img.dispose -> method
img.dispose = method -> method

Description

GIF disposal method. This attribute is used to control how successive images are rendered (how the preceding image is disposed of) when creating a GIF animation.

Argument

An integer corresponding to the disposal method.

Returns

A DisposeType constant.

endian

img.endian -> endian
img.endian = endian -> endian

Description

Specify an endian option for images that support it.

Argument

A EndianType constant.

Returns

A EndianType constant.

extract_info

img.extract_info -> rectangle
img.extract_info = rectangle

Description

Specify a rectangle within an image, or retrieve the rectangle specified when the image was constituted. See extract=.

Argument

A Rectangle object.

Returns

A Rectangle object.

filename

img.filename -> string

Description

The image filename. Get-only.

filesize

img.filesize -> integer

Description

The image filesize in bytes. Get-only.

filter

img.filter -> type
img.filter = type -> type

Description

Filter to use when resizing image. The reduction filter employed has a significant effect on the time required to resize an image and the resulting quality. The default filter is Lanczos which has been shown to produce high quality results when reducing most images.

Argument

A FilterType constant.

Returns

A FilterType constant.

format

img.format -> string
img.format = string -> string

Description

The image encoding format. For example, "GIF" or "PNG". See formats.

Argument

The format name.

Returns

The format name.

fuzz

img.fuzz -> float
img.fuzz = float or string -> float or string

Description

Colors within this distance are considered equal. A number of algorithms search for a target color. By default the color must be exact. Use this [attribute] to match colors that are close to the target color in RGB space.

See opaque, texture_floodfill, and transparent.

Argument

The argument may be a floating-point numeric value or a string in the form "NN%". In the second case, the argument is computed as a percentage of QuantumRange. For example, a value of '5%' sets fuzz to 0.05*QuantumRange.

Returns

A Float or string

gamma

img.gamma -> float
image.gamma = float -> float

Description

Gamma level of the image. The same color image displayed on two different workstations may look different due to differences in the display monitor. Use gamma correction to adjust for this color difference.

geometry

img.geometry -> string
img.geometry = string -> string

Description

Preferred size of the image when encoding.

Argument

A geometry string.

Returns

A geometry string.

gravity

img.gravity -> gravity
img.gravity = gravity -> gravity

Description

Used with the ImageList#composite_layers method. The direction that the image gravitates within the composite.

Argument

A GravityType value.

Returns

A GravityType value.

image_type

img.image_type -> type
img.image_type = type -> type

Description

The image type classification. For example, GrayscaleType. Don't confuse this attribute with the format, that is "GIF" or "JPG". Get-only.

Argument

An ImageType value.

Returns

An ImageType value.

interlace

img.interlace -> type
img.interlace = type -> type

Description

The type of interlacing scheme (default NoInterlace). This option is used to specify the type of interlacing scheme for raw image formats such as RGB or YUV. NoInterlace means do not interlace, LineInterlace uses scanline interlacing, and PlaneInterlace uses plane interlacing. PartitionInterlace is like PlaneInterlace except the different planes are saved to individual files (e.g. image.R, image.G, and image.B). Use LineInterlace or PlaneInterlace to create an interlaced GIF or progressive JPEG image.

Argument

An InterlaceType constant.

Returns

An InterlaceType constant.

iptc_profile

img.iptc_profile -> string
img.iptc_profile = string -> string

Description

The International Press Telecommunications Council profile.

Argument

A IPTC profile is represented as a string. If the argument is nil instead of string then any IPTC profile present in the image is deleted.

Returns

The current IPTC profile, or nil if there is no profile.

See also

add_profile, delete_profile, each_profile. profile!

matte_color

img.matte_color -> string
img.matte_color = string or pixel -> string or pixel

Description

Specify the matte color.

Returns

A matte color name or Pixel object.

mean_error_per_pixel

img.mean_error_per_pixel -> float

Description

The mean error per pixel computed when a image is color reduced. This attribute is only valid if the measure_error argument to quantize[ImageList] [Image] is set to true. Get-only.

mime_type

img.mime_type -> string

Description

Returns the officially registered (or de facto) MIME media-type. If there is no registered media-type, returns "image/x-magick". Get-only.

montage

img.montage -> string

Description

Tile size and offset within an image montage. Only valid for [images produced by montage.] The string is in the form of a geometry string. Get-only.

normalized_mean_error

img.normalized_mean_error -> float

Description

The normalized mean error computed when an image is color reduced. This attribute is only valid if the measure_error argument to quantize[ImageList][Image] is set to true. Get-only.

normalized_maximum_error

img.normalized_maximum_error -> float

Description

The normalized mean error per pixel computed when an image is color reduced. This attribute is only valid if the measure_error argument to quantize[ImageList][Image] is set to true. Get-only.

number_colors

img.number_colors -> integer

Description

Number of unique colors in the image. Get-only.

offset

img.offset -> integer
img.offset = integer -> integer

Description

Number of initial bytes to skip over when reading raw image.

Description

Attenuates the opacity channel of an image. If the image pixels are opaque, they are set to the specified opacity level. Otherwise, the pixel opacity values are blended with the supplied transparency value.

Argument

A number between 0 and QuantumRange. Higher numbers increase transparency.

orientation

img.orientation -> type
img.orientation = type -> type

Description

The value of the Exif Orientation Tag.

Returns

An OrientationType value.

Notes

See https://jpegclub.org/exif_orientation.html for more information about the Exif Orientation Tag.

page

img.page -> rectangle
img.page = rectangle -> rectangle

Description

When compositing, this attribute describes the position of this image with respect to the underlying image. See coalesce, flatten_images, and mosaic.

Argument

A Rectangle object.

Returns

A Rectangle object.

pixel_interpolation_method

img.pixel_interpolation_method -> method
img.pixel_interpolation_method = method -> method

Description

Get/set the pixel color interpolation method. Some methods (such as wave, swirl, implode, and composite) use the pixel color interpolation method to determine how to blend adjacent pixels.

Argument

An PixelInterpolateMethod enum value.

Returns

An PixelInterpolateMethod enum value.

quality

img.quality -> integer

Description

For JPEG images, returns the Independent JPEG Group quality value. This number is a measurement of the amount of compression used when the image was saved. Lower numbers mean higher compression.

Returns

A number between 0-100.

Notes

For more information, see The JPEG image compression FAQ.

quantum_depth

img.quantum_depth -> integer

Description

The image depth to the nearest Quantum (8, 16, or 32). Get-only.

rendering_intent

img.rendering_intent -> type
img.rendering_intent = type -> type

Description

The type of rendering intent. See https://www.cambridgeincolour.com/tutorials/color-space-conversion.htm

Argument

A RenderingIntent constant.

Returns

A RenderingIntent constant.

rows

img.rows -> integer

Description

The height of the image in pixels. Get-only.

scene

img.scene -> integer

Description

The scene number assigned to the image the last time the image was written to a multi-image image file. Don't confuse this attribute with ImageList's scene attribute, which denotes the image to which Image methods will be sent.

start_loop

img.start_loop -> true or false
img.start_loop = true or false -> true or false

Description

Indicates the first image in an animation.

ticks_per_second

img.ticks_per_second -> integer
image.ticks_per_second = integer -> integer

Description

Gets/sets the number of ticks per second. This attribute is used in conjunction with the delay attribute to establish the amount of time that must elapse between frames in an animation.The default is 100.

Returns

The current number of ticks per second

total_colors

img.total_colors -> integer

Description

The number of colors in the image after quantization. Set by quantize [ImageList][Image] if the measure_error argument is true. Get-only.

total_ink_density

img.total_ink_density -> float

Description

The total ink density for a CMYK image. Total Ink Density (TID) is determined by adding the CMYK values in the darkest shadow area in an image. Get-only.

transparent_color

img.transparent_color -> string
img.transparent_color = string or pixel -> string or pixel

Description

Specify the name of the transparent color as a String.

Returns

A transparent color name or Pixel object.

units

img.units -> type
img.units = type -> type

Description

Units of image resolution.

Argument

A ResolutionType constant.

Returns

A ResolutionType constant.

See also

x_resolution, y_resolution

virtual_pixel_method

img.virtual_pixel_method -> method
img.virtual_pixel_method = method -> method

Description

Specify how "virtual pixels" behave. Virtual pixels are pixels that are outside the boundaries of the image. Methods such as blur_image, sharpen, and wave use virtual pixels.

Argument

The virtual pixel method can be any one of the following VirtualPixelMethod constants:

EdgeVirtualPixelMethod
Extend the edge pixel toward infinity. This is the default.
MirrorVirtualPixelMethod
Mirror the image.
TileVirtualPixelMethod
Tile the image.
BackgroundVirtualPixelMethod
The area surrounding the image is the background color.
TransparentVirtualPixelMethod
The area surrounding the image is transparent blackness.
BlackVirtualPixelMethod
The area surrounding the image is black.
GrayVirtualPixelMethod
The area surrounding the image is gray.
WhiteVirtualPixelMethod
The area surrounding the image is white.
RandomVirtualPixelMethod
Choose a random pixel from the image.
DitherVirtualPixelMethod
use a dithered pattern to choose a pixel in a 32x32 neighborhood.
HorizontalTileVirtualPixelMethod
Horizontally tile the image
VerticalTileVirtualPixelMethod
Vertically tile the image
HorizontalTileEdgeVirtualPixelMethod
Horizontally tile the image and replicate the side edge pixels
VerticalTileEdgeVirtualPixelMethod
Vertically tile the image and replicate the side edge pixels
CheckerTileVirtualPixelMethod
Alternate squares with image and background color

Some of these values are not supported by older versions of ImageMagick. To see what values are available, enter the following code in irb:

Magick::VirtualPixelMethod.values {|v| puts v}

Returns

A VirtualPixelMethod constant.

Example

img.virtual_pixel_method = Magick::TransparentVirtualPixelMethod

x_resolution

img.x_resolution -> float
img.x_resolution = float -> float

Description

Horizontal resolution of the image.

See also

units

y_resolution

img.y_resolution -> float
img.y_resolution = float -> float

Description

Vertical resolution of the image.

See also

units