phoenix framework - Generating initials avatar with Elixir -


i working on elixir , looking make avatar service. if user doesn't have avatar, want make 1 initials on it, so:

enter image description here

i haven't slightest idea start or how this.

you can use imagemagick this. call convert command via system.cmd , pass options it. here's simple example how generate image similar 1 posted. i'll leave fine-tuning you.

def generate(outfile, initials)   size = 512   resolution = 72   sampling_factor = 3   system.cmd "convert", [     "-density", "#{resolution * sampling_factor}",                # sample     "-size", "#{size*sampling_factor}x#{size*sampling_factor}",   # corrected size     "canvas:#e0e0e0",                                             # background color     "-fill", "#6d6d6d",                                           # text color     "-font", "/library/fonts/roboto-bold.ttf",                    # font location     "-pointsize", "300",                                          # font size     "-gravity", "center",                                         # center text     "-annotate", "+0+#{25 * sampling_factor}", initials,          # render text, move down bit     "-resample", "#{resolution}",                                 # sample down reduce aliasing     outfile   ] end 

for example this

generate('out.png', 'jd') 

will generate following image:

enter image description here


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -