View Source Image (image v0.28.0)
Image is based upon the fabulous
vix library that provides a libvips
wrapper for Elixir.
Image is intended to provide well-documented common image processing functions in
an idiomatic Elixir functional style as a layer above the very comprehensive set
of functions in Vix and libvips.
In a very simple image resizing
benchmark,
Image is approximately 2 to 3 times faster than Mogrify and uses about 5 times
less memory.
Link to this section Summary
Types
Image orientation.
Error messages returned by libvips
The data type of the image, using the same
type definitions as Nx.Type.t/0.
The valid sources of image data when opening an image.
A 512 bit binary hash of an image.
Represents either in image, or a color that is used to fill a new image
THe structure of an image returned from Kino.Input.read/1
when the input field is a Kino.Input.image/1 type.
A pixel is represented as a list of number values or a single number (which is then assumed to be the value for all bands).
An image bounding box being a four element list of 2-tuples representing the points of a rectangle in the order top left -> top right -> bottom right -> bottom left.
The valid rendering intent values. For all
functions that take an optional intent
parameter the default is :perceptual.
The x location on an image which is either a
non_negative 0-based integer relative to the image left or
a negative -1-based integer relative to the image right or
the symbolic references :left, :center and
:right.
The y location on an image which is either a
non_negative 0-based integer relative to the image top or
a negative -1-based integer relative to the image right or
the symbolic references :top, :middle and
:bottom.
Files and streams
Returns an image created from an in-memory binary representation of an image.
Returns an image created from an in-memory binary representation of an image or raises an exception.
Create a new image of the same shape as the provided image.
Create a new image of the given dimensions.
Return a new image of the same shape as the provided image or raise an exception.
Return a new image of the given dimensions and background color or raise an exception.
Opens an image file or stream for image processing.
Opens an image file for image processing returning an image or raising an exception.
Convert an image into an enumerable stream.
Write an image to a file, a stream, an enumerable or to memory.
Write an image to a file, a stream, an enumerable or to memory returning the image or raising an exception.
Operations
Add an alpha band to an image.
Add an alpha band to an image.
Scales each band of an image to fit the full
dynamic range. Unlike Image.normalize/1, each
band is scaled separately.
Scales each band of an image to fit the full
dynamic range. Unlike Image.normalize/1, each
band is scaled separately. Raises an exception
on error.
Rotate an image based upon the orientation information in an image's EXIF data.
Rotate an image based upon the orientation information in an image's EXIF data. Returns a potentially rotated image or raises and exception.
Applies a gaussian blur to an image.
Applies a gaussian blur to an image.
Automatically determine the chroma key color of an image.
Chroma key an image.
Chroma key an image and return an image or raise an exception.
Return a chroma-based masked image.
Return a chroma-based masked image or raises an exception.
Compose two images together to form a new image.
Compose two images together to form a new image or raise an exception.
Dilate an image mask, adding a pixels to the edge of the mask.
Dilate an image mask, adding a pixels to the edge of the mask or raising an exception.
Embeds an image in a larger image canvas, generating addition border pixels if required.
Erode an image mask, removing pixels from the edge of the mask.
Erode an image mask, removing pixels from the edge of the mask or raising an exception.
Feather (blur the edges) of an image mask.
Feather (blur the edges) of an image mask returning an image or raising an exception.
Returns the fast fourier transform (fft) of the given image.
Returns the fast fourier transform (fft) of the given image returning an image or raising an exception.
Flatten an alpha layer out of an image.
Flatten an alpha layer out of an image or raises an exception.
Flip an image horizontally or vertically.
Flip an image horizontally or vertically returning a flipped image or raising an exception.
Returns the pixel value at the given image location.
Returns the pixel value at the given image location or raises an exception.
Returns the hamming distance of two images or two image hashes.
Returns the histogram for an image.
Scans the condition image cond and uses it to select
pixels from either the then if_image or the else_image.
Applies a transformation matrix to an image.
Mutate an image with through the given function.
Normalize an image by expanding the luminance of an image to cover the full dynamic range.
Normalize an image by expanding the luminance of an image to cover the full dynamic range. Raises an exception on error.
Pixelates an image.
Pixelates an image or raise an exception.
Adds a concentric ripple effect to an image.
Adds a concentric ripple effect to an image returning an image or raising an exception.
Rotate an image clockwise (to the right) by a number of degrees.
Rotate an image clockwise (to the right) by a number of degrees.
Attempts top determine the distance from the perpendicular for a given image.
Split an image to separate the alpha band from the other image bands.
Performs a warp perspective transformation on an image to straighten its perspective.
Performs a warp perspective transformation on an image to straighten its perspective or raises an exception.
Convert image to polar coordinates.
Convert image to polar coordinates returning an image or raising an exception.
Convert image to rectangular coordinates.
Convert image to rectangular coordinates returning an image or raising an exception.
Returns a transformation matrix for a given image, source quadrilateral and desintation quadrilateral.
Performs a warp perspective transformation on an image.
Performs a warp perspective transformation on an image or raises an exception.
Resize
Embeds an image in a larger image canvas, generating addition border pixels if required.
Resize an image.
Resize an image or raise an exception.
Thumbnail an image to fit or fill a bounding box.
Thumbnail an image to fit or fill a bounding box returning an image or raising an exception.
Trims an image to the bounding box of the non-background area.
Trims an image to the bounding box of the non-background area.
Crop
Crops the center from an image.
Crops the center from an image.
Crop an image.
Crop an image.
Crop an image or raises an exception.
Crop an image returning a cropped image or raising an exception.
Transforms
Make a circular or square image intended to be used as an avatar image.
Make a circular or square image intended to be used as an avatar image or raise an exception.
Create an image gradient of the same size as the given image.
Create an image gradient of the same size as the given image. Returns the gradient image or raises and exception.
Create a meme image from a base image and one or two lines of text.
Return a meme image from a base image and one or two lines of text or raise an exception.
Returns a radial gradient as an image.
Apply rounded corners to an image.
Split & Join
Returns the band number of the alpha channel of an image, or nil if it doesn't have one.
Split the image into a list of its component bands.
Color
Converts an image to the given colorspace.
Converts an impage to the given colorspace returning an image or raising an exception.
Information
Returns the aspect of an image.
Return the number of bands in an image.
Returns the dominant color of an image as an RBG triplet value in an integer list.
Returns the filename for an image.
Returns a boolean based upon whether a given image has an alpha band.
Returns the height of an image.
Returns the image interpretation.
Returns the shape of an image.
Returns the data type of the image pixels.
Returns the width of an image.
Masks
Apply a circular mask to an image.
Apply a circular mask to an image returning an image or raising an exception.
Convert an image into a mask.
Convert an image into a mask returning an image or raising an exception.
Apply rounded corners to an image. Returns an image or raises an exception.
Nx & Evision
Converts to an Image image from an Evision.Mat image.
Converts an Nx tensor into an image.
Converts an image into an Nx tensor.
Converts an image into an Nx tensor.
Preview
Outputs an inline preview of an image to an iTerm2 terminal.
Outputs an inline preview of an image to an iTerm2 terminal.
Guards
Guards whether the coordinates can be reasonably interpreted as a bounding box.
Guards whether a value is a percentage as representeed
by a float between -1.0 and 1.0.
Guards whether a term might be reasonably interpreted as an image pixel.
Guards whether a value is a positive percentage as representeed
by a float greater than 0.0 and less than or equal to 1.0.
Guards whether a parameter is a rectangular bounding box. A rectangular bounding box is a list of four 2-tuples that must represent a rectangle (not an arbitrary quadrilateral),
Guards whether a number can be reasonably interpreted as a size (as in size of a crop or mask)
libvips Configuration
Returns the number of operating system
threads available for use by libvips.
Sets the number of available threads for use
by libvips.
Returns the version of libvips in
operation.
Functions
Returns the average color of an image.
Returns the average color of an image or raises and exception.
Returns an image from a Kino image input.
Returns an image from a Kino image input or raises an exception.
Guards whether the given struct is an image type
either Vix.Vips.Image or Vix.Vips.MutableImage.
Execute a function over the image without its alpha band (if any) ensuring the alpha band is replaced when the function returns.
Link to this section Types
@type aspect() :: :landscape | :portrait | :square
Image orientation.
@type error_message() :: term()
Error messages returned by libvips
Typically a string.
@type format() :: {:u | :s | :f | :c | :bf, 8 | 16 | 32 | 64 | 128}
The data type of the image, using the same
type definitions as Nx.Type.t/0.
@type image_data() :: Path.t() | File.Stream.t() | binary()
The valid sources of image data when opening an image.
@type image_hash() :: binary()
A 512 bit binary hash of an image.
Useful for comparing the similarity of
two images. See Image.dhash/1 and
Image.hamming_distance/2.
@type image_or_color() :: Vix.Vips.Image.t() | Image.Color.t()
Represents either in image, or a color that is used to fill a new image
@type kino_image() :: %{ data: binary(), width: pos_integer(), height: pos_integer(), format: :rgb }
THe structure of an image returned from Kino.Input.read/1
when the input field is a Kino.Input.image/1 type.
A pixel is represented as a list of number values or a single number (which is then assumed to be the value for all bands).
The number of list elements is determined by the colorspace interpretations. For example:
RGBcolorspace would be represented by a list of three floats like[0.0, 0,0, 0.0]for black.CMYKcolorspace would be represented by a list of four floats.A
PNGimage can be in any appropriate colorspace but may also have analphaband and therefore have three, four or five floats in a list to represent the pixel.
@type quadrilateral() :: [{x :: non_neg_integer(), y :: non_neg_integer()}, ...]
An image bounding box being a four element list of 2-tuples representing the points of a rectangle in the order top left -> top right -> bottom right -> bottom left.
@type render_intent() :: :perceptual | :relative | :saturation | :absolute
The valid rendering intent values. For all
functions that take an optional intent
parameter the default is :perceptual.
perceptual-intent
Perceptual Intent
Perceptual rendering is used to process photographic type images. This intent processes the colors so that the output reproduction is pleasing. This process tends to change the color from the original, so no guarantee the reproduction will be accurate against the original.
relative-intent
Relative Intent
Relative colorimetric changes all the colours out of gamut to the nearest colour in gamut, so many colours change to the same one. It DOES NOT change colours in gamut. Perceptual changes ALL the colours in the image in a proportional way so that they lie in the output device gamut.
saturation-intent
Saturation Intent
Saturation moves in-gamut colors toward the edge of the destination gamut for maximum saturation and impact. This intent will make an image more colorful by using the full gamut of the destination device. This intent cares not for the genuine representation of color.
absolute-intent
Absolute Intent
Absolute rendering attempts to reproduce all colors numerically (destination = source). This can cause unexpected results if the source gamut is larger than the destination.
@type x_location() :: integer() | :left | :center | :right
The x location on an image which is either a
non_negative 0-based integer relative to the image left or
a negative -1-based integer relative to the image right or
the symbolic references :left, :center and
:right.
@type y_location() :: integer() | :top | :middle | :bottom
The y location on an image which is either a
non_negative 0-based integer relative to the image top or
a negative -1-based integer relative to the image right or
the symbolic references :top, :middle and
:bottom.
Link to this section Files and streams
@spec from_binary( binary :: binary(), options :: Image.Options.Open.image_open_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Returns an image created from an in-memory binary representation of an image.
The binary must be a complete formatted image such as that
returned from File.read!/1.
arguments
Arguments
binaryis a binary representation of a formatted image including.jpg,.png,.webpand.svgbinary data.optionsis a keyword list of options. SeeImage.open/2for the list of applicable options.
returns
Returns
{:ok, image}or{:error, reason}
@spec from_binary!( binary :: binary(), options :: Image.Options.Open.image_open_options() ) :: Vix.Vips.Image.t() | no_return()
Returns an image created from an in-memory binary representation of an image or raises an exception.
binaryis a binary representation of a formatted image including.jpg,.png,.webpand.svgbinary data.
arguments
Arguments
binaryis a binary representation of a formatted imageoptionsis a keyword list of options. SeeImage.open/2for the list of applicable options.
returns
Returns
imageorraises an exception.
@spec new(image :: %Vix.Vips.Image{ref: term()}) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Create a new image of the same shape as the provided image.
The function creates a new image with the same width, height and bands as the image argument.
arguments
Arguments
imageis anyVix.Vips.Image.t/0from which the new imageswidthandheightandbandswill be derived.optionsis a keyword list of options.
options
Options
:bandsdefines the number of bands (channels) to be created. The default is the number of bands inimage.:colordefines the color of the image. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The default is0, meaning black. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. SeeImage.Color.color_map/0andImage.Color.rgb_color/1.:formatdefines the format of the image. The default is{:u, 8}.:interpretationdefines the interpretation of the image. The default is:srgb.
returns
Returns
{:ok, image}or{:error, reason}
@spec new(width :: pos_integer(), height :: pos_integer()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
@spec new(image :: %Vix.Vips.Image{ref: term()}, options :: Image.Options.New.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Create a new image of the given dimensions.
arguments
Arguments
Either width and height OR image should be
provided.
widthis the image width as an integer.heightis the image height as an integer.imageis an image from which thewidth,heightare derived.optionsis a keyword list of options.
options
Options
:colordefines the color of the image. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The default is0, meaning black. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. SeeImage.Color.color_map/0andImage.Color.rgb_color/1.:bandsdefines the number of bands (channels) to be created. The default is the number of bands of:coloroption or if:coloris an integer then the default value is3.:formatdefines the format of the image. The default is{:u, 8}.:interpretationdefines the interpretation of the image. The default is:srgb.
returns
Returns
{:ok, image}or{:error, reason}
notes
Notes
- Either
widthandheightORimageshould be provided as arguments but NOT both.
examples
Examples
# 100x100 pixel image of dark blue slate color
iex> {:ok, _image} = Image.new(100, 100, color: :dark_slate_blue)
# 100x100 pixel green image, fully transparent
iex> {:ok, _image} = Image.new(100, 100, color: [0, 255, 0, 1], bands: 4)
@spec new( width :: pos_integer(), height :: pos_integer(), options :: Image.Options.New.t() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Return a new image of the same shape as the provided image or raise an exception.
The function creates a new image with the same width, height and bands as the image argument.
arguments
Arguments
imageis anyVix.Vips.Image.t/0from which the new imageswidthandheightandbandswill be derived.optionsis a keyword list of options.
options
Options
:bandsdefines the number of bands (channels) to be created. The default is the number of bands inimage.:colordefines the color of the image. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The default is0, meaning black. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. SeeImage.Color.color_map/0andImage.Color.rgb_color/1.:formatdefines the format of the image. The default is{:u, 8}.:interpretationdefines the interpretation of the image. The default is:srgb.
returns
Returns
{:ok, image}or{:error, reason}
@spec new!(width :: pos_integer(), height :: pos_integer()) :: Vix.Vips.Image.t() | no_return()
@spec new!(image :: %Vix.Vips.Image{ref: term()}, options :: Image.Options.New.t()) :: Vix.Vips.Image.t() | no_return()
Return a new image of the given dimensions and background color or raise an exception.
arguments
Arguments
Either width and height OR image should be
provided.
widthis the image width as an integer.heightis the image height as an integer.imageis an image from which thewidth,heightre derived.optionsis a keyword list of options.
options
Options
:bandsdefines the number of bands (channels) to be created. The default is3.:colordefines the color of the image. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The default is0, meaning black. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. SeeImage.Color.color_map/0andImage.Color.rgb_color/1.:formatdefines the format of the image. The default is{:u, 8}.:interpretationdefines the interpretation of the image. The default is:srgb.
returns
Returns
{:ok, image}or{:error, reason}
notes
Notes
- Either
widthandheightORimageshould be provided as arguments but NOT both.
examples
Examples
# 100x100 pixel image of dark blue slate color
iex> {:ok, _image} = Image.new(100, 100, color: :dark_slate_blue)
# 100x100 pixel green image, fully transparent
iex> {:ok, _image} = Image.new(100, 100, color: [0, 255, 0, 1], bands: 4)
@spec new!( width :: pos_integer(), height :: pos_integer(), options :: Image.Options.New.t() ) :: Vix.Vips.Image.t() | no_return()
@spec open( path_or_stream_or_binary :: image_data(), options :: Image.Options.Open.image_open_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Opens an image file or stream for image processing.
arguments
Arguments
image_path_or_stream_or_binaryis the file system path to an image file or aFile.Stream.t/0or anyEnumerable.t/0. It can also be any binary.jpg,.png,.webpor.svgimage.optionsis a keyword list of options. The default is[access: :random]for all images except images derived from binary image data.
options
Options
The available options depend upon the image type.
All image types
:accessis the file access mode, either:randomor:sequential. The default is:random. When:sequential,Image(viaVix) is able to support streaming transformations and optimise memory usage more effectively. However:sequentialalso means that some operations cannot be completed because they would require non-sequential access to the image. In these cases,:randomaccess is required.:fail_onsets the error level at which image loading and decoding will stop. The default is:none. Each error state implies all the states before it such that:errorimplies also:truncated.
JPEG image options
:shrinkis an integer factor in the range1..16by which the image is reduced upon loading. This is an optimization that can result in improved performance and reduced memory usage if the image is being loaded with the intent to resize it to smaller dimensions. The default value is1meaning no shrink-on-load.:autorotateis a boolean value indicating if the image should be rotated according to the orientation data stored in the image metadata. The default isfalse.
WEBP options
:scalewill scale the image on load. The value is a number greater than0and less than or equal to1024with a default of1meaning no scaling on load. Numbers less than1.0scale the image down so that a scale of0.5will halve the image size on load.:pageindicates the first page to be loaded. The value is in the range0..100_000with a default value of0. This parameter is useful on animated images.:pagesindicates the number of pages to load. The value must be between-1and100_000. The default value is1. A value of-1would load all the available pages which is useful if you want to keep the animation of the input image.
TIFF options
:autorotateis a boolean value indicating if the image should be rotated according to the orientation data stored in the image metadata. The default isfalse.:pageindicates the first page to be loaded. The value is in the range0..100_000with a default value of0. This parameter is useful on animated images.:pagesindicates the number of pages to load. The value must be between-1and100_000. The default value is1. A value of-1would load all the available pages which is useful if you want to keep the animation of the input image.
PNG options
- There are no PNG-specific image loading options.
GIF options
:pageindicates the first page to be loaded. The value is in the range0..100_000with a default value of0. This parameter is useful on animated images.:pagesindicates the number of pages to load. The value must be between-1and100_000. The default value is1. A value of-1would load all the available pages which is useful if you want to keep the animation of the input image.
returns
Returns
{:ok, image}or{:error, message}
@spec open!( image_path :: Path.t(), options :: Image.Options.Open.image_open_options() ) :: Vix.Vips.Image.t() | no_return()
Opens an image file for image processing returning an image or raising an exception.
arguments
Arguments
image_path_or_stream_or_binaryis the file system path to an image file or aFile.Stream.t/0or anyEnumerable.t/0. It can also be any binary.jpg,.png,.webpor.svgimage.optionsis a keyword list of options. The default is[access: :random]for all images except images derived from binary image data.
returns
Returns
imageorraises an exception.
@spec stream!( Vix.Vips.Image.t(), options :: Image.Options.Write.image_write_options() ) :: Enumerable.t()
Convert an image into an enumerable stream.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
:buffer_sizeis the size in bytes for each chunk in the stream being written. Some services, like AWS S3, require a minimum 5 MiB per chunk to be delivered and this option can be used to satisfy that requirement.
For additional options see Image.write/3.
returns
Returns
- An
Enumerable.t/0suitable for streaming to an external service such as S3, Minio or any other enumerable consumer.
example
Example
In this example an image is opened, resized and then streamed into AWS S3:
"some/image.jpg"
|> Image.open!()
|> Image.resize!(200)
|> Image.stream!(suffix: ".jpg", buffer_size: 5_242_880)
|> ExAws.S3.upload("images", "some_object_name.jpg")
|> ExAws.request()Since AWS S3 requires multipart uploads to be 5MiB per
chunk, we specify the :buffer_size option to
Image.stream!/2.
@spec write( image :: Vix.Vips.Image.t(), image_path :: Path.t() | Plug.Conn.t() | Enumerable.t() | File.Stream.t() | :memory, options :: Image.Options.Write.image_write_options() ) :: {:ok, Vix.Vips.Image.t()} | {:ok, binary()} | {:error, error_message()}
Write an image to a file, a stream, an enumerable or to memory.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.image_pathis the file system path to an image file. It may also be a stream created withFile.stream!/3or withStream.resource/3, aPlug.Conn.t/0ifPlugis configured or lastly, it can also be:memoryin which case the image is written to a binary.optionsis a keyword list of options. The default is[].
options
Options
The available options depends on the type of image file being opened.
All image types
:strip_metadatais a boolean indicating if all metadata is to be stripped from the image. The default isfalse.:backgroundis the background value to be used for any transparent areas of the image. Jpeg does not support alpha bands so a color value must be assigned.:qualitywhich influences image compression and is a integer in the range1..100. The default for most image formats is75. For PNG files it is the compression amount with a default of60. For HEIF files the default is50.
streaming-images-and-memory-images
Streaming images and :memory images
:suffixmust be specified so that the image is written in the correct format. For example:suffix: ".jpg".
JPEG images
:progressiveis a boolean indicating if the image should be interleaved rather than baseline. Progressive has the advantage of perceived time for the initial image load and the cost of multiple decoding passes on the client. For many applications:progressiveis to be preferred but validation of this assumption for specific use cases is required.:minimize_file_sizeis a boolean indicating whether to apply a number of techniques to minimise the file size of the jpeg file at the cost of additional time to save the image. All metadata will also be removed.:icc_profileindicates the icc profile to be attached to the output image. The value may be an inbuilt profile (:none,:srgb,:cmyk,:p3), the name of an icc profile in the systems profile directory or a full path to an icc profile file. The default is to use the icc profile of the input image if there is one.
PNG images
:progressivewhich has the same meaning and values as for JPEG images.:minimize_file_sizeis a boolean indicating whether to apply a number of techniques to minimise the file size of thepngfile at the cost of additional time to save the image. All metadata will also be removed.:effortis an integer to adjust the level of CPU effort to reduce the file size. The value must be in the range1..10, the default is7.:icc_profileindicates the icc profile to be attached to the output image. The value may be an inbuilt profile (:none,:srgb,:cmyk,:p3), the name of an icc profile in the systems profile directory or a full path to an icc profile file. The default is to use the icc profile of the input image if there is one.
WEBP images
:minimize_file_sizeis a boolean which is most useful on animatedWebP. It enables mixed encoding and optimise the file for minimum size at the cost of additional time to save the image. All metadata will also be removed. Using this parameter on a non-animatedwebpfile will only remove the metadata as:strip_metadatawould do.:effortis an integer to adjust the level of CPU effort to reduce the file size. The value must be in the range1..10, the default is7.:icc_profileindicates the icc profile to be attached to the output image. The value may be an inbuilt profile (:none,:srgb,:cmyk,:p3), the name of an icc profile in the systems profile directory or a full path to an icc profile file. The default is to use the icc profile of the input image if there is one.
GIF options
:interframe_maxerrorMaximum inter-frame error for transparency. The value must be in the range0..32. The default is0. By increasing this value, the encoder will try to take advantage from temporal redundancy between neighboring frames by enabling higher compression rates.:effortis an integer to adjust the level of CPU effort to reduce the file size. The value must be in the range1..10, the default is7.
HEIF images
:compressionis the compression strategy to be applied. The allowable values are:hevc,:avc,:jpegand:av1. The default is:hevc.:effortis an integer to adjust the level of CPU effort to reduce the file size. The value can be in the range1..10, the default is5.:minimize_file_sizeis a boolean indicating whether to apply a number of techniques to minimise the file size of theheiffile at the cost of additional time to save the image. All metadata will also be removed.
returns
Returns
{:ok, image}(or{:ok, binary}is the destination is:memory) or{:error, reason}
@spec write!( image :: Vix.Vips.Image.t(), image_path_or_stream :: Path.t() | Plug.Conn.t() | Enumerable.t() | File.Stream.t(), options :: Image.Options.Write.image_write_options() ) :: Vix.Vips.Image.t() | binary() | no_return()
Write an image to a file, a stream, an enumerable or to memory returning the image or raising an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.image_pathis the file system path to an image file. It may also be a stream created withFile.stream!/3or withStream.resource/3. Lastly, it can also be:memoryin which case the image is written to a memory buffer.optionsis a keyword list of options. SeeImage.write/2.
returns
Returns
image(or a binary is the destination is:memory) orraises an exception.
Link to this section Operations
@spec add_alpha( image :: Vix.Vips.Image.t(), alpha_image :: Vix.Vips.Image.t() | Image.Color.t() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Add an alpha band to an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.alpha_imageis any single-band image that will be added as an alpha image toimage
OR
:colorwhich defines the color of the alpha image. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The default is0, meaning black. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. SeeImage.Color.color_map/0andImage.Color.rgb_color/1.
note
Note
If color is provided then the alpha layer determines
the level of transparency of image. White (RGB color
- means that
imaagewill be opaque. Black (the default, RGB 0) means thatimagewill be transparent. Other colors will determine the level of transparency between the two.
returns
Returns
{:ok, image_with_added_alpha_band}or{:error, reason}
@spec add_alpha!( image :: Vix.Vips.Image.t(), alpha_image :: Vix.Vips.Image.t() | Image.Color.t() ) :: Vix.Vips.Image.t() | no_return()
Add an alpha band to an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.alpha_imageis any single-band image that will be added as an alpha image toimage
OR
:colorwhich defines the color of the alpha image. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The default is0, meaning black. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. SeeImage.Color.color_map/0andImage.Color.rgb_color/1.
note
Note
If color is provided then the alpha layer determines
the level of transparency of image. White (RGB color
- means that
imaagewill be opaque. Black (the default, RGB 0) means thatimagewill be transparent. Other colors will determine the level of transparency between the two.
returns
Returns
image_with_added_alpha_bandorraises an exception.
@spec autolevel(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Scales each band of an image to fit the full
dynamic range. Unlike Image.normalize/1, each
band is scaled separately.
The function finds the image histogram, searches for
thresholds which will select 0.3% and
0.7% of pixels
in each image band, then rescales the image so that those pixel
values become 0 and 255.
The scaling is performed in the :srgb color space
but the image is converted back to its original
color space after levelling.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, auto_levelled_image}or{:error, reason}.
@spec autolevel!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Scales each band of an image to fit the full
dynamic range. Unlike Image.normalize/1, each
band is scaled separately. Raises an exception
on error.
The function finds the image histogram, searches for
thresholds which will select 0.3% and
0.7% of pixels
in each image band, then rescales the image so that those pixel
values become 0 and 255.
The scaling is performed in the :srgb color space
but the image is converted back to its original
color space after levelling.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
auto_levelled_imageorraises an exception.
@spec autorotate(image :: Vix.Vips.Image.t()) :: {:ok, {Vix.Vips.Image.t(), Keyword.t()}} | {:error, error_message()}
Rotate an image based upon the orientation information in an image's EXIF data.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, {auto_rotated_image, flags}}or{:error, reason}
flags
Flags
Two flags are returned indicating what action was taken:
:flipwhich is a boolean indicating if the image was flipped or not and:anglethrough which the image was rotated. This value will be one of0,90,180or270representing the degrees of rotation.
@spec autorotate!(image :: Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Rotate an image based upon the orientation information in an image's EXIF data. Returns a potentially rotated image or raises and exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
auto_rotated_imageorraises an exception.
@spec blur(image :: Vix.Vips.Image.t(), options :: Image.Options.Blur.blur_options()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Applies a gaussian blur to an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
:sigmais thefloatsize of the mask to use. A larger number makes the image more blurry. A range between1.0and10.0is normally appropriate. The default is5.:min_amplitudeis afloatthat determines the accuracy of the mask. The default is0.2. A smaller number will generate a larger, more accurate mask,
returns
Returns
{:ok, blurred_image}or{:error reason}
@spec blur!(image :: Vix.Vips.Image.t(), options :: Image.Options.Blur.blur_options()) :: Vix.Vips.Image.t() | no_return()
Applies a gaussian blur to an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
:sigmais thefloatsize of the mask to use. A larger number makes the image more blurry. A range between1.0and10.0is normally appropriate. The default is5.:min_amplitudeis afloatthat determines the accuracy of the mask. The default is0.2. A smaller number will generate a larger, more accurate mask,
returns
Returns
blurred_imageorraises an exception.
@spec chroma_color(image :: Vix.Vips.Image.t()) :: Image.Color.t()
Automatically determine the chroma key color of an image.
The top left 10x10 pixels of the flattened
image are averaged to produce a color sample
that can then be used by Image.chroma_mask/2,
Image.chroma_key/2 and Image.trim/2.
argument
Argument
imageis anyVix.Vips.Image.t/0.
returns
Returns
- An RGB color as a three-element list of integers.
@spec chroma_key( image :: Vix.Vips.Image.t(), options :: Image.Options.ChromaKey.chroma_key_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Chroma key an image.
Chroma keying is the process of removing a background color from an image resulting in a foreground image that may be composited over another image.
If the image already has an alpha band then the image is flattened before adding the image mask as a new alpha band.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
There are two masking strategies available: the thresholding strategy (default) and the color range strategy.
Threshold strategy
:coloris an RGB color which represents the the chroma key to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:autoin which the average of the top left10x10pixels of the image is used.:thresholdis a positive integer to indicate the threshold around:colorwhen calculating the mask. The default is20.
Color range strategy
:greater_thanis an RGB color which represents the upper end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.:less_thanis an RGB color which represents the lower end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.
@spec chroma_key!( image :: Vix.Vips.Image.t(), options :: Image.Options.ChromaKey.chroma_key_options() ) :: Vix.Vips.Image.t() | no_return()
Chroma key an image and return an image or raise an exception.
Chroma keying is the process of removing a background color from an image resulting in a foreground image that may be composited over another image.
If the image already has an alpha band then the image is flattened before adding the image mask as a new alpha band.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
There are two masking strategies available: the thresholding strategy (default) and the color range strategy.
Threshold strategy
:coloris an RGB color which represents the the chroma key to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:autoin which the average of the top left10x10pixels of the image is used.:thresholdis a positive integer to indicate the threshold around:colorwhen calculating the mask. The default is20.
Color range strategy
:greater_thanis an RGB color which represents the upper end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.:less_thanis an RGB color which represents the lower end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.
@spec chroma_mask( image :: Vix.Vips.Image.t(), options :: Image.Options.ChromaKey.chroma_key_options() | map() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Return a chroma-based masked image.
Chroma masking is the process of removing a background color from an image and returning the remaining content as an alpha mask.
The masking is done in the LCh color space since it's perceptually more uniform. The returned mask in reverted to the interpretation of the original image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
There are two masking strategies available: the thresholding strategy (default) and the color range strategy.
Threshold strategy
:coloris an RGB color which represents the the chroma key to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:autoin which the average of the top left10x10pixels of the image is used.:thresholdis a positive integer to indicate the threshold around:colorwhen calculating the mask. The default is20.
Color range strategy
:greater_thanis an RGB color which represents the upper end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.:less_thanis an RGB color which represents the lower end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.
@spec chroma_mask!( image :: Vix.Vips.Image.t(), options :: Image.Options.ChromaKey.chroma_key_options() ) :: Vix.Vips.Image.t() | no_return()
Return a chroma-based masked image or raises an exception.
Chroma masking is the process of removing a background color from an image and returning the remaining content as an alpha mask.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
There are two masking strategies available: the thresholding strategy (default) and the color range strategy.
Threshold strategy
:coloris an RGB color which represents the the chroma key to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:autoin which the average of the top left10x10pixels of the image is used.:thresholdis a positive integer to indicate the threshold around:colorwhen calculating the mask. The default is20.
Color range strategy
:greater_thanis an RGB color which represents the upper end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.:less_thanis an RGB color which represents the lower end of the color range to be masked. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name.
@spec compose( base_image :: Vix.Vips.Image.t(), overlay_image :: Vix.Vips.Image.t(), options :: Keyword.t() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
@spec compose( base_image :: Vix.Vips.Image.t(), image_list :: [Vix.Vips.Image.t(), ...], options :: Keyword.t() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Compose two images together to form a new image.
arguments
Arguments
base_imageis anyVix.Vips.Image.t/0.overlay_imageis anyVix.Vips.Image.t/0that will be composed over the top ofbase_image. It can also be a list oft:composition/0s that allow for multiple images to be composed in a single call.optionsis a keyword list of options.
options-for-a-single-overlay-image
Options for a single overlay image
:blend_modeis the manner in which the two images are composited. SeeImage.BlendMode.t/0. The default is:overwhich is the most common blend mode.:xis the offset (0-based) from the left of thebase_imagewhere theoverlay_imagewill be placed. It may also be one of the keywords:left,:rightor:center. The default is:center.:yis the offset (0-based) from the top of thebase_imagewhere theoverlay_imagewill be placed. It may also be one of the keywords:top,:bottomor:middle. The default is:middle.
composition-list-options
Composition list options
When overlay_image is an image_list, each entry in
the list is either a Vix.Vips.Image.t/0 or a
t:composition/0. A composition supports the specification
of how a particular image is composed onto the base image.
:xdescribes the absolutexoffset on the base image where this image will be placed. If this option is set to:left,:centeror:rightthen thexposition will be calculated relative to the base image. If:xis nil (the default) then the image will be placed according to the relative offset of the previously composed image using:dx.:ydescribes the absoluteyoffset on the base image where this image will be placed. If this option is set to:top,:middleor:bottomthen theyposition will be calculated relative to the base image. If:yis nil (the default) then the image will be placed according to the relative offset of the previously composed image using:dy.:dxdescribes the relative offset used to calculate thexvalue.:dxis an integer offset from the edge of the previously composed image. Which edge is determined by the:x_baselineoption. If:xis also specified then:xis first calculated, then:dxis added to it. In this case,:x_baselineis ignored.:dydescribes the relative offset used to calculate theyvalue.:dyis an integer offset from the edge of the previously composed image. Which edge is determined by the:y_baselineoption. If:yis also specified then:yis first calculated, then:dyis added to it. In this case,:x_baselineis ignored.:blend_modeis theImage.BlendMode.t/0used when composing this image over its base image. The default is:overwhich is appropriate for most use cases.:x_baselineestablishes the baseline on the previously composed image from which:dxis calculated. The default is:right.:y_baselineestablishes the baseline on the previously composed image from which:dyis calculated. The default is:bottom.
returns
Returns
{:ok, composed_image}or{:error, reason}
examples
Examples
# Compose images over a base image using
# absolute coordinates from the base image
# to place each overlay image.
#=> {:ok, image} = Image.compose(base_image, polygon, x: :middle, y: :top)
#=> {:ok, image} = Image.compose(image, explore_new, x: 260, y: 200)
#=> {:ok, image} = Image.compose(image, places, x: 260, y: 260)
#=> {:ok, image} = Image.compose(image, blowout, x: 260, y: 340)
#=> {:ok, image} = Image.compose(image, start_saving, x: 260, y: 400)
# Compose images over a base image
# using a composition list and coordinates
# that are either absolute with respect to the
# base image or relative to the previously
# composed image.
#=> Image.compose(base_image, [
..> {polygon, x: :center, y: :top},
..> {explore_new, y_baseline: :top, x_baseline: :left, dx: 20, dy: 200},
..> {places, dy: 10},
..> {blowout, dy: 20},
..> {start_saving, dy: 50}
..> ])
@spec compose!( base_image :: Vix.Vips.Image.t(), overlay_image :: Vix.Vips.Image.t(), options :: Keyword.t() ) :: Vix.Vips.Image.t() | no_return()
@spec compose!( base_image :: Vix.Vips.Image.t(), image_list :: [Vix.Vips.Image.t(), ...], options :: Keyword.t() ) :: Vix.Vips.Image.t() | no_return()
Compose two images together to form a new image or raise an exception.
arguments
Arguments
base_imageis anyVix.Vips.Image.t/0.overlay_imageis anyVix.Vips.Image.t/0that will be composed over the top ofbase_image.optionsis a keyword list of options.
options
Options
:blend_modeis the manner in which the two images are composited. SeeImage.BlendMode.t/0. The default is:overwhich is the most common blend mode.:xis the offset (0-based) from the left of thebase_imagewhere theoverlay_imagewill be placed. It may also be one of the keywords:left,:rightor:center. The default is:center.:yis the offset (0-based) from the top of thebase_imagewhere theoverlay_imagewill be placed. It may also be one of the keywords:top,:bottomor:middle. The default is:middle.
composition-list-options
Composition list options
When overlay_image is an image_list, each entry in
the list is either a Vix.Vips.Image.t/0 or a
t:composition/0. A composition supports the specification
of how a particular image is composed onto the base image.
:xdescribes the absolutexoffset on the base image where this image will be placed. If this option is set to:left,:centeror:rightthen thexposition will be calculated relative to the base image. If:xis nil (the default) then the image will be placed according to the relative offset of the previously composed image using:dx.:ydescribes the absoluteyoffset on the base image where this image will be placed. If this option is set to:top,:middleor:bottomthen theyposition will be calculated relative to the base image. If:yis nil (the default) then the image will be placed according to the relative offset of the previously composed image using:dy.:dxdescribes the relative offset used to calculate thexvalue.:dxis an integer offset from the edge of the previously composed image. Which edge is determined by the:x_baselineoption. If:xis also specified then:xis first calculated, then:dxis added to it. In this case,:x_baselineis ignored.:dydescribes the relative offset used to calculate theyvalue.:dyis an integer offset from the edge of the previously composed image. Which edge is determined by the:y_baselineoption. If:yis also specified then:yis first calculated, then:dyis added to it. In this case,:x_baselineis ignored.:blend_modeis theImage.BlendMode.t/0used when composing this image over its base image. The default is:overwhich is appropriate for most use cases.:x_baselineestablishes the baseline on the previously composed image from which:dxis calculated. The default is:right.:y_baselineestablishes the baseline on the previously composed image from which:dyis calculated. The default is:bottom.
returns
Returns
composed_imageorraises an exception
examples
Examples
# Compose images over a base image using
# absolute coordinates from the base image
# to place each overlay image
#=> base_image
..> |> Image.compose!(polygon, x: :middle, y: :top)
..> |> Image.compose!(explore_new, x: 260, y: 200)
..> |> Image.compose!(places, x: 260, y: 260)
..> |> Image.compose!(blowout, x: 260, y: 340)
..> |> Image.compose!(start_saving, x: 260, y: 400)
# Compose images over a base image
# using a composition list and coordinates
# that are either absolute with respect to the
# base image or relative to the previously
# composed image
#=> base_image
..> |> Image.compose!([
..> {polygon, x: :center, y: :top},
..> {explore_new, y_baseline: :top, x_baseline: :left, dx: 20, dy: 200},
..> {places, dy: 10},
..> {blowout, dy: 20},
..> {start_saving, dy: 50}
..> ])
@spec dilate(image :: Vix.Vips.Image.t(), pixels :: pos_integer()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Dilate an image mask, adding a pixels to the edge of the mask.
Mask is used in the sense of an image on a transparent background. The results on other image types is undefined.
The added pixels are the same color as the edge pixels in the mask.
note
Note
Dilate works for any non-complex image type, with any number of bands. The input is expanded by copying edge pixels before performing the operation so that the output image has the same size as the input.
Edge pixels in the output image are therefore only approximate.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.pixelsis a positive integer number of pixels to dilate. The default is1.
returns
Returns
{:ok, dilated_mask}or{:error, reason}
@spec dilate!(image :: Vix.Vips.Image.t(), pixels :: pos_integer()) :: Vix.Vips.Image.t() | no_return()
Dilate an image mask, adding a pixels to the edge of the mask or raising an exception.
Mask is used in the sense of an image on a transparent background. The results on other image types is undefined.
The added pixels are the same color as the edge pixels in the mask.
note
Note
Dilate works for any non-complex image type, with any number of bands. The input is expanded by copying edge pixels before performing the operation so that the output image has the same size as the input.
Edge pixels in the output image are therefore only approximate.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.pixelsis a positive integer number of pixels to dilate. The default is1.
returns
Returns
dilated_maskorraises an exception
@spec embed!( Vix.Vips.Image.t(), non_neg_integer(), non_neg_integer(), Image.Options.Embed.embed_options() ) :: Vix.Vips.Image.t() | no_return()
Embeds an image in a larger image canvas, generating addition border pixels if required.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.widthis the width in pixels of the canvas image.heightis the height in pixels of the canvas image.optionsis a keyword list of options.
options
Options
See Image.embed/4.
returns
Returns
embedded_imageorraises an exception.
@spec erode(image :: Vix.Vips.Image.t(), pixels :: pos_integer()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Erode an image mask, removing pixels from the edge of the mask.
Mask is used in the sense of an image on a transparent background. The results on other image types is undefined.
note
Note
Erode works for any non-complex image type, with any number of bands. The input is expanded by copying edge pixels before performing the operation so that the output image has the same size as the input.
Edge pixels in the output image are therefore only approximate.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.pixelsis a positive integer number of pixels to dilate. The default is1.
returns
Returns
{:ok, eroded_mask}or{:error, reason}
@spec erode!(image :: Vix.Vips.Image.t(), pixels :: pos_integer()) :: Vix.Vips.Image.t() | no_return()
Erode an image mask, removing pixels from the edge of the mask or raising an exception.
Mask is used in the sense of an image on a transparent background. The results on other image types is undefined.
note
Note
Erode works for any non-complex image type, with any number of bands. The input is expanded by copying edge pixels before performing the operation so that the output image has the same size as the input.
Edge pixels in the output image are therefore only approximate.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.pixelsis a positive integer number of pixels to dilate. The default is1.
returns
Returns
eroded_maskorraises an exception
@spec feather( image :: Vix.Vips.Image.t(), options :: Image.Options.Blur.blur_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Feather (blur the edges) of an image mask.
Applies a gaussian blur to a one-band image or the alpha band of a multi-band image that can be used to smooth the blending of one image into another.
arguments
Arguments
imageis anyVix.Vips.Image.t/0that is either a single band image or an image with an alpha band.optionsis a keyword list of options.
options
Options
:sigmais thefloatsize of the mask to use. A larger number makes the image more blurry. A range between1.0and10.0is normally appropriate. The default is5.:min_amplitudeis afloatthat determines the accuracy of the mask. The default is0.2. A smaller number will generate a larger, more accurate mask,
returns
Returns
{:ok, blurred_mask_image}or{:error, reason}
@spec feather!( image :: Vix.Vips.Image.t(), options :: Image.Options.Blur.blur_options() ) :: Vix.Vips.Image.t() | no_return()
Feather (blur the edges) of an image mask returning an image or raising an exception.
Applies a gaussian blur to a one-band image or the alpha band of a multi-band image that can be used to smooth the blending of one image into another.
arguments
Arguments
imageis anyVix.Vips.Image.t/0that is either a single band image or an image with an alpha band.optionsis a keyword list of options.
options
Options
:sigmais thefloatsize of the mask to use. A larger number makes the image more blurry. A range between1.0and10.0is normally appropriate. The default is5.:min_amplitudeis afloatthat determines the accuracy of the mask. The default is0.2. A smaller number will generate a larger, more accurate mask,
returns
Returns
{:ok, blurred_mask_image}or{:error, reason}
@spec fft(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Returns the fast fourier transform (fft) of the given image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
{:ok, fft_image}or{:error, reason}
example
Example
Image.fft(image)
@spec fft!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Returns the fast fourier transform (fft) of the given image returning an image or raising an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
fft_imageorraises an exception
example
Example
Image.fft!(image)
@spec flatten(image :: Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Flatten an alpha layer out of an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, flattened_image}or{:error, reason}
@spec flatten!(image :: Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Flatten an alpha layer out of an image or raises an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
flattened_imageorraises an exception
@spec flip(image :: Vix.Vips.Image.t(), direction :: :vertical | :horizontal) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Flip an image horizontally or vertically.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.directionis either:horizontalor:vertical.
returns
Returns
{:ok, flipped_image}or{:error, reason}
@spec flip!(image :: Vix.Vips.Image.t(), direction :: :vertical | :horizontal) :: Vix.Vips.Image.t() | no_return()
Flip an image horizontally or vertically returning a flipped image or raising an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.directionis either:horizontalor:vertical.
returns
Returns
flipped_imageorraises an exception.
@spec get_pixel(Vix.Vips.Image.t(), non_neg_integer(), non_neg_integer()) :: {:ok, Image.Color.rgb_color()} | {:error, error_message()}
Returns the pixel value at the given image location.
The returned pixel is a list of numbers where the length of the list is equal to the number of bands in the image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.xis an integer offset from the top left of the image along thex(width) axis. The number must be in the range0..width - 1.yis an integer offset from the top left of the image along they(height) axis. The number must be in the range0..height - 1.
returns
Returns
{:ok, pixel_value}or{:error, reason}
@spec get_pixel!(Vix.Vips.Image.t(), non_neg_integer(), non_neg_integer()) :: Image.Color.rgb_color() | no_return()
Returns the pixel value at the given image location or raises an exception.
The returned pixel is a list of numbers where the length of the list is equal to the number of bands in the image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.xis an integer offset from the top left of the image along thex(width) axis. The number must be in the range0..width - 1.yis an integer offset from the top left of the image along they(height) axis. The number must be in the range0..height - 1.
returns
Returns
pixel_valueorraises an exception
@spec hamming_distance(image_1 :: Vix.Vips.Image.t(), image_2 :: Vix.Vips.Image.t()) :: {:ok, non_neg_integer()} | {:error, error_message()}
@spec hamming_distance(image_hash(), image_hash()) :: {:ok, non_neg_integer()} | {:error, error_message()}
Returns the hamming distance of two images or two image hashes.
A hamming distance gives an indication of the similarity of two images.
In general, a hamming distance of less than 10 indicates
that the images are very similar. A distance of
less than 20 suggests the images are quite similar. Any
other distance suggests the images have little in common.
arguments
Arguments
image_1is anyVix.Vips.Image.t/0image_2is anyVix.Vips.Image.t/0
Alternatively, both arguments may be image hashes
returned by Image.dhash/1. Both arguments must
be of the same type.
returns
Returns
{:ok, hamming_distance}where hamming distance is a positive integer or{:error, reason}.
@spec histogram(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Returns the histogram for an image.
The histogram is returned as a t:Vimage.t/0
that is a 255 by 255 image the same numbers of
bands as the source image.
argument
Argument
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, histogram_image}or{:error, reason}
notes
Notes
The returned image is is organized as a 256x256 pixel image with the same number of bands as the original image.
Each pixel on the image returns the count of pixels in the original image that are in that 1/256th part of the image.
if_then_else(condition_image, if_image, else_image)
View Source (since 0.13.0)@spec if_then_else( condition_image :: Vix.Vips.Image.t(), if_image :: image_or_color(), else_image :: image_or_color() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Scans the condition image cond and uses it to select
pixels from either the then if_image or the else_image.
Non-zero means copy a pixel from if_image, 0 means
copy a pixel from else_image.
arguments
Arguments
condition_imageis any image. Typically it is an image formed by the relation operations such asImage.Math.greater_than/2.if_image_or_coloris either ant:Vimage.t/0or aImage.Color.t/0. If a color is provided then an image is constructed with the same shape ascondition_imagefilled with the provided color.else_image_or_coloris either ant:Vimage.t/0or aImage.Color.t/0. If a color is provided then an image is constructed with the same shape ascondition_imagefilled with the provided color.
notes
Notes
Any image can have either 1 band or n bands, where n
is the same for all the non-1-band images. Single band
images are then effectively copied to make n-band images.
Images if_image and else_image are cast up to the
smallest common format. The condition_image is cast to
{:u, 8}.
If the images differ in size, the smaller images are enlarged to match the largest by adding zero pixels along the bottom and right.
The output image is calculated pixel by pixel as:
(condition_image / 255) * if_image + (1 - condition_image / 255) *`else_image`
@spec map(Vix.Vips.Image.t(), Vix.Vips.Image.t(), Keyword.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Applies a transformation matrix to an image.
A transformation matrix is returned by
Image.transform_matrix/3.
Image.warp_perspective/4 uses this function to
apply a perspective transform to an image.
arguments
Arguments
imageis anyt:Vimage.t/0transform_matrixis a matrix returned byImage.transform_matrix/3.
returns
Returns
{:ok, mapped_image}or{:error, reason}
@spec mutate(Vix.Vips.Image.t(), (Vix.Vips.MutableImage.t() -> any())) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Mutate an image with through the given function.
Mutations, like those functions in the
Image.Draw, module are operations on
a copy of the base image and operations
are serialized through a genserver in order
to maintain thread safety.
In order to perform multiple mutations without
coopying for each each mutation,Image.mutate/2 takes
a function argument fun that is passed a
Vix.Vips.MutableImage.t/0 as a parameter. In that
way several mutations can be safely applied withouout
copying the image prior to each mutation.
Although the image is not copied before each mutuation, each mutable operation is still serialized behind a genserver to ensure thread safety.
The functions in Image.Draw all support either
a Vix.Vips.Image.t/0 or a Vix.Vips.MutableImage.t/0
as the image parameter.
When the parameter fun returns, the mutation
process is ended and a normal Vix.Vips.Image.t/0
is returned.
This function is a convenience wrapper
around Vix.Vips.Image.mutate/2.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.funis any 1-arity function that receives aVix.Vips.MutableImage.t/0parameter.
returns
Returns
{:ok, mutated_image}or{:error, reason}
example
Example
# The image is copied and operations
# are serialized behind a genserver.
# Only one copy is made but all operations
# will be serialized behind a genserver.
# When the function returns the genserver
# is broken down and the underlying
# mutated `t:Vix.Vips.Image.t/0` is returned.
Image.mutate image, fn mutable_image ->
mutable_image
|> Image.Draw.rect!(0, 0, 10, 10, color: :red)
|> Image.Draw.rect!(10, 10, 20, 20, color: :green)
end
@spec normalize(image :: Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Normalize an image by expanding the luminance of an image to cover the full dynamic range.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, normalized_image}or{:error, reason}.
@spec normalize!(image :: Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Normalize an image by expanding the luminance of an image to cover the full dynamic range. Raises an exception on error.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
normalized_imageorraises an exception.
@spec pixelate(image :: Vix.Vips.Image.t(), scale :: number()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Pixelates an image.
Pixelation is the process of reducing the image resolution while retaining the image dimensions.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.scaleis the scale factor to apply to the image when it is pixelated. This means that one "pixel" isimage width * scale. The default is0.05.
returns
Returns
{:ok, pixelated_image}or{:error, reason}
@spec pixelate!(image :: Vix.Vips.Image.t(), scale :: number()) :: Vix.Vips.Image.t() | no_return()
Pixelates an image or raise an exception.
Pixelation is the process of reducing the image resolution while retaining the image dimensions.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.scaleis the scale factor to apply to the image when it is pixelated. This means that one "pixel" isimage width * scale. The default is0.05.
returns
Returns
{:ok, pixelated_image}or{:error, reason}
@spec ripple(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Adds a concentric ripple effect to an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, image_with_ripple}or{:error, reason}
@spec ripple!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Adds a concentric ripple effect to an image returning an image or raising an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
image_with_rippleorraises an exception.
@spec rotate( image :: Vix.Vips.Image.t(), angle :: float(), options :: Image.Options.Rotate.rotation_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Rotate an image clockwise (to the right) by a number of degrees.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.angleis afloatnumber of degrees to rotate in a clockwise direction.optionsis a keyword list of options.
options
Options
:idyis the vertical input displacement which defaults to0.0:idxis the horizontal input displacement which defaults to0.0:odyis the vertical output displacement which defaults to0.0:odxis the horizontal output displacement which defaults to0.0:backgroundis the background color to be used for filling the blank areas of the image. The background is specified as a list of 3 or 4 float values depending on the image color space.
notes
Notes
The displacement parameters cause the image canvas to be expanded and the image displaced, relative to the top left corner of the image, by the amount specified.
The rules defining how the image canvas is expanded
is not known to the author of Image. Experimentation will
be required if you explore these options.
returns
Returns
{:ok, rotated_image}or{:error, reason}
@spec rotate!( image :: Vix.Vips.Image.t(), angle :: float(), options :: Image.Options.Rotate.rotation_options() ) :: Vix.Vips.Image.t() | no_return()
Rotate an image clockwise (to the right) by a number of degrees.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.angleis afloatnumber of degrees to rotate in a clockwise direction.optionsis a keyword list of options. SeeImage.rotate/3.
notes
Notes
The displacement parameters cause the image canvas to be expanded and the image displaced, relative to the top left corner of the image, by the amount specified.
The rules defining how the image canvas is expanded
is not known to the author of Image. Experimentation will
be required if you explore these options.
returns
Returns
rotated_imageorraises an exception.
@spec skew_angle(Vix.Vips.Image.t()) :: float()
Attempts top determine the distance from the perpendicular for a given image.
The principle is that rotating the image by the skew angle should return an image in the upright position.
The results are very image sensitive and perfect results are not guaranteed.
The algorithm is an implementation of this stackoverflow post.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
skew_anglewhich is a float number of degrees the image is tilted from the upright.
Example
skew_angle = skew_angle(image)
Image.rotate(image, skew_angle)
@spec split_alpha(image :: Vix.Vips.Image.t()) :: {bands :: Vix.Vips.Image.t(), alpha :: Vix.Vips.Image.t() | nil}
Split an image to separate the alpha band from the other image bands.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{image_bands_without_alpha, alpha_band}or{:image_bands, nil}if there is not alpha band detected.
straighten_perspective(image, source, options \\ [])
View Source (since 0.28.0)@spec straighten_perspective( Vix.Vips.Image.t(), source :: quadrilateral(), Image.Options.WarpPerspective.t() ) :: {:ok, quadrilateral(), Vix.Vips.Image.t()} | {:error, error_message()}
Performs a warp perspective transformation on an image to straighten its perspective.
Requires Nx to be configured as a dependency.
arguments
Arguments
imageis anyt:Vimage.t/0sourceis a list of four 2-tuples representing the four corners of the subject-of-interest inimage.optionsis a keyword list of options. The default is[].
options
Options
:backgrounddefines the color of any generated background pixels. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. It can also be supplied as a hex string of the form#rrggbb. The default is:black.:backgroundcan also be set to:averagein which case the background will be the average color of the base image. See alsoImage.Color.color_map/0andImage.Color.rgb_color/1.:extend_modedetermines how any additional pixels are generated. The values are::black(the default) meaning the generated pixels are black.:whitemeaning the generated pixels are white.:copymeans the generated pixels take the value of the nearest edge pixel of the base image.:repeatmeans the generated pixels are tiles from the base image.:mirrormeans the generated pixels are a reflected tiles of the base image.:backgroundmeans the generated pixels are the background color setinoptions.
returns
Returns
{:ok, destination, straightened_image}or{:error, reason}
notes
Notes
The image is flattened before warping and therefore any alpha band will be multiplied into to the image data and removed.
The returned
destinationis a four element list of 2-tuples representing the four points to which thesourcepoints were transformed.destinationcan be passed as a parameter toImage.crop/2to crop the transformed image to the subject-of-interest that was warped.
straighten_perspective!(image, source, options \\ [])
View Source (since 0.28.0)@spec straighten_perspective!( Vix.Vips.Image.t(), source :: quadrilateral(), Image.Options.WarpPerspective.t() ) :: Vix.Vips.Image.t() | no_return()
Performs a warp perspective transformation on an image to straighten its perspective or raises an exception.
Requires Nx to be configured as a dependency.
arguments
Arguments
imageis anyt:Vimage.t/0sourceis a list of four 2-tuples representing the four corners of the subject-of-interest inimage.optionsis a keyword list of options. The default is[].
options
Options
:backgrounddefines the color of any generated background pixels. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. It can also be supplied as a hex string of the form#rrggbb. The default is:black.:backgroundcan also be set to:averagein which case the background will be the average color of the base image. See alsoImage.Color.color_map/0andImage.Color.rgb_color/1.:extend_modedetermines how any additional pixels are generated. The values are::black(the default) meaning the generated pixels are black.:whitemeaning the generated pixels are white.:copymeans the generated pixels take the value of the nearest edge pixel of the base image.:repeatmeans the generated pixels are tiles from the base image.:mirrormeans the generated pixels are a reflected tiles of the base image.:backgroundmeans the generated pixels are the background color setinoptions.
returns
Returns
straightened_imageor{:error, reason}
notes
Notes
The image is flattened before warping and therefore any alpha band will be multiplied into to the image data and removed.
The returned
destinationis a four element list of 2-tuples representing the four points to which thesourcepoints were transformed.destinationcan be passed as a parameter toImage.crop/2to crop the transformed image to the subject-of-interest that was warped.
@spec to_polar_coordinates(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Convert image to polar coordinates.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, image_in_polar_coordinates}or{:error, reason}
@spec to_polar_coordinates!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Convert image to polar coordinates returning an image or raising an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
image_in_polar_coordinatesorraises an exception.
@spec to_rectangular_coordinates(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Convert image to rectangular coordinates.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
notes
Notes
Roundtrip to polar and back to rectangular coordinates displays some image distortion, likely due to rounding errors in float arithmetic. Further study is required.
returns
Returns
{:ok, image_in_rectangular_coordinates}or{:error, reason}
@spec to_rectangular_coordinates!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Convert image to rectangular coordinates returning an image or raising an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
notes
Notes
Roundtrip to polar and back to rectangular coordinates displays some image distortion, likely due to rounding errors in float arithmetic. Further study is required.
returns
Returns
image_in_rectangular_coordinatesorraises an exception.
@spec transform_matrix( Vix.Vips.Image.t(), source :: quadrilateral(), destination :: quadrilateral() ) :: {:ok, transform_matrix :: Vix.Vips.Image.t()} | {:error, error_message()}
Returns a transformation matrix for a given image, source quadrilateral and desintation quadrilateral.
A transformation matrix when applied to an image
(using, for example, Image.map/2) maps pixels from
the source persecptive to the destination perspective.
Requires Nx to be configured as a dependency.
arguments
Arguments
imageis anyt:Vimage.t/0sourceis a list of four 2-tuples representing the four corners of the subject-of-interest inimage.destinationis a list of four 2-tuples representing the four corners of the destination image into which the subject-of-interest is transformed.
returns
Returns
{:ok, transform_matrix}or{:error, reason}.
warp_perspective(image, source, destination, options \\ [])
View Source (since 0.28.0)@spec warp_perspective( Vix.Vips.Image.t(), source :: quadrilateral(), destination :: quadrilateral(), Image.Options.WarpPerspective.t() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Performs a warp perspective transformation on an image.
Requires Nx to be configured as a dependency.
arguments
Arguments
imageis anyt:Vimage.t/0sourceis a list of four 2-tuples representing the four corners of the subject-of-interest inimage.destinationis a list of four 2-tuples representing the four corners of the destination image into which the subject-of-interest is transformed.optionsis a keyword list of options. The default is[].
options
Options
:backgrounddefines the color of any generated background pixels. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. It can also be supplied as a hex string of the form#rrggbb. The default is:black.:backgroundcan also be set to:averagein which case the background will be the average color of the base image. See alsoImage.Color.color_map/0andImage.Color.rgb_color/1.:extend_modedetermines how any additional pixels are generated. The values are::black(the default) meaning the generated pixels are black.:whitemeaning the generated pixels are white.:copymeans the generated pixels take the value of the nearest edge pixel of the base image.:repeatmeans the generated pixels are tiles from the base image.:mirrormeans the generated pixels are a reflected tiles of the base image.:backgroundmeans the generated pixels are the background color setinoptions.
notes
Notes
- The image is flattened before warping and therefore any alpha band will be multiplied into to the image data and removed.
returns
Returns
{:ok, warped_image}or{:error, reason}
@spec warp_perspective!( Vix.Vips.Image.t(), source :: quadrilateral(), destination :: quadrilateral(), Image.Options.WarpPerspective.t() ) :: Vix.Vips.Image.t() | no_return()
Performs a warp perspective transformation on an image or raises an exception.
Requires Nx to be configured as a dependency.
arguments
Arguments
imageis anyt:Vimage.t/0sourceis a list of four 2-tuples representing the four corners of the subject-of-interest inimage.destinationis a list of four 2-tuples representing the four corners of the destination image into which the subject-of-interest is transformed.optionsis a keyword list of options. The default is[].
options
Options
:backgrounddefines the color of any generated background pixels. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. It can also be supplied as a hex string of the form#rrggbb. The default is:black.:backgroundcan also be set to:averagein which case the background will be the average color of the base image. See alsoImage.Color.color_map/0andImage.Color.rgb_color/1.:extend_modedetermines how any additional pixels are generated. The values are::black(the default) meaning the generated pixels are black.:whitemeaning the generated pixels are white.:copymeans the generated pixels take the value of the nearest edge pixel of the base image.:repeatmeans the generated pixels are tiles from the base image.:mirrormeans the generated pixels are a reflected tiles of the base image.:backgroundmeans the generated pixels are the background color setinoptions.
returns
Returns
warped_imageorraises an exception.
notes
Notes
- The image is flattened before warping and therefore any alpha band will be multiplied into to the image data and removed.
Link to this section Resize
@spec embed( Vix.Vips.Image.t(), non_neg_integer(), non_neg_integer(), Image.Options.Embed.embed_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Embeds an image in a larger image canvas, generating addition border pixels if required.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.widthis the width in pixels of the canvas image.heightis the height in pixels of the canvas image.optionsis a keyword list of options.
options
Options
:xis the x-offset into the canvas image whereimagewill be embedded. The value may be a positive integer indicating a 0-based offset from the left of the canvas or a negative integer indicating a 1-based offset from the right side of the image. It may also be:center(the default) in which case the image will be centered horizontally within the canvas.:yis the y-offset into the canvas image whereimagewill be embedded. The value may be a positive integer indicating a 0-based offset from the top of the canvas or a negative integer indicating a 1-based offset from the bottom of the image. It may also be:center(the default) in which case the image will be centered vertically within the canvas.:backgrounddefines the color of the generated background pixels. This can be specified as a single integer which will be applied to all bands, or a list of integers representing the color for each band. The color can also be supplied as a CSS color name as a string or atom. For example::misty_rose. It can also be supplied as a hex string of the form#rrggbb. The default is:black.:backgroundcan also be set to:averagein which case the background will be the average color of the base image. See alsoImage.Color.color_map/0andImage.Color.rgb_color/1.:extend_modedetermines how any additional pixels are generated. The values are::black(the default) meaning the generated pixels are black.:whitemeaning the generated pixels are white.:copymeans the generated pixels take the value of the nearest edge pixel of the base image.:repeatmeans the generated pixels are tiles from the base image.:mirrormeans the generated pixels are a reflected tiles of the base image.:backgroundmeans the generated pixels are the background color set inoptions.
returns
Returns
{:ok, embedded_image}or{:error, reason}
@spec resize( Vix.Vips.Image.t(), scale :: number(), options :: Image.Options.Resize.resize_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Resize an image.
If the intent is to thumbnail an image then Image.thumbnail/3
is recommended since it applies a very efficient downsizing
algorithm for that use case.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.scaleis a float scale factor.optionsis a keyword list of options.
options
Options
:centreis a boolean indicating whether to use the centre downsampling convention. The default isfalse.:interpolatedefines which resampling kernel to apply. The options are:nearest,:linear,:cubic,:mitchell,:lanczos2or:lanczos3(the default).
returns
Returns
{:ok, resized_image}orraises an exception
@spec resize!( Vix.Vips.Image.t(), scale :: number(), options :: Image.Options.Resize.resize_options() ) :: Vix.Vips.Image.t() | no_return()
Resize an image or raise an exception.
If the intent is to thumbnail an image then Image.thumbnail/3
is recommended since it applies a very efficient downsizing
algorithm for that use case.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.scaleis a float scale factor.optionsis a keyword list of options.
options
Options
:centreis a boolean indicating whether to use the centre downsampling convention. The default isfalse.:interpolatedefines which resampling kernel to apply. The options are:nearest,:linear,:cubic,:mitchell,:lanczos2or:lanczos3(the default).
returns
Returns
resized_imageorraises an exception
@spec thumbnail( Vix.Vips.Image.t(), length :: pos_integer(), options :: Image.Options.Thumbnail.thumbnail_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
@spec thumbnail( Path.t(), length :: pos_integer(), options :: Image.Options.Thumbnail.thumbnail_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
@spec thumbnail( Vix.Vips.Image.t() | Path.t(), dimensions :: binary(), options :: Image.Options.Thumbnail.thumbnail_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Thumbnail an image to fit or fill a bounding box.
arguments
Arguments
imageis anyVix.Vips.Image.t/0or a pathname to an image file.lengthis the integer length of the longest side of the resulting image after resizing. It c an also be of the form "<width>x<height>". That is, a string with the width and height separated by anx. The<height>may be omitted in which case it is the same as providing an integer length.optionsis a keyword list of options.
options
Options
:cropdetermines if the strategy is "resize to fit" (crop is:none) or "resize to fill" (when the crop option is not:none). The value may be one of:none,:center,:entropy,:attention,:lowor:high. The default is:none. See alsoImage.Options.Crop.crop_focus/0.:height- Size to this height. Default is to maintain the image aspect ratio unlessresize: :forceis set. Ifresize; :forceis set then the default:heightis the height ofimage.:fitsets the:cropand:resizeoptions to align with the CSS object-fit property. Note that using the:fitoption overwrites the options:cropand:resize. Since options are processed in the order in which they are presented,:cropand:resizemay still be force set if they are after the:fitoption.:fittakes one of the following values::fill- the image is resized to fill the given dimension. If necessary, the image will be stretched or squished to fit. This is the same as settingresize: :force. Note that is:heightis not specified it will be the same height asimage.:contain- the image keeps its aspect ratio, but is resized to fit within the given dimension. This is the same as settingcrop: :noneandresize: :both.:cover- the image keeps its aspect ratio and fills the given dimensions. The image will be clipped to fit. Clipping will default to:centerunless:cropis already set to a value other than:none. This is the same as settingcrop: :center(if:cropis not already set) andresize: :both.
:autorotateis a boolean indicating if the image should be autorotated based upon the image metadata. The default istrue.:intentindicates the rendering intent. The default is:relative. See alsoImage.render_intent/0.:export_icc_profileindicates the icc profile to be attached to the resized image. The value may be an inbuilt profile (:srgb,:p3or:cmyk), the name of an icc profile in the systems profile directory or a full path to an icc profile file. The default is to export the icc profile of the resized image if there is one.:import_icc_profileindicates the icc profile to be attached to the input image. The value may be an inbuilt profile (:srgb,:p3or:cmyk), the name of an icc profile in the systems profile directory or a full path to an icc profile file. The default is to use the icc profile of the input image if there is one.:linearis a boolean indicating of the image should be resized in linear space. The defaultfalse. Shrinking is normally done in sRGB colourspace. Set linear to shrink in linear light colourspace instead. This can give better results, but can also be far slower, since tricks like JPEG shrink-on-load cannot be used in linear space.:resizedetermines if an image may be only upsized, only downsized, both or a forced aspect ratio is applied. The value may be one of:up,:down,:bothor:force. The default is:both.
returns
Returns
{:ok, thumbnailed_image}or{:error, reason}
@spec thumbnail!( Vix.Vips.Image.t(), length :: pos_integer(), options :: Image.Options.Thumbnail.thumbnail_options() ) :: Vix.Vips.Image.t() | no_return()
@spec thumbnail!( Path.t(), length :: pos_integer(), options :: Image.Options.Thumbnail.thumbnail_options() ) :: Vix.Vips.Image.t() | no_return()
@spec thumbnail!( Vix.Vips.Image.t() | Path.t(), dimensions :: binary(), options :: Image.Options.Thumbnail.thumbnail_options() ) :: Vix.Vips.Image.t() | no_return()
Thumbnail an image to fit or fill a bounding box returning an image or raising an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0or a pathname to an image file.lengthis the integer length of the longest side of the resulting image after resizing. It c an also be of the form "<width>x<height>". That is, a string with the width and height separated by anx. The<height>may be omitted in which case it is the same as providing an integer length.optionsis a keyword list of options. SeeImage.thumbnail/3.
returns
Returns
imageorraises an exception.
@spec trim(image :: Vix.Vips.Image.t(), options :: Image.Options.Trim.trim_options()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Trims an image to the bounding box of the non-background area.
Any alpha is flattened out, then the image is median-filtered, all the row and column sums of the absolute difference from background are calculated in a single pass.
Then the first row or column in each of the four directions where the sum is greater than threshold gives the bounding box that is used to define the crop area.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
:backgroundis the color to be considered the background color. The default is automatically detected by averaging the pixels at the top left of the image.:thresholdis the integer threshold (or color similarity) that is applied when determining the bounds of the non-background area. The default is10. The default value means only a small color background color range is considered. Increasing the threshold value maybe required.
returns
Returns
{:ok, cropped_image}which is the image cropped to the bounding box of the non-background area.{:error, reason}. Reason may be:uncroppedwhich means the image was considered to be only the background color.
@spec trim!(image :: Vix.Vips.Image.t(), options :: Image.Options.Trim.trim_options()) :: Vix.Vips.Image.t() | no_return()
Trims an image to the bounding box of the non-background area.
Any alpha is flattened out, then the image is median-filtered, all the row and column sums of the absolute difference from background are calculated in a single pass.
Then the first row or column in each of the four directions where the sum is greater than threshold gives the bounding box that is used to define the crop area.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
:backgroundis the color to be considered the background color. The default is automatically detected by averaging the pixels at the top left of the image.:thresholdis the integer threshold (or color similarity) that is applied when determining the bounds of the non-background area. The default is10. The default value means only a small color background color range is considered. Increasing the threshold value maybe required.
returns
Returns
cropped_imagewhich is the image cropped to the bounding box of the non-background area orraises an exception.
Link to this section Crop
@spec center_crop(Vix.Vips.Image.t(), pos_integer(), pos_integer()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Crops the center from an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.widthis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifwidthis an integer it is the absolute number of pixels. Ifwidthis a float it is the fraction of the original image width.heightis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifheightis an integer it is the absolute number of pixels. Ifheightis a float it is the fraction of the original image height.
notes
Notes
An error will be returned if
widthandheightare not equal to or smaller than theimagedimensions.This function is a convenience function equivalent to calling
Image.crop(image, :center, :middle, width, height).
returns
Returns
{:ok, cropped_image}or{:error, reason}.
@spec center_crop!(Vix.Vips.Image.t(), pos_integer(), pos_integer()) :: Vix.Vips.Image.t() | no_return()
Crops the center from an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.widthis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifwidthis an integer it is the absolute number of pixels. Ifwidthis a float it is the fraction of the original image width.heightis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifheightis an integer it is the absolute numberof pixels. If
heightis a float it is the fraction of the original image height.
notes
Notes
An error will be returned if
widthandheightare not equal to or smaller than theimagedimensions.This function is a convenience function equivalent to calling
Image.crop!(image, :center, :middle, width, height).
returns
Returns
cropped_imageorraises an exception.
@spec crop(Vix.Vips.Image.t(), quadrilateral()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Crop an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.quadrilateralis a list of four 2-tuples representing the points of the bounding rectangle. The points must be ordered as[top_left, top_right, bottom_right, bottom_left]Each point is of the form{x, y}wherexis the 0-based offset from the left of the image andyis the 0-based offset from the top of the image.
returns
Returns
{:ok, cropped_image}or{:error, reason}
note
Note
The bounding box must be a rectangle, not an
arbitrary quadrilateral. If required, use Image.warp_perspective/4
prior to cropping.
@spec crop( Vix.Vips.Image.t(), x_location(), y_location(), pos_integer(), pos_integer() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Crop an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.leftis the top edge of crop area as an integer or a float in the range-1.0..1.0. Ifleftis an integer it is the absolute number of pixels. Iflefta float is fraction of the width of the image. Ifleftis positive it is relative to the left edge of the image. If it is negative it is relative to the right edge of the image.leftmay also be one of:left,:centerand:rightindicating the crop is relative to the left, center or right of the image.topis the top edge of crop area as an integer or a float in the range-1.0..1.0. Iftopis an integer it is the absolute number of pixels. Iftopis a float is fraction of the height of the image. Iftopis positive it is relative to the top edge of the image. If it is negative it is relative to the bottom edge of the image.topmay also be one of:top,:middleand:bottomindicating the crop is relative to the top, middle or bottom of the image.widthis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifwidthis an integer it is the absolute number of pixels. Ifwidthis a float it is the fraction of the original image width.heightis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifheightis an integer it is the absolute number of pixels. Ifheightis a float it is the fraction of the original image height.
notes
Notes
leftis 0-indexed. That is, the leftmost edge of the image starts at0.topis 0-indexed. That is, the topmost edge of the image starts at0.
returns
Returns
{:ok, cropped_image}or{:error, reason}
@spec crop!(Vix.Vips.Image.t(), quadrilateral()) :: Vix.Vips.Image.t() | no_return()
Crop an image or raises an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.quadrilateralis a list of four 2-tuples representing the points of the bounding rectangle. The points must be ordered as[top_left, top_right, bottom_right, bottom_left]Each point is of the form{x, y}wherexis the 0-based offset from the left of the image andyis the 0-based offset from the top of the image.
returns
Returns
cropped_imageorraises an exception.
note
Note
The bounding box must be a rectangle, not an
arbitrary quadrilateral. If required, use Image.warp_perspective/4
prior to cropping.
@spec crop!(Vix.Vips.Image.t(), integer(), integer(), pos_integer(), pos_integer()) :: Vix.Vips.Image.t() | no_return()
Crop an image returning a cropped image or raising an exception.
arguments
Arguments
leftis the top edge of crop area as an integer or a float in the range-1.0..1.0. Ifleftis an integer it is the absolute number of pixels. Iflefta float is fraction of the width of the image. Ifleftis positive it is relative to the left edge of the image. If it is negative it is relative to the right edge of the image.leftmay also be one of:left,:centerand:rightindicating the crop is relative to the left, center or right of the image.topis the top edge of crop area as an integer or a float in the range-1.0..1.0. Iftopis an integer it is the absolute number of pixels. Iftopis a float is fraction of the height of the image. Iftopis positive it is relative to the top edge of the image. If it is negative it is relative to the bottom edge of the image.topmay also be one of:top,:middleand:bottomindicating the crop is relative to the top, middle or bottom of the image.widthis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifwidthis an integer it is the absolute number of pixels. Ifwidthis a float it is the fraction of the original image width.heightis the width of area remaining as a positive integer or float in the range0.0..1.0. Ifheightis an integer it is the absolute number of pixels. Ifheightis a float it is the fraction of the original image height.
returns
Returns
cropped_imageorraises an exception.
Link to this section Transforms
@spec avatar(Vix.Vips.Image.t(), options :: Image.Options.Avatar.avatar_options()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Make a circular or square image intended to be used as an avatar image.
The image is resized and all metadata is removed
from the image. Depending on the :shape option
the image may be center cropped to a square and
may have a circular mask applied.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options. The default is[shape: :cirlce, crop: :none].
options
Options
:sizeis the diameter (in the case ofshape: :circleor width/height in the case ofshape: :squareof the resulting image after resizing. The default value is180.:shapedefines shape of the avator which can be either:circle(the default) or:square. In both cases the image is first center cropped to a square shape. Then if the format is:circlea circular image mask is applied.For other options see
Image.thumbnail/3.
returns
Returns
{:ok, avatar_image}or{:error, reason}
@spec avatar!(Vix.Vips.Image.t(), options :: Image.Options.Avatar.avatar_options()) :: Vix.Vips.Image.t() | no_return()
Make a circular or square image intended to be used as an avatar image or raise an exception.
The image is resized and all metadata is removed
from the image. Depending on the :shape option
the image may be center cropped to a square and
may have a circular mask applied.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options. The default is[shape: :cirlce, crop: :none].
options
Options
:sizeis the diameter (in the case ofshape: :circleor width/height in the case ofshape: :squareof the resulting image after resizing. The default value is180.:shapedefines shape of the avator which can be either:circle(the default) or:square. In both cases the image is first center cropped to a square shape. Then if the format is:circlea circular image mask is applied.For other options see
Image.thumbnail/3.
returns
Returns
avatar_imageorraises an exception.
linear_gradient(image, start \\ [0, 0, 0, 0], finish \\ [0, 0, 0, 255])
View Source@spec linear_gradient( Vix.Vips.Image.t(), start :: Image.Color.rgb_color(), finish :: Image.Color.rgb_color() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Create an image gradient of the same size as the given image.
The gradient will interpolate from the start
value to the finish value. The default start
value is black with 100% transparency. The
default finish value is black with 100% opacity.
start and finish are given as an rgb triplet
or quadruplet list of integers between 0 and 255.
arguments
Arguments
imageis anyVix.Vips.Image.t/0:start is anrgbtriplet or quadruplet list of numbers between0and255. *:finish is anrgbtriplet or quadruplet list of numbers between0and255.
returns
Returns
{:ok, gradient_image}or{:error, reason}
example
Example
# transparent_black and opaque_black are the default
# start and finish values
transparent_black = [0, 0, 0, 0]
opaque_black = [0, 0, 0, 255]
{:ok, gradient} = Image.linear_gradient(image, transparent_black, opaque_black)
linear_gradient!(image, start \\ [0, 0, 0, 0], finish \\ [0, 0, 0, 255])
View Source@spec linear_gradient!( Vix.Vips.Image.t(), start :: Image.Color.rgb_color(), finish :: Image.Color.rgb_color() ) :: Vix.Vips.Image.t() | no_return()
Create an image gradient of the same size as the given image. Returns the gradient image or raises and exception.
The gradient will interpolate from the start
value to the finish value. The default start
value is black with 100% transparency. The
default finish value is black with 100% opacity.
start and finish are given as an rgb triplet
or quadruplet list of integers between 0 and 255.
arguments
Arguments
imageis anyVix.Vips.Image.t/0:start is anrgbtriplet or quadruplet list of numbers between0and255. *:finish is anrgbtriplet or quadruplet list of numbers between0and255.
returns
Returns
gradient_imageorraises an exception.
example
Example
# transparent_black and opaque_black are the default
# start and finish values
transparent_black = [0, 0, 0, 0]
opaque_black = [0, 0, 0, 255]
gradient = Image.linear_gradient!(image, transparent_black, opaque_black)
@spec meme( image :: Vix.Vips.Image.t(), headline :: String.t(), options :: Image.Options.Meme.meme_options() ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Create a meme image from a base image and one or two lines of text.
The size of the text is determined by the size of the base image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0over which the meme text will be composed.headlineis the top line of the meme text.optionsis a keyword list of options.
options
Options
:textis the second line of text at the bottom of the meme image. The default is"".:text_sizeis the size of the bottom text in points. The default is calculated proportional to the size of the image.:headline_sizeis the size of the headline text in points. The default is calculated proportional to the size of the image.:fontis the name of the font family to be applied. The default isImpact.:font_fileis the path name to a font file that will be loaded. The default is:defaultwhich will load the includedImpactfont if the font family isImpact. If the font family is notImpactand the:font_fileis:defaultthen the font displayed is resolved by the underlying operating system. If:font_fileis a string, then it is expected to be a valid font file. If:font_fileis set to a path then the:fontoption should also be set to the correct font name.:weightis the font weight to be rendered. The options are:ultralight,:light,:normal,:bold,:ultrabold, and:heavy. The default:bold.:transformdetermines how the text is presented. The options are:upcase,:downcase,:capitalizeand:none. The default is:upcase.:coloris an RGB color of the text. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:white.:outline_coloris an RGB color of the text outline. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:black.:marginis the width of the margin in pixels. The margin is applied to both the left and right sides of the image. The default is calculated proportional to the size of the image.
@spec meme!( image :: Vix.Vips.Image.t(), headline :: String.t(), options :: Image.Options.Meme.meme_options() ) :: Vix.Vips.Image.t() | no_return()
Return a meme image from a base image and one or two lines of text or raise an exception.
The size of the text is determined by the size of the base image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0over which the meme text will be composed.headlineis the top line of the meme text.optionsis a keyword list of options.
options
Options
:textis the second line of text at the bottom of the meme image. The default is"".:text_sizeis the size of the bottom text in points. The default is calculated proportional to the size of the image.:headline_sizeis the size of the headline text in points. The default is calculated proportional to the size of the image.:fontis the name of the font family to be applied. The default isImpact. If the font family name is"Impact"then the includedunicode.impact.ttffont file will also be loaded. This ensures that theImpactfont is available on all systems.:font_fileis the path name to a font file that will be loaded. The default is:defaultwhich will load the includedImpactfont if the font family isImpact. If the font family is notImpactand the:font_fileis:defaultthen the font displayed is resolved by the underlying operating system. If:font_fileis a string, then it is expected to be a valid font file. If:font_fileis set to a path then the:fontoption should also be set to the correct font name.:weightis the font weight to be rendered. The options are:ultralight,:light,:normal,:bold,:ultrabold, and:heavy. The default:bold.:justifyis a boolean indicating if the headline and text are to be justified. Iftruethen space is added between words so that both edges of each line are aligned with both margins. The default isfalse.:transformdetermines how the text is presented. The options are:upcase,:downcase,:capitalizeand:none. The default is:upcase.:coloris an RGB color of the text. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:white.:outline_coloris an RGB color of the text outline. The color can be an integer between0..255, a three-element list of integers representing an RGB color or an atom representing a CSS color name. The default is:black.:marginis the width of the margin in pixels. The margin is applied to both the left and right sides of the image. The default is calculated proportional to the size of the image.
@spec radial_gradient( width :: pos_integer(), height :: pos_integer(), options :: Keyword.t() ) :: {:ok, %Vix.Vips.Image{ref: term()}} | {:error, error_message()}
Returns a radial gradient as an image.
This image might then be composited over another image.
arguments
Arguments
widthis the width of the gradient in pixels.heightis the height of the gradient in pixels.optionsis a keyword list of options. The default is[].
options
Options
:startis the color from which the gradient starts in the center of the image.:finishis the color at which the gradient finishes at the end of the gradient.:featheris the slope of the gradient. That it, how quickly the gradient moves from the:startcolor to the:finishcolor. The valid range is1..10representing the smallest amount of feather (harshest transition) to the largest amount of feather (smoothest transition).
returns
Returns
{:ok, gradient_image}or{:error, reason}
@spec rounded(Vix.Vips.Image.t(), Keyword.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Apply rounded corners to an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
:radiusis the desired corner radius. The default is 50.
returns
Returns
{:ok, rounded_corner_image}or{:error, reason}
Link to this section Split & Join
@spec alpha_band(Vix.Vips.Image.t()) :: 1..4 | nil
Returns the band number of the alpha channel of an image, or nil if it doesn't have one.
The determination is a heuristic so certainty cannot be guaranteed.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- An integer in the range
1..4depending on the image interpretation. Returnsnilif there is no alpha band. The integer is a 0-based offset and can therefore be directly used to access the band. For exampleimage[alpha_band(image)].
@spec split_bands(Vix.Vips.Image.t()) :: [Vix.Vips.Image.t()]
Split the image into a list of its component bands.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
- a list of single band images extracted
from
image.
Link to this section Color
@spec to_colorspace(Vix.Vips.Image.t(), Image.Interpretation.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Converts an image to the given colorspace.
Available colorspaces are returned from
Image.Interpretation.known_interpretations/0.
arguments
Arguments
imageis anyVix.Vips.Image.t/0colorspaceis any known colorspace. SeeImage.Interpretation.known_interpretations/0for a list of the known colorspaces.
returns
Returns
{;ok, image_in_new_colorspace}or{:error, reason}
example
Example
Image.to_colorspace(image, :bw)
@spec to_colorspace!(Vix.Vips.Image.t(), Image.Interpretation.t()) :: Vix.Vips.Image.t() | no_return()
Converts an impage to the given colorspace returning an image or raising an exception.
Available colorspaces are returned from
Image.Interpretation.known_interpretations/0.
arguments
Arguments
imageis anyVix.Vips.Image.t/0colorspaceis any known colorspace. SeeImage.Interpretation.known_interpretations/0for a list of the known colorspaces.
returns
Returns
image_in_new_colorspaceorraises an exception
example
Example
Image.to_colorspace!(image, :bw)
Link to this section Information
Returns the aspect of an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0optionsis a keyword list of options
options
Options
:square_ratioindicates when an image is to be considered square. It is a floating point indicator of the ratio between the width and height below which the image is considered square. The default is0.0meaning that the dimensions must be exactly equal in order for the image to be considered square.
returns
Returns
- Either
:landscape,:portraitor:square.
example
Example
iex> puppy = Image.open!(Path.expand("test/support/images/puppy.webp"))
iex> Image.aspect(puppy, square_ratio: 0.05)
:landscape
@spec bands(image :: Vix.Vips.Image.t()) :: pos_integer()
Return the number of bands in an image.
A band is sometimes referred to as a channel.
Note than bands are 0-indexed. That is, the first band is band 0, the second band is band 1 and so on.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- An integer number of bands in the image.
@spec dominant_color(Vix.Vips.Image.t(), Keyword.t()) :: Image.Color.rgb_color()
Returns the dominant color of an image as an RBG triplet value in an integer list.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options. The default is[].
options
Options
:binsis an integer number of color frequency bins the image is divided into. The default is10.
returns
Returns
[r, g, b]
@spec filename(image :: Vix.Vips.Image.t()) :: Path.t() | nil
Returns the filename for an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- The pathname from which the image was opened or
nilif there is no associated path. This can happen in the case of a streamed image or an image created from a memory buffer.
@spec has_alpha?(Vix.Vips.Image.t()) :: boolean()
Returns a boolean based upon whether a given image has an alpha band.
The determination is a heuristic so certainty cannot be guaranteed.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
trueorfalse
@spec height(image :: Vix.Vips.Image.t()) :: pos_integer()
Returns the height of an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- The image height as an integer.
@spec interpretation(image :: Vix.Vips.Image.t()) :: Image.Interpretation.t()
Returns the image interpretation.
The interpretation is how Image understands
the image date. For example, :srgb or
:cmyk or :bw.
For most common web applications, the
interpretation will be :srgb.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
- The image interpretation as an atom.
notes
Notes
@spec shape(image :: Vix.Vips.Image.t() | Vix.Vips.MutableImage.t()) :: {width :: pos_integer(), height :: pos_integer(), bands :: pos_integer()}
Returns the shape of an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- The image shape as a tuple of
{width, height, bands}.
@spec type(image :: Vix.Vips.Image.t()) :: Image.BandFormat.t()
Returns the data type of the image pixels.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
- The image type as a tuple in the same
format as
Nx.Type.t/0. For example{:u, 8}for a common:srgbimage.
@spec width(image :: Vix.Vips.Image.t()) :: pos_integer()
Returns the width of an image.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- The image width as an integer.
Link to this section Masks
@spec circle(Vix.Vips.Image.t(), Keyword.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Apply a circular mask to an image.
The returned image has an alpha band masking the circular image.
As a result, it is best saved to a
format, like .png that supports
alpha transparency.
Note that .jpg files do not support
alpha transparency.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
{:ok, circular_image}or{:error, reason}
@spec circle!(Vix.Vips.Image.t(), Keyword.t()) :: Vix.Vips.Image.t() | no_return()
Apply a circular mask to an image returning an image or raising an exception.
The returned image has an alpha band masking the circular image.
As a result, it is best saved to a
format, like .png that supports
alpha transparency.
Note that .jpg files do not support
alpha transparency.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
circular_imageorraises an exception.
@spec convert_to_mask(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Convert an image into a mask.
Takes an image, extracts its alpha channel which holds the opacity information and inverts the content.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
{:ok, mask}or{:error, reason}
@spec convert_to_mask!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
Convert an image into a mask returning an image or raising an exception.
Takes an image, extracts its alpha channel which holds the opacity information and inverts the content.
arguments
Arguments
imageis anyVix.Vips.Image.t/0
returns
Returns
maskimage orraises an exception
@spec rounded!(Vix.Vips.Image.t(), Keyword.t()) :: Vix.Vips.Image.t() | no_return()
Apply rounded corners to an image. Returns an image or raises an exception.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.optionsis a keyword list of options.
options
Options
:radiusis the desired corner radius. The default is 50.
returns
Returns
rounded_corner_imageorraises an exception.
Link to this section Metadata
Link to this section Nx & Evision
Converts to an Image image from an Evision.Mat image.
arguments
Arguments
evision_imageis anyEvision.Matimage.
returns
Returns
{:ok, image}
notes
Notes
Imageimages have the shape{width, height, bands}whereasEvisionimages have the shape{height, width, bands}so this function transposes the dimensions to match.Imagedata is arranged asrgbdata elements whereasEvisionrequires the data to be inbgrorder. This function also reorders the data appropriately.
@spec from_nx(tensor :: Nx.Tensor.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Converts an Nx tensor into an image.
arguments
Arguments
tensoris any three dimensionalNx.Tensor.t/0.optionsis a keyword list of options. For valid options seeNx.from_binary/2.
returns
Returns
{:ok, image}or{:error, reason}
notes
Notes
In order to convert a tensor into an image it must satisfy these constraints:
It must have three dimensions.
It must have a tensor type that is compatible with
libvips(most tensors will satisfy this requirement other than tensors whose type is complex).The names of the axes must be
[:width, :height, any_other]or[:height, :width, any_other].
example
Example
iex> {:ok, image} = Vix.Vips.Operation.black(3, 3)
iex> {:ok, tensor} = Image.to_nx(image)
iex> {:ok, _image_2} = Image.from_nx(tensor)
Converts an Image image to an Evision image.
Note that only images with 3 bands can be transferred
to eVision.
arguments
Arguments
imageis anyt:Vimage.t/0convert_to_bgris a boolean indicating if the color order should be converted fromRGBtoBGRwhich is the normal channel layout for OpenCV. The default istrue.
returns
Returns
{:ok, evision_image}
notes
Notes
Imageimages have the shape{width, height, bands}whereasEvisionimages have the shape{height, width, bands}so this function transposes the dimensions to match.Imagedata is arranged asrgbdata elements whereasEvisionrequires the data to be inbgrorder. This function also reorders the data appropriately.
@spec to_nx(image :: Vix.Vips.Image.t(), options :: Keyword.t()) :: {:ok, Nx.Tensor.t()} | {:error, error_message()}
Converts an image into an Nx tensor.
arguments
Arguments
imageis anyt:Vimage.t/0optionsis a keyword list of options
options
Options
:shapedetermines how the tensor is shaped. The valid values are::whbor:whcwhich leaves the tensor unchanged with the underlying data inwidth, height, bandsshape. This is the default action.:hwcor:hwbwhich reshapes the tensor toheight, width, channelswhich is commonly used for machine learning models.
returns
Returns
{:ok, tensor)where tensor is anNx.Tensor.t/0tensor suitable for use in theNxlibrary or{:error, reason}.
example
Example
iex> {:ok, image} = Vix.Vips.Operation.black(3, 3)
iex> Image.to_nx(image, backend: Nx.BinaryBackend)
{:ok,
Nx.tensor([[[0], [0], [0]], [[0], [0], [0]], [[0], [0], [0]]],
type: {:u, 8}, names: [:width, :height, :bands], backend: Nx.BinaryBackend)}
@spec to_nx!(image :: Vix.Vips.Image.t(), options :: Keyword.t()) :: Nx.Tensor.t() | no_return()
Converts an image into an Nx tensor.
arguments
Arguments
imageis anyt:Vimage.t/0optionsis a keyword list of options
options
Options
:shapedetermines how the tensor is shaped. The valid values are::whbor:whcwhich leaves the tensor unchanged with the underlying data inwidth, height, bandsshape. This is the default action.:hwcor:hwbwhich reshapes the tensor toheight, width, channelswhich is commonly used for machine learning models.
returns
Returns
tensorwhere tensor is anNx.Tensor.t/0tensor suitable for use in theNxlibrary orraises an exception.
example
Example
iex> {:ok, image} = Vix.Vips.Operation.black(3, 3)
iex> Image.to_nx!(image, backend: Nx.BinaryBackend)
Nx.tensor([[[0], [0], [0]], [[0], [0], [0]], [[0], [0], [0]]],
type: {:u, 8}, names: [:width, :height, :bands], backend: Nx.BinaryBackend)
Link to this section Preview
@spec p(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | {:error, error_message()}
Outputs an inline preview of an image to an iTerm2 terminal.
Only iTerm2 terminal windows are supported.
Delegates to Image.preview/1
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
notes
Notes
The function
Image.p/1is delegated to this function.The maximum width of the preview can be set by the environment variable
IMAGE_PREVIEW_MAX_WIDTH. The default is1_000pixels wide. If the width of the image is greater than the maximum it will be resized to the maximum width for the preview.Intended to be used as shortcut in
iex. It can be included in.iex.exsfile:# .iex.exs import_if_available(Image, only: [p: 1])
@spec preview(Vix.Vips.Image.t() | {:ok, Vix.Vips.Image.t()}) :: Vix.Vips.Image.t() | {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Outputs an inline preview of an image to an iTerm2 terminal.
Only iTerm2 terminal windows are supported.
arguments
Arguments
imageis anyVix.Vips.Image.t/0or a tuple of the form{:ok, image}.
returns
Returns
- The
imageparameter as provided with the side effect of emitting an image preview on an iTerm terminal.
notes
Notes
The function
Image.p/1is delegated to this function.The maximum width of the preview can be set by the environment variable
IMAGE_PREVIEW_MAX_WIDTH. The default is1_000pixels wide. If the width of the image is greater than the maximum it will be resized to the maximum width for the preview.Intended to be used as shortcut in
iex. It can be included in an.iex.exsfile:# .iex.exs import_if_available(Image, only: [preview: 1])
Link to this section Guards
Guards whether the coordinates can be reasonably interpreted as a bounding box.
left and top when positive are relative to
the left and top of the image respectively. When
negative they are relative to the right and bottom
of the image.
Guards whether a value is a percentage as representeed
by a float between -1.0 and 1.0.
Guards whether a term might be reasonably interpreted as an image pixel.
Guards whether a value is a positive percentage as representeed
by a float greater than 0.0 and less than or equal to 1.0.
Guards whether a parameter is a rectangular bounding box. A rectangular bounding box is a list of four 2-tuples that must represent a rectangle (not an arbitrary quadrilateral),
The order of points is top_left -> top right -> bottom right -> bottm left.
Guards whether a number can be reasonably interpreted as a size (as in size of a crop or mask)
Link to this section libvips Configuration
@spec get_concurrency() :: pos_integer()
Returns the number of operating system
threads available for use by libvips.
By default the number of threads will be the number of cores in the system.
Since image processing is CPU intensive it may be appropriate to reduce the number of threads to be available to reduce the risk of CPU starvation for other workloads.
@spec put_concurrency(pos_integer()) :: pos_integer()
Sets the number of available threads for use
by libvips.
By default this is the same as the number of cores in the system. Reducing this number may prevent CPU starvation for other workloads.
arguments
Arguments
concurrencyis a positive integer denoting the maximum number of threads thatlibvipswill use for concurrency.
returns
Returns
{:ok, updated_concurrency}
@spec vips_version() :: {:ok, Version.t()}
Returns the version of libvips in
operation.
Link to this section Functions
@spec average(Vix.Vips.Image.t()) :: Image.Color.t() | {:error, error_message()}
Returns the average color of an image.
The average is calculated for each band of an image and then combined.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- A list of average pixel values which can be interpreted as the average color of the image.
example
Example
iex> Image.open!("./test/support/images/Hong-Kong-2015-07-1998.jpg")
...> |> Image.average()
[66, 86, 106]
@spec average!(Vix.Vips.Image.t()) :: Image.Color.t() | no_return()
Returns the average color of an image or raises and exception.
The average is calculated for each band of an image and then combined.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.
returns
Returns
- A list of average pixel values which can be interpreted as the average color of the image.
example
Example
iex> Image.open!("./test/support/images/Hong-Kong-2015-07-1998.jpg")
...> |> Image.average!()
[66, 86, 106]
@spec from_kino(image :: kino_image(), options :: Keyword.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Returns an image from a Kino image input.
arguments
Arguments
imageis a a map returned fromKino.Input.read(image)via aKino.Input.image/1input field. The data will have the following fields::datawhich contains the raw binary of the image:widthwhich is the width of the image in pixels:heightwhich is the height of the image in pixels:formatwhich is the image band format which must be:rgb
optionsis a keyword list of options
options
Options
:bandsindicates the integer number of bands (channels) in the image. The default is3.
notes
Notes
- The image is assumed to contain pixel data that is in unsigned 8-bit format which is common for most web-oriented images.
returns
Returns
{:ok, image}or{:error, reason}
@spec from_kino!(image :: kino_image(), options :: Keyword.t()) :: Vix.Vips.Image.t() | no_return()
Returns an image from a Kino image input or raises an exception.
arguments
Arguments
imageis a a map returned fromKino.Input.read(image)via aKino.Input.image/1input field. The data will have the following fields::datawhich contains the raw binary of the image:widthwhich is the width of the image in pixels:heightwhich is the height of the image in pixels:formatwhich is the image band format which must be:rgb
optionsis a keyword list of options
options
Options
:bandsindicates the integer number of bands (channels) in the image. The default is3.
notes
Notes
- The image is assumed to contain pixel data that is in unsigned 8-bit format which is common for most web-oriented images.
returns
Returns
{:ok, image}orraises an exception.
Guards whether the given struct is an image type
either Vix.Vips.Image or Vix.Vips.MutableImage.
@spec without_alpha_band( Vix.Vips.Image.t(), (Vix.Vips.Image.t() -> {:ok, Vix.Vips.Image.t()} | {:error, error_message()}) ) :: {:ok, Vix.Vips.Image.t()} | {:error, error_message()}
Execute a function over the image without its alpha band (if any) ensuring the alpha band is replaced when the function returns.
arguments
Arguments
imageis anyVix.Vips.Image.t/0.funis any 1-arity function that is required to return{:ok, image}or{:error, reason}.
returns
Returns
{:ok, image}or{:error, reason}