Page 1 of 1

Simple Put Alpha Text Image over Background Image

Posted: 2013-08-14T14:21:06-07:00
by edam
Hello,

I am generating an image from input text:

convert -channel RGBA -density 196 -background none -fill blue -font Times -pointsize 10 -size 400x400 -gravity North -bordercolor none -border 3 caption:'message' temp.png

This creates an image for me with the string message, of size 400x400, and transparent background. I don't care about the size of this temp image, it will contain a string of between 100 and 200 characters each time. I just want it to be text on transparent background for pasting onto another image.

This text must be placed over a background image, centered at the top but not all the way at the top, and with margins. The text itself I would like to be justified. The background image is 400x400 and must remain this size.

composite -tile background.png temp.png -compose DstOver result.png.

This is working, however the text image is just placed at the very top, per the Gravity North directive. I would like to be able to place the text more specifically on the background image, with margins/paddig.

I've tried all sorts of additional options to both the convert and composite commands (-geometry 400x400+10+10 or -geometry 400x400+40+40 or -region 400x400+40+40, using 300x300 instead of 400 for size/region/geometry, and placing the options after convert, after composite, after composite but before -compose.. using positive and negative offsets, etc.

Bottom line I don't know enough about these commands and am just looking for a one-off solution that works for my simple problem.

I would really appreciate if this is easy/simple for anyone to point out how to accomplish the placement, or better yet provide the convert and composite commands required.

Thanks!

Re: Simple Put Alpha Text Image over Background Image

Posted: 2013-08-14T14:55:09-07:00
by fmw42
convert -channel RGBA -density 196 -background none -fill blue -font Times -pointsize 10 -size 400x400 -gravity North -bordercolor none -border 3 caption:'message' temp.png
This is not well formed for IM 6, though may still work. It probably should be something more like


convert -size 400x400 -background none -fill blue -font Times -pointsize 10 -gravity North caption:'message' -bordercolor none -border 3 -density 196 temp.png


-channel RGBA is not really necessary though does not hurt. But the border and density should be done after creating the caption:

I am not sure why you need the 3 pixel border, unless your pointsize is so large that it makes the text bigger than 400x400.


composite -tile background.png temp.png -compose DstOver result.png.

This is working, however the text image is just placed at the very top, per the Gravity North directive. I would like to be able to place the text more specifically on the background image, with margins/paddig.
You will likely need to use convert rather than composite to get the -geometry and -gravity settings to work. And also to use -tile you need to specify the size.


convert \( -size 400x400 tile:background.png \) temp.png -gravity ... -geometry ... -compose over -composite result.png

In fact, you can do both steps at once using parenthesis processing:

Code: Select all

convert \( -size 400x400 tile:background.png \) \
\( -size 400x400 -background none -fill blue -font Times -pointsize 10 -gravity North caption:'message' \
    -bordercolor none -border 3 -density 196 \) \
-gravity ... -geometry ... -compose over -composite result.png

see
http://www.imagemagick.org/Usage/canvas/#tile
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/basics/#parenthesis

If we had links to your images, it would be easier to get the syntax just right and to understand about your temp.png image creation.

Re: Simple Put Alpha Text Image over Background Image

Posted: 2013-08-14T18:49:56-07:00
by edam
wow, this is exactly what I was looking for. great stuff, thanks!! I'm going to try it out, thx for the links as well

Re: Simple Put Alpha Text Image over Background Image

Posted: 2013-08-14T19:31:33-07:00
by fmw42
I forgot to mention that if you try to offset the overlay image and it is the same size as the tiled background image, it likely will get cutoff by using -composite. You should use -trim +repage on the image of text so that it its size is just around the text. Then you can overlay it with offsets via -gravity and -geometry.