Search code examples
imagebitmapimagemagickgraphic

How to programmatically generate square images with users' initials?


I want to create images for users, similar to what google does on gmail for android, as shown in this screenshot: http://blog.brightwavemarketing.com/wp-content/uploads/2013/06/gmail_for_android_4.5.png

I took a look at using ImageMagick (http://www.imagemagick.org/Usage/draw/) from the command line but I'm hoping there are simpler options out there I could use instead.

What I need to do:
- specify image size
- specify background color
- specify a pair of letters for the foreground, choose their color, and make them 80% of the width of the square
- anti-alias the text


Solution

  • You can start from this command:

    convert -size 100x100 xc:#A02B2B -pointsize 70 -fill White -gravity center -draw "text 0,0 'AZ'" output.jpg
    

    It genarates a square of specified size(-size 100x100) and color (xc:#A02B2B) filling it with letters ('AZ') of specified color (-fill White).

    This is command's output:

    enter image description here