class Pixie::Image
- Pixie::Image
- Reference
- Object
Included Modules
Defined in:
pixie/image.crConstructors
- .new(width : Int, height : Int, background_color : Pixel = Pixel::TRANSPARENT)
-
.new(wand : Pointer(LibMagick::MagickWand))
Creates a new
Image
from the givenLibMagick::MagickWand
instance. -
.new(image : Pointer(LibMagick::Image))
Creates a new
Image
from the givenLibMagick::Image
instance. -
.new(input : String | Bytes | IO)
Creates a new
Image
from the given stream. -
.new(images : Array(String) | Array(Bytes) | Array(IO))
Creates a new
Image
from the given Array, where each element is a layer in the image. -
.new(image : Image)
Creates a new
Image
from the givenPixie::Image
instance. -
.new
Creates a new
Image
with no data.
Class Method Summary
Instance Method Summary
- #==(other : Image)
- #[](index : Int)
- #[](format : String)
- #adaptive_blur(radius : Float, sigma : Float)
- #adaptive_resize(width : Int, height : Int, preserve_aspect_ratio : Bool = false)
- #adaptive_sharpen(radius : Float, sigma : Float)
- #adaptive_threshold(width : Int, height : Int, bias : Float)
- #add_image(image : Image)
- #add_noise(noise_type : LibMagick::NoiseType, attenuate : Float = 1.0)
- #affine_transform(brush : Brush)
- #animate(server_name : String = ":0")
- #annotate(brush : Brush, x : Float, y : Float, angle : Float, text : String)
- #append(top_to_bottom : Bool = false)
- #auto_gamma
- #auto_level
- #auto_orient
- #auto_threshold(method : LibMagick::AutoThresholdMethod)
-
#background_color
Return the background color of the image as a
Pixie::Pixel
. - #black_threshold(threshold : Pixel)
- #blob
- #blue_primary
- #blue_shift(factor : Float)
- #blur(radius : Float, sigma : Float)
-
#border(border_color : Pixel, width : Int, height : Int, compose : LibMagick::CompositeOperator = :undefined)
Add a border to the image using the given
Pixie::Pixel
. -
#border_color
Return the border color of the image as a
Pixie::Pixel
. - #brightness_contrast(brightness : Float, contrast : Float)
- #bytesize
- #canny_edge(radius : Float, sigma : Float, lower_percent : Float, upper_percent : Float)
- #channel_fx(expression : String)
- #charcoal(radius : Float, sigma : Float)
- #chop(width : Int, height : Int, x : Int, y : Int)
- #clahe(width : Int, height : Int, number_bins : Float, clip_limit : Float)
- #clamp
- #clear
- #clip
- #clip_path(pathname : String, inside : Bool = false)
- #clone
- #clut(clut : Image, method : LibMagick::PixelInterpolateMethod)
- #coalesce
- #collect_unique_colors
- #color_correct(collection : String)
- #color_matrix(matrix : LibMagick::KernelInfo)
- #colorize(colorize : Pixel, blend : Pixel)
- #colormap_color(index)
- #colors
- #colorspace
- #combine(colorspace : LibMagick::ColorspaceType)
- #comment(comment : String)
- #compare(reference : Image, metric : LibMagick::MetricType, distortion : Float)
- #compare_layers(method : LibMagick::LayerMethod)
- #complex(op : LibMagick::ComplexOperator)
- #composite(source : Image, operator : LibMagick::CompositeOperator, clip_to_self : Bool, x : Int, y : Int)
- #composite(source : Image, compose : LibMagick::CompositeOperator, gravity : LibMagick::GravityType)
- #composite_layers(source : Image, compose : LibMagick::CompositeOperator, x : Int, y : Int)
- #composite_operator
- #compression
- #compression_quality
- #connected_components(connectivity : Int)
- #constitute(columns : Int, rows : Int, map : String, storage : LibMagick::StorageType, pixels : Array(U)) forall U
- #contrast(sharpen : Bool)
- #contrast_stretch(black_point : Float, white_point : Float)
- #convolve(kernel : LibMagick::KernelInfo)
- #crop(width : Int, height : Int, x : Int, y : Int)
- #cycle_colormap(displace : Int)
- #decipher(passphrase : String)
- #deconstruct
- #delay
- #delete_property(name : String)
- #depth
- #deskew(threshold : Float)
- #despeckle
- #display(x_server : String = ":0")
- #displays(x_server : String = ":0")
- #dispose
- #distort(method : LibMagick::DistortMethod, args : Array(Float64), best_fit : Bool = false)
- #distortion(reference : Wand, metric : LibMagick::MetricType)
- #distortions(reference : Wand, metric : LibMagick::MetricType, channel : LibMagick::ChannelType)
- #draw(brush : Brush)
- #draw(&block : Brush -> )
- #edge(radius : Float = 0.0)
- #emboss(radius : Float = 0.0, sigma : Float = 0.0)
- #encipher(passphrase : String)
- #endian
- #enhance
- #enhance_local_contrast(radius : Float64, strength : Float64)
- #equalize
- #evaluate(operator : LibMagick::MagickEvaluateOperator, value : Float)
- #evaluate(operator : LibMagick::MagickEvaluateOperator)
- #exif
- #extent(width : Int, height : Int, x : Int, y : Int)
- #features(distance)
- #filename
- #finalize
- #flip
- #flood_fill_paint(fill : Pixel, fuzz : Float, border_color : Pixel, x : Int, y : Int, invert : Bool = false)
- #flop
- #format
- #forward_fourier_transform(magnitude : Float)
- #frame(matte_color : Pixel, width : Int, height : Int, inner_bevel : Int, outer_bevel : Int, compose : LibMagick::CompositeOperator)
- #function(function : LibMagick::MagickFunction, args : Array(Float64))
- #fuzz
- #fx(expression : String)
- #gamma(gamma : Float)
- #gamma
- #gaussian_blur(radius : Float, sigma : Float)
- #get_region(width, height, x, y)
- #gravity
- #green_primary
- #has_alpha?
-
#has_next?
Returns true if there are multiple images in the image set, and
#pos
is less than the number of images. -
#has_prev?
Returns true if there are multiple images in the image set, and
#pos
is greater than zero. -
#hash
Generates an
UInt64
hash value for this object. - #height
- #histogram(n_colors = nil)
- #hough_line(width, height, threshold)
- #identify
- #identify_type
- #image_similarity(reference : Wand, metric : LibMagick::MetricType, threshold : Float64)
- #implode(radius, method : PixelInterpolateMethod = :average)
- #import_pixels(pixels : Iterable(Int), width, height, depth : Int, map : String = "RGB")
- #intent
- #interlace_scheme
- #interpolative_resize(width, height, method : LibMagick::PixelInterpolateMethod = :average, preserve_aspect_ratio : Bool = false)
- #inverse_fourier_transform(phase_image : Pixie::Wand, magnitude = false)
- #iterations
-
#kurtosis
TODO Figure out how to specify a channel
- #kuwahara_filter(radius : Float64, sigma : Float64)
- #label(label : String)
-
#layers
Returns an
Array(Image)
, where each image is a layer in the image. - #level(black_point : Float64, gamma : Float64, white_point : Float64)
- #level_colors(black_color : Pixel, white_color : Pixel, invert = false)
- #levelize(black_point : Float64, white_point : Float64, gamma : Float64)
- #linear_stretch(black_point : Float64, white_point : Float64)
- #liquid_rescale(width : Int, height : Int, delta_x : Float64 = 0.0, rigidity : Float64 = 0.0)
- #lower(width : Int, height : Int, x : Int, y : Int)
- #magnify
- #matte_color
- #mean
- #mean_shift(width : Int, height : Int, color_distance : Float64)
- #merge_layers(method : LibMagick::LayerMethod = :merge)
- #minify
- #modulate(brightness : Float64, saturation : Float64, hue : Float64)
- #montage(thumbnail_geometry : String | Nil = nil, tile_geometry : String | Nil = nil, brush : Brush = Brush.new, mode : LibMagick::MontageMode = :undefined, frame : String | Nil = nil)
- #morphology(n_frames : Int)
- #morphology_method(method : LibMagick::MorphologyMethod, iterations : Int, kernel : Pointer(LibMagick::KernelInfo))
- #motion_blur(radius : Float64, sigma : Float64, angle : Float64)
- #negate(gray : Bool)
- #next
- #normalize
- #oil_paint(radius : Float64, sigma : Float64)
- #opaque_paint(target_color : Pixel, fill_color : Pixel, fuzz : Float64, invert : Bool = false)
- #optimize_layers
- #optimize_transparency
- #ordered_dither(threshold_map : String)
- #orientation
- #page
-
#path : String | Nil
The location of the current working file
- #pixel(x, y)
- #pixel_interpolation_method
- #pixels(x : Int = 0, y : Int = 0, columns : Int = width, rows : Int = height, map : String = "RGB", storage : LibMagick::StorageType = :char)
- #polaroid(brush : Brush, caption : String, angle : Float64, method : LibMagick::PixelInterpolateMethod = :average)
- #polynomial(n_terms : Int, terms : Float64)
- #pos
- #posterize(levels : Int, dither_method : LibMagick::DitherMethod = :none)
- #prev
- #preview_transform(type : LibMagick::PreviewType)
- #property(name : String)
- #quantize(n_colors : Int, colorspace : LibMagick::ColorspaceType, treedepth : Int, dither_method : LibMagick::DitherMethod = :none, measure_error : Bool = false)
- #quantize_all(n_colors : Int, colorspace : LibMagick::ColorspaceType, treedepth : Int, dither_method : LibMagick::DitherMethod = :none, measure_error : Bool = false)
- #query_fonts(pattern : String)
- #query_formats(pattern : String)
- #raise(width : Int, height : Int, x : Int, y : Int)
- #random_threshold(low : Float64, high : Float64)
- #range
- #range_threshold(low_black : Float64, low_white : Float64, hight_white : Float64, hight_black : Float64)
- #read(filename : String)
- #read(buffer : IO)
- #read(buffer : Bytes)
- #red_primary
- #remap(affinity : Wand, method : LibMagick::DitherMethod = :none)
- #remove
- #resample(x_resolution : Float64, y_resolution : Float64, filter : LibMagick::FilterType)
- #reset_page(page : String)
- #resize(width : Int, height : Int, filter : LibMagick::FilterType = :lanczos)
- #resize_to_fit(width : Int, height : Int, filter : LibMagick::FilterType = :lanczos)
- #resolution
- #rewind
- #roll(x : Int, y : Int)
- #rotate(background : Pixel, degrees : Float64)
- #rotational_blur(angle : Float64)
- #sample(width : Int, height : Int)
- #scale(width : Int, height : Int)
- #scene
- #segment(colorspace : LibMagick::ColorspaceType, cluster_threshold : Float64, smooth_threshold : Float64, verbose = false)
- #selective_blur(radius : Float64, sigma : Float64, threshold : Float64)
- #separate(channel : LibMagick::ChannelType)
- #sepia(threshold : Float64)
- #set(image : Wand)
- #set_alpha(value : LibMagick::AlphaChannelOption)
- #set_artifact(key : String, value : String)
-
#set_background_color(background : Pixel)
Set the background color of the image to the given
Pixie::Pixel
. - #set_blue_primary(x, y, z)
-
#set_border_color(color : Pixel)
Set the border color of the image to the given
Pixie::Pixel
. - #set_color(color : Pixel)
- #set_colormap_color(index : Int, color : Pixel)
- #set_colorspace(colorspace : LibMagick::ColorspaceType)
- #set_composite_operator(op : LibMagick::CompositeOperator)
- #set_compression(value : LibMagick::CompressionType)
- #set_compression_quality(quality : Int)
- #set_delay(val : Int)
- #set_depth(val : Int)
- #set_dispose(val : LibMagick::DisposeType)
- #set_endian(val : LibMagick::EndianType)
- #set_extent(width : Int, height : Int)
- #set_filename(val : String)
- #set_format(val : String)
- #set_fuzz(val : Float64)
- #set_gamma(val : Float64)
- #set_gravity(val : Float64)
- #set_green_primary(x, y, z)
- #set_intent(val : LibMagick::RenderingIntent)
- #set_interlace_scheme(val : LibMagick::InterlaceType)
- #set_iterations(val : Int)
- #set_matte(val : Bool)
- #set_matte_color(val : Pixel)
- #set_orientation(val : LibMagick::OrienationType)
- #set_page(width : Int, height : Int, x : Int, y : Int)
- #set_pixel(x : Int, y : Int, color : Pixel)
- #set_pixel_interpolation_method(val : LibMagick::PixelInterpolateMethod)
- #set_pos(index : Int)
- #set_property(name : String, value : String)
- #set_red_primary(x, y, z)
- #set_resolution(x : Float64, y : Float64)
- #set_scen(scene : Int)
- #set_ticks_per_second(val : Int)
- #set_type(val : LibMagick::ImageType)
- #set_units(val : LibMagick::ResolutionType)
- #set_virtual_pixel_method(val : LibMagick::VirtualPixelMethod)
- #set_white_point(x : Float64, y : Float64, z : Float64)
- #shade(azimuth : Float64, elevation : Float64, gray : Bool = false)
- #shadow(alpha : Float64, sigma : Float64, x : Int, y : Int)
- #sharpen(radius : Float64, sigma : Float64)
- #shave(width : Int, height : Int)
- #shear(background : Pixel, x : Float64, y : Float64)
- #sigmoidal_constrast(alpha : Float64, beta : Float64, sharpen : Bool = false)
- #signature
- #size
- #sketch(radius : Float64, sigma : Float64, angle : Float64)
- #smush(offset : Int, stack : Bool = false)
- #solarize(threshold : Float64)
- #sparse_color(method : LibMagick::SparseColorMethod, args : Array(Float64))
- #splice(width : Int, height : Int, x : Int, y : Int)
- #spread(method : LibMagick::PixelInterpolateMethod, radius : Float64)
- #statistic(type : LibMagick::StatisticType, width : Int, height : Int)
- #statistics(channel : LibMagick::ChannelType)
- #stego(watermark : Wand, offset : Int)
- #stereo(offset : Wand)
- #strip
- #swirl(degrees : Float64, method : LibMagick::PixelInterpolateMethod)
- #texture(texture : Wand)
- #threshold(threshold : Float64)
- #threshold_channel(channel : LibMagick::ChannelType, threshold : Float64)
- #thumbnail(width : Int, height : Int)
- #ticks_per_second
- #tint(tint : Pixel, blend : Pixel)
- #to_io
- #to_unsafe : Pointer(LibMagick::MagickWand)
- #to_unsafe_image
- #total_ink_density
- #transform_colorspace(colorspace : LibMagick::ColorspaceType)
- #transparent_paint(target : Pixel, alpha : Float64, fuzz : Float64, invert : Bool = false)
- #transpose
- #transverse
- #trim(fuzz : Float64)
- #type
- #units
- #unsharp_mask(radius : Float64, sigma : Float64, gain : Float64, threshold : Float64)
- #vignette(radius : Float64, sigma : Float64, x : Int, y : Int)
- #virtual_pixel_method
- #wave(amplitude : Float64, length : Float64, method : LibMagick::PixelInterpolateMethod)
- #wavelet_denoise(threshold : Float64, softness : Float64)
- #white_point
- #white_threshold(threshold : Pixel)
- #width
- #write(path : String)
- #xmp
Class methods inherited from module Pixie::Helpers
assert_no_exception(exception_info : LibMagick::ExceptionInfo)
assert_no_exception
Constructor Detail
Creates a new blank image using the given width, height, and background color. The default background color is transparent, and the format is set to PNG.
Example:
image = Image.new(640, 480, Pixel::RED)
Creates a new Image
from the given LibMagick::MagickWand
instance.
Creates a new Image
from the given LibMagick::Image
instance.
Creates a new Image
from the given stream. See Image#read
for
more information.
Creates a new Image
from the given Array, where each element is
a layer in the image.
Creates a new Image
from the given Pixie::Image
instance.
Creates a new Image
with no data. This is the underlying method
used by all other constructors.
Class Method Detail
Instance Method Detail
Get the individual image (layer) at the given index.
Example:
image = Image.new("/path/to/image.gif")
image[0] # => Image
Get image details using special formatting characters. See https://imagemagick.org/script/escape.php
Example:
image = Image.new("/path/to/image.png")
image["%w"] # => "640"
image["%h"] # => "480"
image["%f"] # => "image.png"
Add noise to the image. Valid noise types are:
:undefined
:uniform
:gaussian
:multiplicative_gaussian
:impulse
:laplacian
:poisson
:random
Automatically threshold the image using the given method. Valid methods are:
:undefined
:kapur
:ohtsu
:triangle
Add a border to the image using the given Pixie::Pixel
.
a variant of adaptive histogram equalization in which the contrast amplification is limited, so as to reduce this problem standard non-contrast limited AHE.
Clips along the named paths from the 8BIM profile, if present. Later operations take effect inside the path. Id may be a number if preceded with #, to work on a numbered path, e.g., "#1" to use the first path.
Composites a set of images while respecting any page offsets and disposal methods. GIF, MIFF, and MNG animation sequences typically start with an image background and each subsequent image varies in size and offset. Returns a new sequence where each image in the sequence is the same size as the first and composited with the next image in the sequence.
accepts a lightweight Color Correction Collection (CCC) file which solely contains one or more color corrections and applies the color correction to the image. Here is a sample CCC file:
<ColorCorrectionCollection xmlns="urn:ASC:CDL:v1.2">
<ColorCorrection id="cc03345">
<SOPNode>
<Slope> 0.9 1.2 0.5 </Slope>
<Offset> 0.4 -0.5 0.6 </Offset>
<Power> 1.0 0.8 1.5 </Power>
</SOPNode>
<SATNode>
<Saturation> 0.85 </Saturation>
</SATNode>
</ColorCorrection>
</ColorCorrectionCollection>
which includes the offset, slope, and power for each of the RGB channels as well as the saturation.
Apply color transformation to an image. The method permits saturation changes, hue rotation, luminance to alpha, and various other effects. Although variable-sized transformation matrices can be used, typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA (or RGBA with offsets). The matrix is similar to those used by Adobe Flash except offsets are in column 6 rather than 5 (in support of CMYKA images) and offsets are normalized (divide Flash offset by 255).
Combines one or more images into a single image. The grayscale value of the pixels of each image in the sequence is assigned in order to the specified channels of the combined image. The typical ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
Compares each image with the next in a sequence and returns the maximum bounding region of any pixel differences it discovers.
Performs complex mathematics on an image sequence using the given oprtator. Valid operators are:
:undefined
:add
:conjugate
:divide
:magnitude_phase
:multiply
:real_imaginary
:subtract
Composites two images together using the given operator.
See Image#complex
for a list of valid operators.
Composites two images together using the given operator and gravity.
See Image#complex
for a list of valid operators. Valid
gravities are:
:undefined
:forget
:north_west
:north
:north_east
:west
:center
:east
:south_west
:south
:south_east
:static
Composite the images in the source wand over the images in the destination wand in sequence, starting with the current image in both lists. Each layer from the two image lists are composted together until the end of one of the image lists is reached. The offset of each composition is also adjusted to match the virtual canvas offsets of each layer. As such the given offset is relative to the virtual canvas, and not the actual image. Composition uses given x and y offsets, as the 'origin' location of the source images virtual canvas (not the real image) allowing you to compose a list of 'layer images' into the destination images. This makes it well suitable for directly composing 'Clears Frame Animations' or 'Coalesced Animations' onto a static or other 'Coalesced Animation' destination image list. GIF disposal handling is not looked at.
Special case:- If one of the image sequences is the last image (just a single image remaining), that image is repeatedly composed with all the images in the other image list. Either the source or destination lists may be the single image, for this situation. In the case of a single destination image (or last image given), that image will be cloned to match the number of images remaining in the source image list. This is equivalent to the "-layer Composite" Shell API operator.
For a list of valid operators, see Image#complex
.
Returns the connected-components of the image uniquely labeled. The returned connected components image colors member defines the number of unique objects. Choose from 4 or 8-way connectivity.
Adds an image to the wand comprised of the pixel data you supply. The pixel data must be in scanline order top-to-bottom. The data can be char, short int, int, float, or double. Float and double require the pixels to be normalized [0..1], otherwise [0..Max], where Max is the maximum value the type can accomodate (e.g. 255 for char).
For example, to create a 640x480 image from unsigned red-green-blue character data:
image = Image.new
data = Array(UInt8).new(640 * 480 * 3) { 0u8 }
image.constitute(640, 480, "RGB", :char, data)
Enhances the intensity differences between the lighter and darker elements of the image. Set sharpen to a value other than 0 to increase the image contrast otherwise the contrast is reduced.
Enhances the contrast of a color image by adjusting the pixels color to span the entire range of colors available. You can also reduce the influence of a particular channel with a gamma value of 0.
Displaces an image's colormap by a given number of positions. If you cycle the colormap a number of times you can produce a psychodelic effect.
Compares each image with the next in a sequence and returns the maximum bounding region of any pixel differences it discovers.
Delete a specific property of the image.
Example:
image = Image.new("/path/to/image.png")
image.delete_property("exif:GPSLatitude")
Removes skew from the image. Skew is an artifact that occurs in scanned images because of the camera being misaligned, imperfections in the scanning or surface, or simply because the paper was not placed completely flat when scanned.
Distorts an image using various distortion methods, by mapping color lookups of the
source image to a new destination image usally of the same size as the source
image, unless best_fit
is set to true.
Valid distortion methods are:
:undefined
:affine
:affine_projection
:scale_rotate_translate
:perspective
:perspective_projection
:bilinear_forward
:bilinear_reverse
:polynomial
:arc
:polar
:de_polar
:cylinder2plane
:plane2cylinder
:barrel
:barrel_inverse
:shepards
:resize
:sentinel
Example:
image = Image.new("/path/to/image.png")
image.distort(:affine, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
Enhances edges within the image with a convolution filter of the given radius. Using a radius of 0 will select a suitable radius for you.
Enhance edges within the image with a convolution filter of the given radius and sigma. Using a radius of 0 will select a suitable radius for you.
Extend the image as defined by the geometry, gravity, and wand background color. Set the (x,y) offset of the geometry to move the original wand relative to the extended wand.
Returns true if there are multiple images in the image set, and
#pos
is less than the number of images.
Returns true if there are multiple images in the image set, and
#pos
is greater than zero.
Generates an UInt64
hash value for this object.
This method must have the property that a == b
implies a.hash == b.hash
.
The hash value is used along with #==
by the Hash
class to determine if two objects
reference the same hash key.
Subclasses must not override this method. Instead, they must define hash(hasher)
,
though usually the macro def_hash
can be used to generate this method.
Returns an Array(Image)
, where each image is a layer in the image. Useful for
gif
, pdf
, psd
, and any other image format with layers.
Example:
image = Image.new("/path/to/image.gif")
image.layers # => Array(Image)
Extract pixel data from the image and return it as a multi-dimensional array of rows and columns, each containing an array of pixel data represnting the given map (defaulting to RGB). The map can be any combination or order of:
- R = red
- G = green
- B = blue
- A = alpha (0 is transparent)
- O = opacity (0 is opaque)
- C = cyan
- Y = yellow
- M = magenta
- K = black
- I = intensity (for grayscale)
- P = pad
Example:
image = Image.new("/path/to/image.png")
image.pixels.each do |row|
row.each do |col|
puts col # => [255, 255, 255]
end
end
Get a specific property of the image.
Example:
image = Image.new("/path/to/image.png")
image.property("date:create") # => "2019:01:01 12:00:00"
Set the image's alpha channel to the given LibMagick::AlphaChannelOption
.
Valid options are:
:undefined
:activate
:associate
:background
:copy
:deactivate
:discrete
:disassociate
:extract
:off
:on
:opaque
:remove
:set
:shape
:transparent
Set the background color of the image to the given Pixie::Pixel
.
Set the border color of the image to the given Pixie::Pixel
.
Example:
image = Image.new("/path/to/image.png")
image.border_color = Pixel::RED
Set a specific property of the image.
Example:
image = Image.new("/path/to/image.png")
image.set_property("exif:GPSLatitude", "40/1, 43/1, 54/1")