img.palette? -> true or false
Returns true if the image is PseudoClass and has 256 unique colors or less.
true or false
IsPaletteImage
img.paint_transparent(color, opacity=TransparentOpacity, invert=false, fuzz=img.fuzz) -> image
Changes the opacity value of all the pixels that match color to the value specified by opacity. If invert is true, changes the pixels that don't match color.
A new image
matte_replace, Draw#matte, transparent
TransparentPaintImage
img.pixel_color(x, y[, new_color]) -> pixel
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
img.polaroid(angle=-5.0) [ { optional arguments } ] -> image
Produce an image that looks like a Polaroid® instant picture. If the image has a "Caption" property, the value is used as a caption.
Optional arguments may be specified in a block associated with the method. These arguments control the shadow color and how the label is rendered. By
default the shadow color is gray75. To specify a different shadow color, use options.shadow_color
. To specify a different border color
(that is, the color of the image border) use options.border_color
. Both of these methods accept either a
color name or a Pixel argument.
The following annotate attributes control the label rendering: align, decorate, density, encoding, fill, font, font_family, font_stretch, font_style, font_weight, gravity, pointsize, stroke, stroke_width, text_antialias, undercolor.
img.polaroid do |options| options.shadow_color = "gray40" options.pointsize = 12 end
PolaroidImage
"Polaroid" and the other names of products of Polaroid Corporation are trademarks of Polaroid Corporation.
img.posterize(levels=4, dither=false) -> image
Reduces the image to a limited number of colors for a "poster" effect.
A new image
PosterizeImage
img.preview(preview) -> image
Creates an image that contains 9 small versions of the receiver image. The center image is the unchanged receiver. The other 8 images are variations created by transforming the receiver according to the specified preview type with varying parameters.
A preview image is an easy way to "try out" a transformation method.
One of the following PreviewType constants:
A new image
This half-size preview demonstrates the SolarizePreview argument.
PreviewImage
img.profile!(name, profile) -> self
Adds or removes a ICM, IPTC, or generic profile from an image.
If profile
is nil
, the specified profile is removed from the image. Use profile('*', nil)
to remove all profiles
from the image.
nil
to cause the profile to be removed.self
add_profile and delete_profile perform very similar functions. However,
add_profile
accepts the name of a profile file on disk instead of the profile data itself and, if the file contains more than one profile,
will load all the profiles at once.
ProfileImage
ImageMagick does not automatically remove profiles when resizing images. If you are trying to make your JPEG thumbnail images as small as possible, use
profile!
to remove any profiles from the image as well. Also see strip!
img.properties [ {|name,value| block} ] -> hash
If called with an associated block, properties
runs the block once for each property defined for the image. The block arguments are the
property name and its value. If there is no block, properties
returns a hash with one element for each property. The hash key is the
property name and the associated value is the property value.
If called without a block, returns a hash, otherwise returns
self
.
The EXIF property is not created until the first time an EXIF tag or entry number is referenced.
img.quantize(number_colors=256, colorspace=RGBColorspace,
dither=RiemersmaDitherMethod
, tree_depth=0,
measure_error=false
) ->
image
Analyzes the colors within a reference image and chooses a fixed number of colors to represent the image. The goal of the algorithm is to minimize the difference between the input and output image while minimizing the processing time.
NoDitherMethod
to disable dithering. See the documentation for the
ImageMagick -dither option
for more information.
true
to calculate quantization errors when quantizing the image.A new image
See the example for colorize.
ordered_dither, posterize, ImageList#quantize
QuantizeImage
img.quantum_operator(operator, rvalue, channel=AllChannels) -> self
Performs the requested integer arithmetic operation on the selected channel of the image. This method allows simple arithmetic operations on the
component values of all pixels in an image. Of course, you could also do this in Ruby using
get_pixels and store_pixels, or view, but
quantum_operator
will be faster, especially for large numbers of pixels, since it does not need to convert the pixels from C to Ruby.
QuantumExpressionOperator
constants:
AndQuantumOperator
DivideQuantumOperator
LShiftQuantumOperator
MaxQuantumOperator
MinQuantumOperator
MultiplyQuantumOperator
OrQuantumOperator
RShiftQuantumOperator
SubtractQuantumOperator
XorQuantumOperator
PowQuantumOperator
LogQuantumOperator
ThresholdQuantumOperator
ThresholdBlackQuantumOperator
ThresholdWhiteQuantumOperator
GaussianNoiseQuantumOperator
ImpulseNoiseQuantumOperator
LaplacianNoiseQuantumOperator
MultiplicativeNoiseQuantumOperator
PoissonNoiseQuantumOperator
UniformNoiseQuantumOperator
CosineQuantumOperator
SineQuantumOperator
AddModulusQuantumOperator
Magick::QuantumExpressionOperator.values {|v| puts v}
Numeric
operation rvalue.self
Divide the red component of all the pixels in the image by 2:
img.quantum_operator(Magick::DivideQuantumOperator, 2, Magick::RedChannel)
The Image::View class supports operations on individual pixels and collections of pixels, as well as operations on channels within pixels. See view, below.
EvaluateImageChannel
img.radial_blur(float) -> image
Applies a radial blur to the image.
A new image
blur_image, gaussian_blur, motion_blur, radial_blur_channel, selective_blur_channel
RadialBlurImage
img.radial_blur_channel(float [, channel...]) -> image
Applies a radial blur to the selected image channels.
A new image
RadialBlurImageChannel
img.raise(width=6, height=6,
raised=true
) -> image
Creates a simulated three-dimensional button-like effect by lightening and darkening the edges of the image.
true
, the image is raised, otherwise lowered.A new image
RaiseImage
img.random_threshold_channel( thresholds, [channel...] ) -> image
Changes the value of individual pixels based on the intensity of each pixel compared to a random threshold. The result is a low-contrast, two color image.
A new image
geom = Magick::Geometry.new(Magick::QuantumRange/2) random_threshold_channel(geom, Magick::RedChannel)
adaptive_threshold, bilevel_channel, threshold
RandomThresholdImageChannel
img.recolor(color_matrix) -> image
Use this method to translate, scale, shear, or rotate image colors. Although you can use variable sized matrices, typically you use a 5×5 for an RGBA image and a 6×6 for CMYKA. Populate the last row with normalized values to translate.
An array of Float values representing the recolor matrix.
RecolorImage
img.reduce_noise(radius) -> image
Smooths the contours of an image while still preserving edge information. The algorithm works by replacing each pixel with its neighbor closest in value.
reduce_noise
selects a suitable radius for you.
A new image
The left side of the image has been modified by
add_noise
. The right side has been filtered by reduce_noise(0)
.
ReduceNoiseImage
img.remap(remap_image, dither=RiemersmaDitherMethod) -> self
Reduce the number of colors in img to the colors used by remap_image. If a dither method is specified then the given colors are dithered over the image as necessary, otherwise the closest color (in RGB colorspace) is selected to replace that pixel in the image.
self
RemapImage (available in ImageMagick 6.4.3-6)
img.resample(horizontal_res=72.0[, vertical_res]) -> image
Resample image to specified horizontal and vertical resolution.
Resize the image so that its rendered size remains the same as the original at the specified target resolution. For example, if a 300 DPI image renders at 3 inches by 2 inches on a 300 DPI device, when the image has been resampled to 72 DPI, it will render at 3 inches by 2 inches on a 72 DPI device. Note that only a small number of image formats (e.g. JPEG, PNG, and TIFF) are capable of storing the image resolution. For formats which do not support an image resolution, the original resolution of the image must be specified via the density attribute prior to specifying the resample resolution.
img.resize(new_width, new_height, filter=LanczosFilter, support=1.0) -> image
img.resize(scale_factor) -> image
Changes the size of the receiver to the specified dimensions.
You can specify the new size in two ways. Either specify the new width and height explicitly, or specify a scale factor, a number that represents the percentage change.
Use the change_geometry method to resize an image with constraints such as "maintain the current proportions."
A new image
change_geometry, resize!, magnify, minify, sample, scale, thumbnail
ResizeImage
img.resize!(new_width, new_height, filter=LanczosFilter,
support=1.0) -> self
img.resize!(scale_factor) -> self
img.resize_to_fill(width [, height [,
gravity=CenterGravity
]]) ->
image
A convenience method. Resize the image to fit within the specified dimensions while retaining the aspect ratio of the original image. If necessary, crop the image in the larger dimension.
crop
method. The default is CenterGravity
.
A new image
In this example, some rows have been cropped from the top and bottom to produce a square thumbnail from a rectangular image without distorting the image.
crop_resized
is an alias for this method.
img.resize_to_fill!(width [, height [,
gravity=CenterGravity
]]) ->
self
self
crop!, resize!, resize_to_fit!
crop_resized!
is an alias for this method.
img.resize_to_fit(new_width [, new_height]) -> image
A convenience method. Resize the image to fit within the specified dimensions while retaining the original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
A new image
Compare the result of this example to the result of the resize_to_fill example above.
img.resize_to_fit!(new_width [, new_height]) -> self
img.roll(x_offset, y_offset) -> image
Offsets an image as defined by x_offset and y_offset.
A new image
This image has been offset 25% in both directions.
RollImage
img.rotate(amount [, qualifier]) -> image
Rotate the receiver by the specified angle. Positive angles rotate clockwise while negative angles rotate counter-clockwise. New pixels introduced by the rotation are the same color as the current background_color. Set the background color to "none" to make the new pixels transparent black.
A new image, or nil
if the image was not rotated because it did not meet the qualification specified by the second argument.
RotateImage
img.rotate!(amount [, qualifier]) -> self
In-place form of rotate.
self, or nil
if the image was not rotated because it did not meet the qualification specified by the second argument.
img.sample(new_width, new_height) -> image
img.sample(scale_factor) -> image
Scales an image to the desired dimensions with pixel sampling. Unlike other scaling methods, this method does not introduce any additional color into the scaled image.
A new image
sample!, magnify, minify, resize, scale, thumbnail
SampleImage
img.sample!(new_width, new_height) -> self
img.sample!(scale_factor) -> self
img.scale(new_width, new_height) -> image
img.scale(scale_factor) -> image
Changes the size of an image to the given dimensions.
A new image
scale!, magnify, minify, resize, sample, thumbnail
ScaleImage
img.scale!(new_width, new_height) -> self
img.scale!(scale_factor) -> self
img.segment(colorspace=RGBColorspace, cluster_threshold=1.0,
smoothing_threshold=1.5, verbose=false
) ->
image
Segments an image by analyzing the histograms of the color components and identifying units that are homogeneous with the fuzzy c-means technique.
ColorspaceType
value.
Empirical evidence suggests that distances in YUV or YIQ correspond to perceptual color differences more closely than do distances in RGB space.
The image is then returned to RGB colorspace after color reduction.
true
, segment
prints detailed information about the identified classes.A new image
img.segment(YUVColorspace, 0.4, 0.4)
SegmentImage
img.selective_blur_channel(radius, sigma, threshold[, channel...]) -> image
Selectively blur pixels within a contrast threshold.
A new image
img2 = img.selective_blur_channel(0, 1, '10%')
blur_channel, blur_image, gaussian_blur_channel, motion_blur, radial_blur
SelectiveBlurImageChannel (available in ImageMagick 6.5.0-3)
Image.separate(channel...) -> imagelist
Constructs a grayscale image for each channel specified.
0 or more ChannelType arguments. If no channels are specified, constructs an image for each of the red, green, and blue channels.
A new imagelist containing the new images.
If the image does not have an opacity channel an OpacityChannel argument is ignored.
SeparateImages
img.sepiatone(threshold=QuantumRange) -> image
Applies a special effect to the image, similar to the effect achieved in a photo darkroom by sepia toning.
A new image.
You can get more control by using colorize.
SepiaToneImage
img.set_channel_depth(channel, depth) -> self
Sets the depth of the image channel.
self
SetImageChannelDepth
img.shade(shading=false
, azimuth=30,
elevation=30) -> image
Shines a distant light on an image to create a three-dimensional effect. You control the positioning of the light with azimuth and elevation; azimuth is measured in degrees off the x axis and elevation is measured in pixels above the Z axis.
true
, shade
shades the intensity of each pixel.A new image
img.shade(true, 50, 50)
ShadeImage
img.shadow(x_offset=4, y_offset=4, sigma=4.0, opacity=1.0) -> image
A new image
ShadowImage
The shadow image is 2×sigma pixels larger on a side than the original image, as can be seen in the example above.
img.sharpen(radius=0.0, sigma=1.0) -> image
Sharpens an image. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma). For reasonable results, radius should be larger than sigma. Use a radius of 0 and
sharpen
selects a suitable radius for you.
The radius and standard deviation of the Gaussian operator.
A new image
SharpenImage
img.sharpen_channel( radius, sigma [,channel...] ) -> image
Sharpens one or more image channels. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma) . For reasonable results, radius should be larger than sigma. Use a radius of 0 and
sharpen_channel
selects a suitable radius for you.
A new image
SharpenImageChannel
img.shave(width, height) -> image
Removes pixels from the edges of the image, leaving the center rectangle.
A new image
ShaveImage
img.shave!(width, height) -> self
img.shear(x_shear, y_shear) -> image
Shearing slides one edge of an image along the X or Y axis, creating a parallelogram. An X direction shear slides an edge along the X axis, while a Y direction shear slides an edge along the Y axis. The amount of the shear is controlled by a shear angle. For X direction shears, x_shear is measured relative to the Y axis, and similarly, for Y direction shears y_shear is measured relative to the X axis. Empty triangles left over from shearing the image are filled with the background color.
The X and Y shear angles, measured in degrees. These values must not be 180.0. If either value is 0, no shearing will occur.
A new image
ShearImage
img.sigmoidal_contrast_channel(contrast=3.0, midpoint=50.0,
sharpen=false[,channel...]) -> image
Adjusts the contrast of an image channel with a non-linear sigmoidal contrast algorithm. Increases the contrast of the image using a sigmoidal transfer function without saturating highlights or shadows.
QuantumRange * 0.50
.
true
to increase the image contrast otherwise the contrast is reduced.A new image
SigmoidalContrastImageChannel
img.signature -> string
Computes a message digest from an image pixel stream with an implementation of the NIST SHA-256 Message Digest algorithm. This signature uniquely identifies the image and is convenient for determining if an image has been modified or whether two images are identical.
ImageMagick adds the computed signature to the image's properties.
The signature as a 64-character string.
img = Magick::Image.read('ex/images/Flower_Hat.jpg').first #=> ex/images/Flower_Hat.jpg JPEG 200x250 DirectClass 8-bit 9761b img.properties #=> {"comment"=>"File written by Adobe Photoshop\250 4.0"} img.signature #=> "485e01ecba1a1f47924d67b887cb07b474f695841733796dfa3c2876965c7e8b" img.properties #=> {"signature"=>"485e01ecba1a1f47924d67b887cb07b474f695841733796dfa3c2876965c7e8b", # "comment"=>"File written by Adobe Photoshop\250 4.0"}
SignatureImage
img.sketch(radius=0.0, sigma=1.0, angle=0.0) -> image
Simulates a pencil sketch. For best results start with a grayscale image.
A new image
SketchImage
img.solarize(threshold=50) -> image
Applies a special effect to the image similar to the effect achieved in a photo darkroom by selectively exposing areas of photo sensitive paper to light.
Ranges from 0 to QuantumRange and is a measure of the extent of the solarization. The default is 50.
A new image
SolarizeImage
img.sparse_color(method, x1, y1, color1[, x2, y2, color2...][, channel...]) -> image
Fills the image with the specified color or colors, starting at the x,y coordinates associated with the color and using the specified interpolation method.
For more information about this method see the ImageMagick documentation for the -sparse-color option. Also see Sparse Points of Color at Examples of ImageMagick Usage.
A new image
SparseColorImage (available in 6.4.3)
img.splice(x, y, width, height[, color]) -> image
Splice a solid color into the image as defined by the x
, y
, width
, and height
arguments. This method
is the opposite of chop.
A new image
color_fill_to_border, color_floodfill, color_reset!, erase!, opaque
SpliceImage
img.spread(radius=3) -> image
Randomly displaces each pixel in a block defined by the radius parameter.
A new image
SpreadImage
img.stegano(watermark, offset) -> image
Hides a digital watermark in the receiver. You can retrieve the watermark by reading the file with the stegano:
prefix, thereby proving the
authenticity of the file.
The watermarked image must be saved in a lossless RGB format such as MIFF, or PNG. You cannot save a watermarked image in a lossy format such as JPEG or a pseudocolor format such as GIF. Once written, the file must not be modified or processed in any way.
A copy of the image containing the embedded watermark.
SteganoImage
img.stereo(offset_image) -> image
Combines two images and produces a single image that is the composite of a left and right image of a stereo pair. Special red-green stereo glasses are required to view this effect.
Another image or imagelist. If the argument is an imagelist, uses the current image.
A new image
StereoImage
img.store_pixels(x, y, columns, rows, pixels) -> image
Replace the pixels in the specified rectangle with the pixels in the pixels array.
rows*columns
.
The image, with the rectangle suitably altered.
Also see the example for
get_pixels
.
SetImagePixels, SyncImagePixels
img.strip! -> self
Strips an image of all profiles and comments.
self
StripImage
img.swirl(degrees) -> image
Swirls the pixels about the center of the image, where degrees indicates the sweep of the arc through which each pixel is moved. You get a more dramatic effect as the degrees move from 1 to 360.
The number of degrees to swirl the image.
A new image
This example is an animated image. Mouse over the image to start the animation.
SwirlImage
img.sync_profiles -> true
or
false
Synchronizes image properties with the image profiles.
True
if everything went okay, false
if there was a problem with the profile.
Currently we only support updating the EXIF resolution and orientation.
SyncImageProfiles
img.texture_fill_to_border(x, y, texture) -> image
Replaces the target pixel at x, y and its neighbors that are not the border color with copies of the texture image. Use the fuzz attribute to specify how closely a pixel must match the border color.
A new image
In this example the target is the pixel in the center of the image. The texture - in this case a picture of a girl in a flowered hat - replaces this
pixel and its neighbors until reaching a black pixel. Mouse over the image to see the original image. Notice the plum-colored circles are replaced as
well. Compare this result with the result of
texture_floodfill
, below.
color_fill_to_border, matte_fill_to_border
ColorFloodfillImage
img.texture_floodfill(x, y, texture) -> image
Replaces the target pixel at x, y and its neighbors that are the same color with the texture image. By default, the neighbor pixels must be exactly the same color as the target pixel. Use the fuzz attribute to specify how much difference is acceptable.
A new image
In this example the target is the pixel in the center of the image. The texture - in this case a picture of a girl in a flowered hat - replaces this
pixel and its same-colored neighbors. Mouse over the image to see the original image. Notice the plum-colored circles are not replaced. Compare this
result with the result of
texture_fill_to_border
, above.
color_floodfill, matte_floodfill
ColorFloodfillImage
img.threshold(threshold) -> image
Changes the value of individual pixels based on the intensity of each pixel compared to threshold. The result is a high-contrast, two color image.
A value between 0 and QuantumRange.
A new image
img.threshold(Magick::QuantumRange * 0.55)
adaptive_threshold, bilevel_channel, random_threshold_channel
ThresholdImage
img.thumbnail(new_width, new_height) -> image
img.thumbnail(scale_factor) -> image
The thumbnail
method is a fast resizing method suitable for use when the size of the resulting image is < 10% of the original.
You can call thumbnail
with either the new width and height or the scale factor.
0.095
.
A new image
img = Magick::Image.read("images/Cheetah.jpg").first thumbnail = img.thumbnail(img.columns * 0.09, img.rows * 0.09)
ThumbnailImage
img.thumbnail!(new_width, new_height) -> self
img.thumbnail!(scale_factor) -> self
img.to_blob [ { optional arguments } ]-> string
Creates a Binary Large OBject, a direct-to-memory version of the image. The from_blob method constructs an image from a BLOB created by this method.
No required arguments, however you can specify the image format (such as JPEG, PNG, etc.) and depth by calling the format and depth attributes, as well as other Image::Info attributes as appropriate, in a block associated with the method.
A string containing the image data represented as a BLOB.
ImageToBlob
img.to_color(pixel) -> string
Returns the color name for a pixel. Unlike the
Pixel#to_color
method, to_color uses the depth attribute of the image to determine the color name.
A Pixel object.
A color name.
img = Magick::Image.read('ex/images/Flower_Hat.jpg').first #=> ex/images/Flower_Hat.jpg JPEG 200x250 DirectClass 8-bit 9761b pixel = img.pixel_color(img.columns/2, img.rows/2) #=> #<struct Pixel red=216, green=147, blue=106, opacity=0> img.to_color(pixel) #=> "#D8936A"
QueryColorname
img.transparent(color, opacity=TransparentOpacity) -> image
Changes the opacity value of all the pixels that match color to the value specified by opacity. By default the pixel must match exactly, but you can specify a tolerance level by setting the fuzz attribute on the image.
A new image
Mouse over the image to see the original. In this example, all the black pixels are made transparent. The resulting image has been composited over a plasma background, which shows through the transparent pixels.
matte_replace, Draw#matte, paint_transparent, transparent_chroma
TransparentPaintImage
img.transparent_chroma(low, high,
opacity=TransparentOpacity, invert=false
) -> image
Changes the opacity value associated with any pixel between low and high to the value defined by opacity.
As there is one fuzz value for the all the channels, the transparent method is not suitable for the operations like chroma, where the tolerance for similarity of two color components (RGB) can be different, Thus we define this method take two target pixels (one low and one high) and all the pixels of an image which are lying between these two pixels are made transparent.
A new image
TransparentPaintImageChroma (available in ImageMagick 6.4.5-6)
img.transpose -> image
Creates a horizontal mirror image by reflecting the pixels around the central y-axis while rotating them by 90 degrees.
A new image
flip, flop, rotate, transpose!, transverse
TransposeImage
img.transpose! -> self
img.transverse -> image
Creates a vertical mirror image by reflecting the pixels around the central x-axis while rotating them by 270 degrees
A new image
flip, flop, rotate, transpose, transverse!
TransposeImage
img.transverse! -> self
img.trim(reset=false) -> image
Removes the edges that are exactly the same color as the corner pixels. Use the fuzz attribute to make
trim
remove edges that are nearly the same color as the corner pixels.
The trim method retains the offset information in the cropped image. This may cause the image to appear to be surrounded by blank or black space when viewed with an external viewer. This only occurs when the image is saved in a format (such as GIF) that saves offset information. To reset the offset data, use true as the argument to trim. See also crop.
A new image
CropImage
img.trim!(reset=false) -> self
img.unique_colors -> image
Constructs a new image with one pixel for each unique color in the image. The new image has 1 row. The row has 1 column for each unique pixel in the image.
A new image
UniqueImageColors
img.unsharp_mask(radius=0.0, sigma=1.0, amount=1.0, threshold=0.05) -> image
Sharpens an image. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma). For reasonable results, radius should be larger than sigma. Use a radius of 0 and
unsharp_mask
selects a suitable radius for you.
All arguments are optional.
A new image
enhance, median_filter, reduce_noise, unsharp_mask_channel
UnsharpMaskImage
img.unsharp_mask_channel(radius=0.0, sigma=1.0, amount=1.0, threshold=0.05 [,channel...]) -> image
Sharpens an image. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma). For reasonable results, radius should be larger than sigma. Use a radius of 0 and
unsharp_mask_channel
selects a suitable radius for you.
Only the specified channels are sharpened.
All arguments are optional.
A new image
enhance, median_filter, reduce_noise, unsharp_mask
UnsharpMaskImageChannel
img.view(x, y, width,
height) -> aView
img.view(x, y, width,
height) { |view| block } -> nil
View
is a convenience method that supports getting and setting individual image pixels by [i][j]
coordinates. With no associated
block, view
returns an Image::View object. If the optional code block is given, it will be passed the
Image::View
object as an argument. The sync method will be called automatically when the block
terminates. In this case, view
returns nil
.
If the optional code block is present, view
returns nil
. If it is not present, view
returns an
Image::View
object.
The example image below has been scaled 500% for clarity.
img = Magick::Image.new(40, 40) { |options| options.background_color = 'lightcyan2'} # The view is 400 pixels square, starting at # column 10, row 5 from the top of the image. img.view( 10, 5, 20, 20) do |view| # Set all the pixels in the view to green. view[][] = Pixel.new(0, Magick::QuantumRange) # Change the top and bottom rows to red. view[0][] = 'red' view[-1,1][] = 'red' # Set 6 pixels to black. view[[13,15]][[12,14,16]] = 'black' # Set 1 pixel to yellow. view[5][7] = 'yellow' # Change the green channel of all the # pixels on row 8. view[8][].green = Magick::QuantumRange/2 # Change the blue channel of 8 pixels # on column 10. view[4,8][10].blue = Magick::QuantumRange end
pixel_color, get_pixels, store_pixels
The view
method introduces a relatively high level of overhead to pixel manipulation compared to methods that use the ImageMagick API to
identify and change pixels. I recommend that you use view
only when the number of pixels identified in the view is fairly small (a few
thousand to a few hundred thousand, depending on your patience and the speed of your computer) and you need this degree of control.
img.vignette(x, y, radius=0.0, sigma=10.0) -> image
Gradually shades the edges of the image by transforming the pixels into the background color.
A new image
VignetteImage
The image produced by vignette
is very similar to the image produced by RMagick's vignette.rb example script. However, the example script
gives you more control over the size, shape, and background color of the vignette.
img.watermark(mark, lightness=1.0, saturation=1.0,
x_offset=0, y_offset=0) -> image
img.watermark(mark, lightness=1.0, saturation=1.0,
gravity, x_offset=0, y_offset=0) -> image
Composites a watermark image on the target image using the Modulate composite operator. This composite operation operates in the HSL colorspace and combines part of the lightness, part of the saturation, and all of the hue of each pixel in the watermark with the corresponding pixel in the target image
Watermark can be called with a gravity argument or without. When a gravity argument is specified but the x- and y-offsets are omitted, the watermark is positioned based on the value of the gravity argument:
When the gravity argument is present and the x-offset (and optionally the y-offset) is present, the x- and y-offset are measured from the right and/or bottom edges of the target image based on the value of gravity. If the argument is NorthEastGravity, EastGravity, or SouthEastGravity, the x-offset is measured from the right side of the image. If the argument is SouthEastGravity, SouthGravity, or SouthWestGravity, the y-offset is measured from the bottom of the image. All other values are ignored and the x- and y-offset are measured from the upper-left corner of the image.
A new image
See "Water Marking".
img.wave(amplitude=25.0, wavelength=150.0) -> image
Creates a "ripple" effect in the image by shifting the pixels vertically along a sine wave whose amplitude and wavelength is specified by the given parameters.
A new image
WaveImage
img.wet_floor(initial=0.5, rate=1.0) -> image
Creates a "wet floor" reflection. The reflection is an inverted copy of the image that changes from partially transparent to entirely transparent. By default only the bottom third of the image appears in the reflection.
Note that the output image is just the reflection. This makes it easy to apply further transformations to the reflection before combining it with the original image.
A new image
Here are four examples of wet_floor
. The top image shows the result of appending the default reflection to the original image. The second
image shows the result of decreasing the initial transparency to 0.25 and using 0.5 as the rate argument. The third image uses
the same reflection as the second image but has a slant added. The bottom image is the same as the third image but with a ripple effect.
img.white_threshold(red_channel [, green_channel[, blue_channel[, opacity_channel]]]) -> image
Forces all pixels above the threshold into white while leaving all pixels below the threshold unchanged.
Each channel argument is a number between 0 and QuantumRange. All arguments except the first may be omitted. If the green_channel or blue_channel argument is omitted, the default value is the red_channel value. If the opacity_channel argument is omitted, the default value is OpaqueOpacity.
A new image
black_threshold, bilevel_channel
WhiteThresholdImage
img.write(filename) [ { optional arguments } ] -> self
img.write(file) [ { optional arguments } ] -> self
Writes the image to the specified file. ImageMagick determines image format from the prefix or extension.
If the argument is an open file, ImageMagick will write the image in its current format. You can force a different format by setting the image's format attribute.
A file name or open file object. You may also specify optional arguments by setting Image::Info attributes in an associated block.
self
, or nil
if the image format cannot be determined.
Almost all of the examples call write
.
When the argument is a filename, specify the output format via the filename extension (for example ".jpg" or ".gif") or by prefixing the filename with
the desired format (for example, "jpeg:myfile"), not via
format=
.
Do not use a StringIO object or a Tempfile object as the argument. Neither of these work. Use to_blob
to write to a String.
Instead of a tempfile, get the path of the tempfile from the path
method. Prefix the path with the desired image format. For example,
temp = Tempfile.new("image") img.write("jpeg:"+ temp.path)
WriteImage