I am using ImageMagick from within an elixir-application. My code is:
Code: Select all
defp create_picture(outfile, initials) do
size = 480
resolution = 72
sampling_factor = 2
color = ...some color...
fontcolor = ...some color...
System.cmd "convert", [
"-density", "#{resolution * sampling_factor}", # sample up
"-size", "#{size*sampling_factor}x#{size*sampling_factor}", # corrected size
"-background", "#{color}", # background color
"-fill", "#{fontcolor}", # text color
"-font", "Open-Sans", # font type
"-gravity", "Center", # center text
"caption: #{initials}", # text
"-resample", "#{resolution}", # sample down to reduce aliasing
outfile
]
end
This is the actual code I am using. Tried already different approches with annotate, label, caption... -gravity center is making always the same mistake. The font is Open Sans, same result with Roboto.
And I don't want to use a fixed pointsize. Try "MR" with pointsize "72" and try it with "WW". You will see why I want to avoid the pointsize. The avatars are getting processed inside some applications and rendered as a circle. What I want is a simple picture with two letters and a padding. Pointsize auto and text centered. Seems not that difficult, but it seems to me ImageMagick can't do the job in a simple way, because gravity center cannot calculate the width of some letters correctly.
"\n MR \n":