Carta - Generate images from HTML

Hi :waving_hand:,

I’m building an open source Elixir blog engine, for which I needed a way to generate OG images from HTML templates, and after having that built, I decided to extract it into a separate Elixir package.

Carta is an HTML to image Elixir package. It uses a pool of headless Chrome instances under the hood. My suggestion if you plan to use it for the same thing is that you use our provided hash to cache them in object storage and serve them from there in the future since hitting the Chrome pool for every request is inefficient.

2 Likes

Hi, good library. I’ve read the code and here are my comments

  1. It creates a task mix version to bump version of project in mix.exs. I think it is out of scope of this library
  2. Templates must be EEx files on disk, its not possible to render a string template
  3. It renders only EEx templates. Its not possible to just render a ready HTML. And I think that users can handle a single EEx.eval_string |> Carta.render, so rendering a template is outside of the scope of the library. Handling template rendering over to the library user is a bit more universal approach since user may user non-EEx templates, or just use a plain HTML
  4. Have you considered using Wallaby? It has all the browser functionality you need, it supports both Selenium API and Chromium API, allowing you to render images with any modern browser
  5. I think that it would be better if users could start their browser pools manually, instead of the dependency starting the pool for them based on application configuration. Thats important because starting this dependency with pool_size: 0 in configuration results in crash:
    ** (ArgumentError) pool_size must be a positive integer, got: 0
        (nimble_pool 1.1.0) lib/nimble_pool.ex:398: NimblePool.start_link/1
    
1 Like

Hey @Asd :waving_hand:

Thanks for your feedback. Let me address it

I agree. I published a new version that removes it.

I removed this concern from the library, so now it just takes the HTML content, and does the rendering.

Wallaby requires the indirection of a separate binary driver (ChromeDriver). I designed Carta to take a different approach using a pool and direct communication with the browser using CDP in the case of Chrome, and NIF bindings in the case of Servo (WIP).

This should also be addressed in this new release. You can configure a pool and pass it when calling the Carta APIs.

1 Like