image.enhance -> anImage
Applies a digital filter that improves the quality of a noisy image.
A new image
The left-hand side has had noise added by add_noise
. The right-hand side is the
result after using enhance
.
median_filter, reduce_noise, unsharp_mask
EnhanceImage
image.equalize -> anImage
Applies a histogram equalization to the image.
A new image
EqualizeImage
image.erase! -> image
image.export_pixels(x=0, y=0, columns=image.columns, rows=image.rows, map="RGB") -> anArray
Extracts the pixel data from the specified rectangle and
returns it as an array of Integer
values.
The array returned by export_pixels
is suitable
for use as an argument to import_pixels
.
# Export the r'th scanline from an image in red-green-blue order scanline = img.export_pixels(0, r, img.columns, 1, "RGB");
dispatch, export_pixels_to_str, import_pixels, get_pixels
ExportImagePixels
This method replaces the dispatch
method.
image.export_pixels_to_str(x=0, y=0, columns=image.columns,
rows=image.rows, map="RGB",
type=Magick::CharPixel
)
-> aString
Extracts the pixel data from the specified rectangle and returns it as a string. If you need to get the pixel data in a memory buffer (as input to another application, for example), this method is much, much faster than export_pixels or get_pixels.
The string returned by export_pixels_to_str
is
suitable for use as an argument to
import_pixels
.
Note: You can also use to_blob to convert an image into a string.
CharPixel
,
which means that the pixel values will be stored as C
unsigned char
s.dispatch, export_pixels, import_pixels, get_pixels
ExportImagePixels
image.flip -> anImage
Create a vertical mirror image of the receiver.
A new image
FlipImage
image.flip! -> image
image.flop -> anImage
Create a horizontal mirror image of the receiver.
A new image
FlopImage
image.flop! -> image
image.frame(width=25, height=25,
x=25, y=25,
inner_bevel=6, outer_bevel=6, color=matte_color
) ->
anImage
Adds a simulated 3D border.
A new image
FrameImage
image.gamma_channel(gamma, [channel...]) = anImage
Gamma-correct a particular image channel. The same image viewed on different devices will have perceptual differences in the way the image's intensities are represented on the screen.
A new image
The older gamma_correct method
is implemented in terms of gamma_channel
.
GammaImageChannel
image.gamma_correct(red_gamma[,green_gamma[, blue_gamma[, opacity_gamma]]]) -> anImage
Gamma-correct an image. The same image viewed on different devices will have perceptual differences in the way the image's intensities are represented on the screen.
You must specify at least red_gamma
. Omitted
arguments take on the value of the last specified argument.
Values typically range from 0.8 to
2.3.
A new image
GammaImage
image.gaussian_blur(radius=0.0, sigma=1.0) -> anImage
Blurs an image. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma).
Float
value representing the radius of the Gaussian, in pixels, not counting
the center pixel.Float
value representing the standard
deviation of the Gaussian operator, in pixels. This argument
must be > 0.0.A new image
gaussian_blur(0.0, 3.0)
blur_image, motion_blur, radial_blur
GaussianBlurImage
image.gaussian_blur_channel(radius=0.0, sigma=1.0[, channel...]) -> anImage
Blurs the selected channel or channels using a Gaussian operator of the specified radius and standard deviation.
Float
value representing the radius of the Gaussian, in pixels, not counting
the center pixel.Float
value representing the standard
deviation of the Gaussian operator, in pixels. This argument
must be > 0.0.A new image
image.get_exif_by_entry([name]*) -> anArray
Returns the value associated with the specified EXIF entry name or names. If no names are specified, returns all the entries. The return value is an array containing one or more [name, value] elements.
Zero or more EXIF entry names.
The elements in the returned array are 2-element arrays in
the form [name, value]. If ×Magick does not know the name
for an entry it uses "unknown." There may be more than one
entry for "unknown" in the returned array. If there is no entry
with the specified name the value is set to
nil
.
image.get_exif_by_entry('Make') » [["Make", "Canon"]] image.get_exif_by_entry("ShutterSpeedValue") » [["ShutterSpeedValue", "189/32"]] image.get_exif_by_entry() » [["Make", "Canon"], ["ShutterSpeedValue", "189/32"] ...]
image.get_exif_by_number([tag]*) -> aHash
Returns the value associated with the specified EXIF tag number or numbers. If no numbers are specified, returns all the tags. The return value is a hash. The hash keys are EXIF tag numbers. The values are the values associated with the tags.
Zero or more EXIF tag numbers.
A hash. If there is no tag with the specified number the
value is set to nil
.
image.get_exif_by_number(271) » {271=>"Canon"} image.get_exif_by_number(37377) » {37377=>"189/32"} image.get_exif_by_number() » {271=>"Canon", 37377=>"189/32" ...}
image.get_pixels(x, y, columns, rows) -> anArray
Gets the pixels from the specified rectangle within the image.
An array of pixels. There
will be columns*rows
elements in the array.
This example composites
a black-and-white version of an image over the same image in
its original colors. It uses get_pixels
and
store_pixels to make
each column of pixels in the black-and-white image slightly
more opaque than the column on its left, so that the resulting
composite changes smoothly from color on the left to
black-and-white on the right.
AcquireImagePixels
image.gray? -> true
or false
Returns true
if all the pixels in the image
have the same red, green, and blue intensities.
true
or false
IsGrayImage
image.grayscale_pseudo_class(optimize=true
) ->
anImage
Converts an image to a PseudoClass grayscale representation with an optionally compressed and sorted colormap.. This method is only available in GraphicsMagick 1.1 and later.
A new image
GrayscalePseudoClass
image.qrey? -> true
or false
Synonym for gray?
image.implode(amount=0.50) -> anImage
A funhouse mirror effect. See the example below.
A Float
value. Increasing the absolute value of
the argument increases the effect. The value may be positive
for implosion, or negative for explosion. The default is
0.50.
A new image
This example is an animated image. Mouse over the image to start the animation.
ImplodeImage
image.import_pixels(x, y, columns, rows, map, pixels, type=Magick::CharPixel) -> image
Replaces the pixels in the specified rectangle with pixel
data from the supplied array or string. When the pixels argument is an array of pixel data, this
method is the reverse of export_pixels
. When the
pixels argument is a string,
import_pixels
is ideal for loading very large
amounts of binary pixel data.
:to_str
import_pixels
assumes that pixels can be converted to a string by
to_str
and that the result is a C array of
the type specified by type
containing binary pixel data in the order specified by
map. The elements in the buffer
must be in the range specified by type.import_pixels
assumes that pixels is an array or an object that can be
converted to an array by the Kernel::Array
method. The elements in the array must be
Numeric
values in the range [0..MaxRGB]. In
either case, the pixel data must be stored in scanline
order: left-to-right and top-to-bottom.The image as transformed by the pixel data.
# Replace the r'th scanline of the image using # pixel data stored in red-green-blue order. img.import_pixels(0, r, img.columns, 1, "RGB", scanline);
This example is contrived since there's no need to convert
the pixels
array into a string by calling
pack
, but it does demonstrate the use of a string
pixels argument. Note that this
example assumes that ×Magick is configured with
QuantumDepth=8.
hat = Magick::Image.read("Flower_Hat.jpg").first pixels = hat.export_pixels(0, 0, hat.columns, hat.rows, "RGB") char_buffer = pixels.pack("C*") img = Magick::Image.new(hat.columns, hat.rows) img.import_pixels(0, 0, hat.columns, hat.rows, "RGB", char_buffer, Magick::CharPixel)
constitute, export_pixels, store_pixels
ImportImagePixels
This method replaces the constitute
method.
image.inspect -> aString
Constructs a description of the image as a string. The string contains some or all of the following fields:
f.inspect » "images/Flower_Hat.jpg JPEG 200x250 DirectClass 8-bit 9kb"
image.level(black_point=0.0
, white_point=MaxRGB
, gamma=1.0
) -> anImage
Adjusts the levels of an image by scaling the colors falling between specified white and black points to the full available quantum range. The parameters provided represent the black, mid, and white points. The black point specifies the darkest color in the image. Colors darker than the black point are set to zero. Gamma specifies a gamma correction to apply to the image. White point specifies the lightest color in the image. Colors brighter than the white point are set to the maximum quantum value
A new image
level(0,1.50)
Prior to version 1.11.0 RMagick defined the signature for
level
incorrectly:
img.level(white_point, gamma, black_point) -> anImage # wrong!
That is, the gamma
and white_point
arguments were swapped. In an effort to maintain compatiblity
with older scripts that expect that signature,
level
inspects its arguments and will interchange
white_point
and gamma if they "look" incorrect.
That is, if gamma
is > 10.0, or if
white_point
is < 10.0, or if gamma
> white_point
, then level
will
swap them.
If you want to avoid this behavior, use the
level2
method instead. The level2
method is exactly the same as level
except that it
never swaps the arguments.
LevelImage
image.level_channel(channel, black_point=0, white_point=MaxRGB - black_point, gamma=1.0) -> anImage
A new image
LevelImageChannel
image.magnify -> anImage
A convenience method that scales the receiver to twice its size.
A new image
magnify!, minify, resize, scal
MagnifyImage
image.magnify! -> image
image.map(img, dither=false) -> anImage
Replaces the colors of an image with the closest color from a reference image.
A new image
This image has been mapped to the Netscape 216-color cube.
MapImage
image.matte_fill_to_border(x, y) -> anImage
Makes transparent all the pixels that are neighbors of the pixel at x,y and are not the border color.
The x- and y- coordinates of the target pixel.
A new image
In this example the border color is black. The fill starts in the center and makes all the pixels transparent until it reaches a black pixel. The resulting image has been composited over a plasma background, which shows through the transparent pixels.
MatteFloodfillImage
image.matte_floodfill(x, y) -> anImage
Makes transparent all the pixels that are the same color as the pixel at x, y, and are neighbors.
The x- and y-coordinates of the target pixel.
A new image
In this example the fill starts at the center pixel and replaces all the yellow pixels - the color of the center pixel. The resulting image has been composited over a plasma background, which shows through the transparent pixels.
MatteFloodfilImage
image.matte_point(x, y) -> anImage
Makes the pixel at x, y transparent. This method makes a copy of the image, just to make one pixel transparent. I recommend using the Draw#matte method instead.
The x- and y-coordinates of the target pixel.
A new image
image.matte_replace(x, y) -> anImage
Makes transparent all the pixels that are the same color as the pixel at x, y.
A new image
In this example the target pixel is a black pixel in the center of the uppermost circle. The matte_replace method makes all the black pixels in the image transparent. The resulting image has been composited over a plasma background, which shows through the transparent pixels.
TransparentImage
image.matte_reset! -> image
Makes all the pixels in the image transparent.
self
image.median_filter(radius=1.0) -> anImage
Applies a digital filter that improves the quality of a noisy image. Each pixel is replaced by the median in a set of neighboring pixels as defined by radius.
The filter radius. The larger the value, the longer it takes to render. Values larger than 8 or 9 may take longer than you want to wait, and will not have significantly better results than much smaller values.
A new image
The left side of the image has been modified by add_noise. The right side has been filtered by median_filter(0.05).
enhance, reduce_noise, unsharp_mask
MedianFilterImage
image.minify -> anImage
A convenience method that scales the receiver to half its size.
A new image
minify! magnify, resize, sample, scale, thumbnail
MinifyImage
image.minify! -> image
image.modulate(brightness=1.0, saturation=1.0, hue=1.0) -> anImage
Changes the brightness, saturation, and hue.
The percent change in the brightness, saturation, and hue, represented as Float numbers. For example, 0.25 means "25%". All three arguments may be omitted. The default value of each argument is 1.0, that is, 100%.
A new image
modulate(0.85)
ModulateImage
image.monochrome? -> true or false
Returns true if all the pixels have the same red, green, and blue values and the values are either 0 or MaxRGB. That is, the image is black-and-white.
IsMonochromeImage
image.motion_blur(radius, sigma, angle) -> anImage
Simulates motion blur. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma). Use a radius of 0 and motion_blur selects a suitable radius for you. Angle gives the angle of the blurring motion.
A new image
MotionBlurImage
image.negate(grayscale=false) -> anImage
Negates the colors in the receiver.
A new image
NegateImage
image.negate_channel(grayscale=false, [channel...]) = anImage
Negate a particular image channel or channels.
A new image
negate_channel(false, GreenChannel)
NegateImageChannel
image.normalize -> anImage
Enhances the contrast of a color image by adjusting the pixel color to span the entire range of colors available.
A new image
NormalizeImage
image.normalize_channel([channel...]) = anImage
Enhances the contrast of a color image by adjusting the pixel color to span the entire range of colors available. Only the specified channels are normalized.
A new image
NormalizeImageChannel (available in ImageMagick 6.1.0)
image.oil_paint(radius=3.0) -> anImage
Applies a special effect filter that simulates an oil painting. Each pixel is replaced by the most frequent color occurring in a circular region defined by radius.
A new image
OilPaintImage
image.opaque(target, fill) -> anImage
Changes all pixels having the target color to the fill color.
A new image
This example replaces white pixels with red pixels. Set the fuzz attribute to specify how closely the target pixels must match.
OpaqueImage
image.opaque? -> true or false
Returns true if all of the pixels in the receiver have an opacity value of OpaqueOpacity.
true or false
IsOpaqueImage
image.ordered_dither(order=2) -> anImage
Uses the ordered dithering technique of reducing color images to monochrome using positional information to retain as much information as possible.
A new image
RandomThresholdImageChannel
image.palette? -> true or false
Returns true if the image is PseudoClass and has 256 unique colors or less.
true or false
IsPaletteImage
image.pixel_color(x, y[, new_color]) -> aPixel
Returns the color of the pixel at x, y. Optionally, changes the color of the pixel to a new color.
If new_color is specified, pixel_color changes the image type to DirectClass if necessary.
old = image.pixel_color(20,40,"white")
AcquireImagePixels
image.posterize(levels=4, dither=false) -> anImage
Reduces the image to a limited number of colors for a "poster" effect.
A new image
PosterizeImage