sergio

sergio

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.

Most Liked

kip

kip

ex_cldr Core Team

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)

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

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

iex> Image.Text.text!("KC", background_fill_color: :cyan, font_size: 200, padding: 80) 
...> |> Image.avatar!(shape: :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.

11
Post #9
sergio

sergio

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

maz

maz

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

patrickdm

patrickdm

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.

sergio

sergio

That’s amazing bro!

Where Next?

Popular in Guides/Tuts Top

njwest
Greetings: I just wrote a step-by-step guide on building a Phoenix 1.3 JWT Auth API with Guardian JWTs and Comeonin password hashing. I ...
New
jtormey
Hello! Having written a lot of LiveView code, I’ve made some VS Code snippets to speed up writing callbacks for LiveViews and LiveCompon...
New
TwistingTwists
This is a thread to note down things/best practices encountered in LiveBeats App as I explore the source code. Found this usage of r...
New
dmitriid
This is not a question, but a post for anyone who may need it in the future. Sometimes some browsers may mangle the filename if it’s non-...
New
AstonJ
This was originally posted on my blog, but since my I’ve taken it down (I hadn’t posted anything on it for a while and since it was runni...
New
ben-pr-p
Hey all! I put together a starter-pack / instructions to set up Phoenix with the new parcel-bundler instead of brunch (or webpack). It’s...
New
anuragg
We just published a guide to automatic clustering in Elixir 1.9, with Mix releases and libcluster. The cluster automatically discovers n...
New
kevinlang
Hey all, With Phoenix 1.6 just around the corner, I figured I’d make a tutorial on how to add Bulma to a new Phoenix 1.6 project. By lev...
New
AstonJ
With a few questions relating to this recently, I wonder if it might help having a thread where we share how we’ve set up Elixir/Erlang/P...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement