View Source Vix.Vips.Image (vix v0.9.0)
Functions for reading and writing images as well as accessing and updating image metadata.
The Access
behaviour is implemented to allow
acccess to image bands. For example image[1]
. Note that
due to the nature of images, pop/2
and put_and_udpate/3
are not supported.
Link to this section Summary
Functions
Get "bands" of the image
Get "coding" of the image
Get "filename" of the image
Get "format" of the image
Return a boolean indicating if an image has an alpha band.
Get all image header field names.
Get image header value.
Get image header value as string.
Get "height" of the image
Get "interpretation" of the image
Get "mode" of the image
Mutate an image in-place. You have to pass a function which takes MutableImage as argument. Inside the callback function, you can call functions which modify the image, such as setting or removing metadata. See Vix.Vips.MutableImage
Get "n-pages" of the image
Create a new image from formatted binary bin
. Binary should be an
image encoded in a format such as JPEG. It tries to recognize the
format by checking the binary.
Opens path
for reading, returns an instance of Vix.Vips.Image.t/0
Creates a new image with width, height, format, interpretation, resolution and offset taken from the input image, but with each band set from value
.
Make a VipsImage from list.
Make a VipsImage which, when written to, will create a temporary file on disc.
Get "offset" of the image
Get "orientation" of the image
Get "page-height" of the image
Get "scale" of the image
Get "width" of the image
Returns vips_image
as binary based on the format specified by suffix
. This function is similar to write_to_file
but instead of writing the output to the file, it returns it as a binary.
Write vips_image
to a file.
Get "xoffset" of the image
Get "xres" of the image
Get "yoffset" of the image
Get "yres" of the image
Link to this section Types
Specs
t() :: %Vix.Vips.Image{ref: reference()}
Represents an instance of VipsImage
Link to this section Functions
Specs
Get "bands" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-bands
Specs
Get "coding" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-coding
Specs
Get "filename" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-filename
Specs
Get "format" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-format
Specs
Return a boolean indicating if an image has an alpha band.
Example
{:ok, im} = Image.new_from_file("puppies.jpg")
has_alpha? = Image.has_alpha?(im)
Specs
Get all image header field names.
See https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-fields for more details
Specs
header_value(t(), String.t()) :: {:ok, integer() | float() | String.t() | binary() | list()} | {:error, term()}
Get image header value.
This is a generic function to get header value.
Casts the value to appropriate type. Returned value can be integer, float, string, binary, list. Use Vix.Vips.Image.header_value_as_string/2
to get string representation of any header value.
{:ok, width} = Image.header_value(vips_image, "width")
Specs
Get image header value as string.
This is generic method to get string representation of a header value. If value is VipsBlob, then it returns base64 encoded data.
See: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-as-string
Specs
Get "height" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-height
Specs
Get "interpretation" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-interpretation
Specs
Get "mode" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-mode
Specs
mutate(t(), (Vix.Vips.MutableImage.t() -> any())) :: {:ok, t()} | {:error, term()}
Mutate an image in-place. You have to pass a function which takes MutableImage as argument. Inside the callback function, you can call functions which modify the image, such as setting or removing metadata. See Vix.Vips.MutableImage
Return value of the callback is ignored.
Call returns updated image.
Example
{:ok, im} = Image.new_from_file("puppies.jpg")
{:ok, new_im} =
Image.mutate(im, fn mut_image ->
:ok = MutableImage.update(mut_image, "orientation", 0)
:ok = MutableImage.set(mut_image, "new-field", :gint, 0)
end)
Specs
Get "n-pages" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-n-pages
Specs
Create a new image from formatted binary bin
. Binary should be an
image encoded in a format such as JPEG. It tries to recognize the
format by checking the binary.
If you already know the image format of bin
then you can just use
corresponding loader operation function directly from
Vix.Vips.Operation
instead. For example to load jpeg, you can use
Vix.Vips.Operation.jpegload_buffer/2
The options available depend on the file format. Try something like:
$ vips jpegload_buffer
Not all loaders support load from buffer, but at least JPEG, PNG and TIFF images will work.
Specs
Opens path
for reading, returns an instance of Vix.Vips.Image.t/0
It can load files in many image formats, including VIPS, TIFF, PNG, JPEG, FITS, Matlab, OpenEXR, CSV, WebP, Radiance, RAW, PPM and others.
Load options may be appended to filename as "[name=value,...]". For example:
Image.new_from_file("fred.jpg[shrink=2]")
Will open "fred.jpg", downsampling by a factor of two.
The full set of options available depend upon the load operation that will be executed. Try something like:
$ vips jpegload
at the command-line to see a summary of the available options for the JPEG loader.
If you want more control over the loader, Use specifc format loader from Vix.Vips.Operation
. For example for jpeg use Vix.Vips.Operation.jpegload/2
Loading is fast: only enough of the image is loaded to be able to fill out the header. Pixels will only be decompressed when they are needed.
Specs
Creates a new image with width, height, format, interpretation, resolution and offset taken from the input image, but with each band set from value
.
Specs
Make a VipsImage from list.
This convenience function makes an image which is a matrix: a one-band VIPS_FORMAT_DOUBLE image held in memory. Useful for vips operations such as conv
.
mask = Image.new_matrix_from_array(3, 3, [[0, 1, 0], [1, 1, 1], [0, 1, 0]])
optional
Optional
- scale - Default: 1
- offset - Default: 0
Specs
Make a VipsImage which, when written to, will create a temporary file on disc.
The file will be automatically deleted when the image is destroyed. format is something like "%s.v"
for a vips file.
The file is created in the temporary directory. This is set with the environment variable TMPDIR. If this is not set, then on Unix systems, vips will default to /tmp
. On Windows, vips uses GetTempPath()
to find the temporary directory.
vips_image = Image.new_temp_file("%s.v")
Specs
Get "offset" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-offset
Specs
Get "orientation" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-orientation
Specs
Get "page-height" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-page-height
Specs
Get "scale" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-scale
Specs
Get "width" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-width
Specs
Returns vips_image
as binary based on the format specified by suffix
. This function is similar to write_to_file
but instead of writing the output to the file, it returns it as a binary.
Currently only TIFF, JPEG and PNG formats are supported.
Save options may be encoded in the filename or given as a hash. For example:
Image.write_to_buffer(vips_image, ".jpg[Q=90]")
The full set of save options depend on the selected saver. You can get list of available options for the saver
$ vips jpegsave
Specs
Write vips_image
to a file.
Save options may be encoded in the filename or given as a hash. For example:
Image.write_to_file(vips_image, "fred.jpg[Q=90]")
A saver is selected based on path
. The full set of save options depend on the selected saver. Try something like:
$ vips jpegsave
at the command-line to see all the available options for JPEG save.
If you want more control over the saver, Use specifc format saver from Vix.Vips.Operation
. For example for jpeg use Vix.Vips.Operation.jpegsave/2
Specs
Get "xoffset" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-xoffset
Specs
Get "xres" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-xres
Specs
Get "yoffset" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-yoffset
Specs
Get "yres" of the image
see: https://libvips.github.io/libvips/API/current/libvips-header.html#vips-image-get-yres