Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Magick - Converting text to image - is there a way to center the text to the middle of the image?

Tags:

imagemagick

I have a simple text file that reads something like "It is 28 degrees today" I am trying to use imagemagick to center it to the middle of the image. The command i am using is this right now

    `convert -background lightblue -fill blue  -size 165x70 filename.txt image.png`

I tried using gravity but it always put the text outside of the image for some reason. I am not using it correctly from what I can see. I would like it to be centered. Any suggestions?

like image 668
moorecats Avatar asked Sep 29 '10 22:09

moorecats


2 Answers

convert \
    -size 165x70 \
    xc:lightblue \
    -font Bookman-DemiItalic \
    -pointsize 12 \
    -fill blue \
    -gravity center \
    -draw "text 0,0 'It is 28 degrees today'" \
    image.png

If you want to pull the input from an existing file, just feed that to the draw command:

convert \
    -size 165x70 \
    xc:lightblue \
    -font Bookman-DemiItalic \
    -pointsize 12 \
    -fill blue \
    -gravity center \
    -draw "text 0,0 '$(cat file.txt)'" \
    image.png
like image 175
Alex Howansky Avatar answered Nov 02 '22 06:11

Alex Howansky


Look At this

convert temp.jpg -gravity Center  -pointsize 30 -annotate 0 'Love you      
mom' temp1.jpg 

'i love u mom' text word gravity positioning center place of the text

like image 22
Mari Selvan Avatar answered Nov 02 '22 07:11

Mari Selvan