Packages
vix
0.3.0
0.40.0
0.39.0
0.38.0
0.37.0
0.36.0
0.35.0
0.34.0
0.33.1
0.33.0
0.32.0
0.31.1
0.31.0
0.30.0
0.29.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.0
0.23.1
0.22.0
0.21.0
0.20.0
0.19.0
0.18.0
0.17.0
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.1
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.0
0.8.0
0.7.0
0.6.1
0.6.0
0.5.0
0.4.0
0.3.0
0.2.1
0.2.0
retired
0.1.0
NIF based bindings for libvips
Current section
Files
Jump to
Current section
Files
README.md
# Vix [](https://hex.pm/packages/vix)
Vix is Elixir extension for [vips](https://libvips.github.io/libvips/).
Vix is a **NIF bindings** for libvips. Image Operation binding are generated using vips introspection, so documentation and bindings will be in-sync with the vips version installed. It uses dirty IO scheduler to avoid blocking main schedulers.
Check [vips operation documentation](https://hexdocs.pm/vix/Vix.Vips.Operation.html) for the list of available operations and spec.
### What is Vips
*(from vips documentation)*
> libvips is a [demand-driven, horizontally threaded](https://github.com/libvips/libvips/wiki/Why-is-libvips-quick) image processing library. Compared to similar libraries, [libvips runs quickly and uses little memory](https://github.com/libvips/libvips/wiki/Speed-and-memory-use).
See [libvips documentation](https://libvips.github.io/libvips/API/current/How-it-works.md.html) for more details.
### Example
```elixir
alias Vix.Vips.Image
alias Vix.Vips.Operation
def example(path) do
{:ok, im} = Image.new_from_file(path)
# put im at position (100, 100) in a 3000 x 3000 pixel image,
# make the other pixels in the image by mirroring im up / down /
# left / right, see
# https://libvips.github.io/libvips/API/current/libvips-conversion.html#vips-embed
{:ok, im} = Operation.embed(im, 100, 100, 3000, 3000, extend: :VIPS_EXTEND_MIRROR)
# multiply the green (middle) band by 2, leave the other two alone
{:ok, im} = Operation.linear(im, [1, 2, 1], [0])
# make an image from an array constant, convolve with it
{:ok, mask} =
Image.new_matrix_from_array(3, 3,
[
[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]
],
scale: 8
)
{:ok, im} = Operation.conv(im, mask, precision: :VIPS_PRECISION_INTEGER)
# finally, write the result back to a file on disk
:ok = Vix.Vips.Image.write_to_file(im, "out.jpg")
end
```
The [libvips reference manual](https://libvips.github.io/libvips/API/current/) has a complete explanation of every method.
### Simple *unscientific* comparison with mogrify
For generating thumbnail
| | Vix | Mogrify |
|---|-----------|-----------|
| 1 | 298.731ms | 618.854ms |
| 2 | 29.873ms | 605.824ms |
| 3 | 34.479ms | 609.820ms |
| 4 | 31.339ms | 604.712ms |
| 5 | 32.526ms | 605.553ms |
The significant reduction in operation-time for subsequent calls is because of [operation caching](https://libvips.github.io/libvips/API/current/VipsOperation.html) in vips.
### Warning
This library is experimental. Interface might change significantly in the future versions. The code is not well tested, so you might experience crashes.
### Requirements
* libvips
* pkg-config
* c compiler
## Installation
```elixir
def deps do
[
{:vix, "~> x.x.x"}
]
end
```
### TODO
- [ ] support mutable operations such as draw*
- [ ] support `VipsConnection`(?)
- [ ] support all remaining vips types