david

david

Avatarex - Generate unique, reproducible avatars from hashed strings

Avatarex is an elixir package for generating unique, reproducible Avatars from hashed strings.
The package is inspired by Robohash

Hey everyone! I’ve been working on a personal project and was in want of some unique placeholder avatars for my users. I really love the Robohash python lib, but wanted something a bit for “functional”. So here’s what I put together this weekend.


Current Avatar sets include Birdy and Kitty avatars created using images created
by David Revoy and used under CC-BY-4.0.

You can create your own avatar sets, see the AvatarexSet docs for more details.

Images are generated using @kip’s Image elixir package.

Note: The package is currently under development but is up on hex.

Cheers

Most Liked

Eiji

Eiji

Looks like there is a bug in this line:
https://github.com/davidkuhta/avatarex/blob/ecaa02a90558c8dfd6432100b408b32a00f79e83/lib/avatarex/Kitty.ex#L10
it should be:

:avatarex |> :code.priv_dir() |> Path.join(~w[sets kitty])

Same patch should be applied to the birdy

Unfortunately current macro code does not allow it and I was in need to use it like:

defmodule Kitty do                               
  use AvatarexSet,
    dir: "deps/avatarex/priv/sets/kitty",
    keys: [:body, :eye, :fur, :mouth, :accessory]
end

which cannot be used in prod environment static paths are not guaranteed to work in all environments and therefore you should support: :code.priv_dir/1.

Similarly the macro does not allows to use a sigil for keys i.e.:

defmodule Kitty do                                                  
  use AvatarexSet,                                                  
    dir: "deps/avatarex/priv/sets/kitty",                                 
    keys: ~w[body eye fur mouth accessory]a
end
** (Protocol.UndefinedError) protocol Enumerable not implemented for {:sigil_w, [delimiter: "[", line: 5], [{:<<>>, [line: 5], ["body eye fur mouth accessory"]}, 'a']} of type Tuple. This protocol is implemented for the following type(s): Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Range, Stream
    (elixir 1.14.4) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.14.4) lib/enum.ex:166: Enumerable.reduce/3
    (elixir 1.14.4) lib/enum.ex:4307: Enum.reduce/3
    (avatarex 0.1.0) expanding macro: AvatarexSet.__using__/1

The other problem is priv/renders. Once again there should be a :code.priv_dir/1 call. To support priv directory for current project you should use otp_app and pass this option to said function. Your documentation does not mentions to create such a directory which would not work in app generated using mix new task. I would recommend to create it automatically using File.mkdir_p with combination to :code.priv_dir/1 call mentioned above.

Also why do you use AvatarexSet instead of Avatarex.Set? It’s like reserving 2 namespaces for just one package and therefore it’s not seen as a good practice.

david

david

Updated with all your suggestions.

Eiji

Eiji

Already better, but you have still a lot to learn. I reserved some time, deeply investigated your code and created an example pull request with project rewrite proposal to show what code you would be able to write in future. :rocket:

https://github.com/davidkuhta/avatarex/pull/1

If you do not understand something feel free to ask questions in this thread. :dark_sunglasses:

Have a nice day! :smiling_imp:

Where Next?

Popular in Announcing Top

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
bryanjos
Hi, I just published version 0.23.0 of Elixirscript. https://github.com/bryanjos/elixirscript/blob/master/CHANGELOG.md Most of the chan...
New
mtrudel
Bandit is an HTTP server for Plug and WebSock apps. Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
mikehostetler
I’m excited to announce Jido, a framework providing foundational primitives for building autonomous agent systems in Elixir. While develo...
New
kip
ex_cldr provides localisation and internationalisation support based upon the data from the Unicode CLDR project. Unicode released CLDR ...
407 13056 120
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement