问题
I am working on Elixir and looking to make an avatar service. If the user doesn't have an avatar, want to make one with their initials on it, like so:

I really haven't the slightest idea where to start or how to do this.
回答1:
You can use ImageMagick to do this. Simply call the convert
command via System.cmd and pass the options to it. Here's a simple example how to generate an image similar to the one you posted. I'll leave the fine-tuning up to you.
def generate(outfile, initials) do
size = 512
resolution = 72
sampling_factor = 3
System.cmd "convert", [
"-density", "#{resolution * sampling_factor}", # sample up
"-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 a bit
"-resample", "#{resolution}", # sample down to reduce aliasing
outfile
]
end
For example this
generate('out.png', 'JD')
will generate the following image:

回答2:
Use Mogrify. It is a Elixir-ImageMagick integration.
来源:https://stackoverflow.com/questions/31395381/generating-initials-avatar-with-elixir