Generate images with name initials using Elixir and ImageMagick

https://sergiotapia.me/generate-images-with-name-initials-using-elixir-and-imagemagick-374eca4d14ff


Hope this saves you guys some time! Using ImageMagick and some fancy flags is all you need to generate nice initial avatars for your users.

5 Likes

Unfortunately this link is dead…
Does anyone have another recommended link for this purpose?

maybe http://tapia49.rssing.com/chan-5508682/all_p2.html#item35

(near the bottom of the page) -> 02/21/18–08:04: Generate images with name initials using Elixir and ImageMagick.

3 Likes

Thank you random chinese bot scraper website! I lost my old blog and now I can recover this post!

5 Likes

I made a new package that uses your PNG generation code:

4 Likes

That’s amazing bro!

1 Like

Thanks for the motivation to fix a couple of bugs in Image. As of version 0.26.0 its easier to generate text-based avatars and to produce either square or circular avatars.

There’s no specific support for text-based background color generation but that might be interesting to add to the Image.Color module.

iex> Image.avatar!("./test/support/images/Kip_small.jpg", shape: :square)

image_avatar_square

iex> Image.avatar!("./test/support/images/Kip_small.jpg", shape: :circle)

image_avatar_circle

iex> Image.Text.text!("KC", background_fill_color: :cyan, font_size: 200, padding: 80) 
...> |> Image.avatar!(shape: :square) 

text_avatar_square

iex> Image.Text.text!("KC", background_fill_color: :cyan, font_size: 200, padding: 80) 
...> |> Image.avatar!(shape: :circle) 

text_avatar_circle

Since Image is based on vix and libvips the code is fast and memory efficient. Definitely faster than using ImageMagick since vix is NIF based. And generally considered more secure that ImageMagick too.

10 Likes