I have some ideas I would like to share with you, since I can’t do them :
Color palette detection, for theming purposes. (Like say a page displays an image, it can color itself based on the palette of the image, or it can be used for showing a dominant color, before the image loads.)
Color grading images based on LUT provided. (For consistent look and feel of the site)
Rendering a HEEX template, a webpage or a section of a webpage, or svg into an image without using headless chrome if possible. (To allow creation of badges like shields.io, or run in LiveBook badge, or images that can be used in profiles like GitHub or Twitter or Linked, like GitHub Readme Stats)
Video to gif or something better.
Some default / custom placeholder image in case of error.
For instance, how do I introduce a ML trained model to the pipeline. (E.g. Object detection using YOLO ML Algo, or Image scale using a machine model.)
How to introduce compression step into the pipeline.
General examples like the ones you have put in this discussion thread are missing in the official docs page. (I would have not been able to imagine such things are possible by looking at the API )
P.S. I skimmed through the API Documentation, so I don’t know if some of the suggestions are already possible. I hope there are examples in the future for every thing this library is capable of.
P.P.S. It’s incredible how many APIs are present in that library, so I feel ashamed asking for more.
I appreciate the suggestions, they are very welcome. Some may be possible.
Color palette detection, for theming purposes. (Like say a page displays an image, it can color itself based on the palette of the image, or it can be used for showing a dominant color, before the image loads.)
I’ve got another lib called Color in development that implements color science and John Cullpit, the author of libvips, has agreed to put k-means of an image in the next release which is very helpful for palette optimisation.
Color grading images based on LUT provided. (For consistent look and feel of the site)
Color grading I also want to do since photography is a passion of mine and managing color is very helpful. May be possible, there are some LUT capabilities in libvips and vision. Also complementary, analogous, split complementary, triadic color calculation.
Nothing special in libvips for that but I’ll take a look. Lower priority in my mind.
Rendering a HEEX template, a webpage or a section of a webpage, or svg into an image
Not available directly in libvips. It renders SVG into images really well using librsvg but not html.
Video to gif or something better.
I’m more likely to do gif to video since that the more common trend I’m seeing?
Some default / custom placeholder image in case of error.
Yes, that makes sense. Will think about what that might look like.
Documentation
Absolutely - I will work on tutorial and user guide style docs using Livebook as the platform as a priority before version 1.0. It all takes a lot of time …
Amazing work on this lib kip, can see this becoming the defacto lib for Elixir regarding common Image tasks.
The idea is not to wrap OpenCV (eVision) completely right, just the most common image tasks with higher level abstractions on top, I guess?
Yes, you are right. Both Vix and eVision are great libraries and there’s little value in just wrapping them. But there is value, I think, providing more idiomatic interfaces to common higher level image processing functions.
I also hope that this work demonstrates that image processing on Elixir is definitely possible - and not just possible, really can be a joy leveraging everything Elixir brings to the table as well as the power of the underlying libs.
One of the unifying reasons why Image builds on top of both Vix and eVision is the ability for both libraries to reuse binary image data without copying it. That makes interoperation really performant. For example, for QR code generation the matrix is generated in eVision but resized using Vix. But no data is copied. Similar for the Nx integration.
It probably doesn’t make sense to wrap any other libraries if they don’t also have a compatible in-memory model. However given the explosion of imaging capabilities I would like to find a way to keep the imaging eco-system as easy to adopt at the higher level as possible without losing the ability to go as low as you want.
As for OG Image generation, if the rendering can be accomplished by librsvg then Vix and/or Image might be a fast way to get started. I didn’t look closely enough but it did look somewhat SVG-centric. I just haven’t explored if librsvg supported HTML embedded SVG. And I don’t think it will support tailwind classes out of the box (I see the Vercel lib uses the same class names but with a different attribute name?).
Overall, just happy to see an emerging vibrant community of people interested in image processing and some amazing tooling being build, especially by @akash-akya and @cocoa.
I wanted to tell you about blurhash, for placeholder purposes, which I forgot to link in my previous comment!!
They have a funny description too:
Does your designer cry every time you load their beautifully designed screen, and it is full of empty boxes because all the images have not loaded yet? Does your database engineer cry when you want to solve this by trying to cram little thumbnail images into your data to show as placeholders?
BlurHash generates incredibly small previews using Base83 encoding. Base83 encoding allows it to squeeze more information into fewer bytes, which is part of how it keeps the previews so small.
Which means in front end JavaScript is needed for preview!
An alternative to generate blurry placeholder, that doesn’t need JavaScript on front end is SQIP, which is based on SVG:
A great side-effect of using SVG as the basis for image previews is that SVG is a plaintext asset and therefore benefits from compression by gzip, zopfli and brotli. Using these compression techniques cuts SQIP size down by half, reaching the minimum viable raster LQIP size of ~400-600 bytes while providing a superior user experience.
Thats very interesting, thanks for posting. I especially like that the original primitive is based upon libvips so I think there’s a probably a reasonable path forward. And I like the idea of SVG-based placeholders since they inline well and compress well.
Also, it’s just a really interesting algorithm and artistic outputs.
Hmmm, looks like there’s another rabbit hole I’m diving down …
It would be great if Image.Options.Crop.crop_focus() could have a focal point {x_percent, y_percent} too. It’s really nice to have an Image in your backend with a little dot you can drag to choose the focal point of the image. Then we can crop around this point:
Here it’s x=17 and y=48 (in percent) which means if I had a portrait crop here it would crop around this point (as far as is possible of course). It’s pretty neat!
Hey I just open-sourced a library that we use in production that do just that (with the imaginary format, a popular go image proxy server). We could abstract the parsing of the URL to be compatible with other popular tools. Right now it supports streaming images from arbitray URL, url signature of useful transform operation from Vix.
It would be great if Image.Options.Crop.crop_focus() could have a focal point {x_percent, y_percent}
Great suggestion and happy to do that. Will get that out the door this weekend.
The process will be a little more expensive since Image.thumbnail/3 doesn’t take that option natively. So basically I will crop from the provided centre-point and then set the :centre option to :focus to get the result you’re after.
Fixed on main branch if you’re willing to try it from there. I have a couple of additional tests and then will publish an update to hex. Thanks for pointing out the issue.
You missed the spec for Image.write! which still states that Vimage.t() | no_return() is returned. I changed the code to use write() and dialyzer is happy. (As am I, very nice lib!)
I know I’m asking for the moon and the stars Is there a way to put text on an image within a bounding box?
Let’s say, I need to add a caption on top of an image in the lower half of it, but I don’t know beforehand how long the text is? Basically, best fit caption from ImageMagick?
Definitely possible to do, will need a few hours to get back with the details (day job getting in the way). Might be a bit tricky to auto-size the text to make it fit in a bounding box. But putting text in a bounding box - can do.