kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir.
Image is intended to provide well-documented, performant and reliable common image processing functions in an idiomatic Elixir functional style. It operates at 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.
Since Image is based upon Vix and libvips it is performant, concurrent, pipelining and has a low memory footprint.
In this first release it focuses on resizing, cropping, masking, corner rounding, circular cropping, metadata extract, metadata minimisation. It also includes some simple functions to make it easy to resize and compress images for many well-known social media platforms at the correct size.
In the next two releases, Image will:
- Provide streamed image processing. That will allow an image to be streamed from a file, or from S3 or from any Elixir stream or enumerable, process the image and then stream its output - including to chunked responses for HTTP applications.
- Provide bi-directional Integration with Nx that will efficiently share memory buffers and make it even simpler to involve image processing in ML applications.
Simple examples
Resize to fit
Image.resize(image, 200, crop: :none)
Resize to fill
Image.resize(image, 200, crop: :attention)
Crop image
Image.crop!(image, 550, 320, 200, 200)
Rounded corners
image |> Image.resize!(200, crop: :attention) |> Image.rounded!()
Avatar (circular mask, remove most metadata, crop to a subject of interest)
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
webuhu
Wonderful.
Mind to tag within the repository for the
ex_docsource links and links on Hex.kip
Whoops, sorry about that. Done!
jeroenvisser101
Hey Kip, this is awesome! In addition to streaming, to ‘streamline’ the API, will you also add functions to load images from Memory, and will the S3-thing be a behaviour so other backends (such as GCS) can be added as well?
PS. Have you considered applying for GitHub Sponsors? I would love to sponsor you there as I use many (or even all) of your libraries, and would love to help even if in a small way! If you do, let me know
mayel
This looks great! I’ve been using imagemagick via Mogrify so far and while I’d like to use vips, I would prefer having the option to shell out rather than using the NIF when dealing with user-uploaded images (for the reasons you point out in your readme). Is this something you would consider adding to the library?
AndrewDryga
@kip does it support overlays (drawing an image on top of another one), transparency, and writing a text on an image?
Exadra37
Something like shown in the animation in the home page of:
kip
vixandlibvipssupport everything you can think of, possibly even making you coffee in the morning. Text overlays are definitely on the list of features to expose. I’ve been working on what the right API should look like - feedback welcome. In the Vix readme there is an example of rendering a text overlay (see below).@mayel, I understand the concern, and this is of course a benefit of using mogrify. Nevertheless, shelling out doesn’t resolve the issue of maliciously crafted images, and there is a long history of CVEs. So while you avoid a crash in
mogrifybringing down the BEAM, there are other issues. Its a tradeoff.Image, which depends onVix, is firmly wedded tolibvipsas a NIF. I am going to try some experiments in runningImagein its own BEAM node but that’s as far as it will go. I have to note that so far the stability has been excellent - only crashing when I made a poorly written addition to the NIF (which @akash-akya promptly fixed).kip
@jeroenvisser101, the streaming API will do exactly what you want. @akash-akya has an experimental branch with the NIF implementation that basically means that image streaming can consume any
Enumerableand as an output can produce anEnumerable.This is fabulous for taking an
S3image, transforming it, and sending it as a chunked image in an HTTP request. There are many other use cases, but I think that one is high on the list of valuable capabilities.Which is why it will be part of the
Image 0.2release in a week or so.If you’re interested you can take a look at these tests in
Vix.kip
A couple of addition thoughts on the overall imaging pipeline strategy. What appeals to me about a library based upon
libvipsis that it is fast, has a small memory footprint and has really good concurrency support. These alone are for me enough to accept the potential issues with a NIF-based solution.When you also have:
libvipsthat is very friendly for a NIF implementation. This because only references are ever passed from Elixir-land to NIF-land so no large memory copies.libvipsthat means transformation evaluation is only done at the point at which an image is rendered (either by writing to a file or sending to a client for example). Its very efficient.Then I think
libvipswithVixis a really strong platform - as long as the concerns relevant to any NIF-based solution are recognised. Its analogous a little bit toNx, the benefits outweigh the risks for a number of use cases.AndrewDryga
We are processing a ton of images with internal service that works on top of graphicsmagick but we faced many issues with it (like it can corrupt its internal miff format during text-based transforms). We have a workaround for those but libvips is also an option so I was asking if the library supports that, so maybe we can run an experiment replacing gm with vix. We don’t need external services.