Search code examples
rubyimageimagemagickimagemagick-convertminimagick

How to create image with ImageMagick?


I need to dynamically create an image, and I'm trying to find a good 'starting place' using magick or convert from command line (the actual library I will convert the CLI command to is MiniMagick for ruby)

To be honest, it's a little bit overwhelming... I'm not asking someone to write the whole thing for me, just get me a good 'starting' place that I can then work on adding text "layers" to.

Here is what the final output image needs to look like, and the required things I'm looking for:

  1. A background image (the gray circle) that I can position using x,y coordinates. The input file is circle.png. I'd also like to be able to enlarge/reduce the dimensions of the circle to be the exact size i want.
  2. Red small, centered text.
  3. Bold, larger, centered black text. For this text it needs to intelligently go on new lines when the line is too long (and have padding against the outside of the image so it doesn't touch the edge)
  4. Blue, underlined, medium text thats centered.
  5. A red border that overlays the background image

enter image description here

circle.png for reference

enter image description here


Solution

  • This will get you a start using ImageMagick to create your image. Unix syntax. ImageMagick does not have an underline feature. So you need to select an underline font for that section. (However, there are slightly more complex ways to achieve that using label: and then splicing in the underline)

    convert -size 299x249 xc:white \( circle.png -resize 200x200 \) \
    -gravity northwest -geometry +100+70 -compose over -composite \
    -bordercolor red -border 1 \
    -font arial -fill red -pointsize 18 -gravity north -annotate +0+20 "**Info**" \
    -font arial -fill blue -pointsize 28 -gravity south -annotate +0+50 "click here" \
    \( -size 279x -background none -fill black \
    -font arial -pointsize 28 -gravity center \
    caption:"Welcome John to your profile, have a look around" -trim +repage \) \
    -gravity center -geometry +0-20 -compose over -composite \
    result.png
    

    NOTE: updated slightly

    enter image description here