Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
I think to do what you want you need to make the text area separate from the image and -append it.
This has a drawback as you need to find the width of the original image but I seem to remember seeing a trick to do it. I wonder if it had something to do with cloning the original image filling it with the colour and then cropping? A bit long winded but it could work?
convert -background '#800000' -fill '#FFAEB9' -font Arial -pointsize 18 -size 300x30 -gravity Center caption:'this is my text' output.jpg
as this seems to centre the text horizontally and vertically. As you pointed out I need to know the width of the original image which thankfully I do. The only part I don't know how to do is how to add the caption to the top of the original image?
Most of my code is written for php and I use getimagesize() and use the width variable in the convert code. You can get the image width using the fx option in Imagemagick but that is an extra step as well.
If you are running a script it is not really a problem but some people want everything on one line. I believe in version 7 you should be able to get the image width on the same line of code as the convert.
convert -background "#800000" -fill "#FFAEB9" -font Arial -pointsize 18 -size 300x30 -gravity Center caption:"this is my text" -write mpr:image +delete mpr:image -append input.jpg mpr:image -append output.jpg
Out of interest this variation of the auto width nearly works but I can not fill the caption area with a colour ( hopefully fmw42 or snibgo can make a suggestion on how to do that):
I should explain the first piece of code above:
The caption image is created and saved into the memory called image; that image is then called from the memory twice and use in the append option.
I realise that this can probably be done more efficiently but I've chosen to create a file for each of the captions and then stitch them back together using the -append & +append options. This gives me the flexibility to put the captions on any of the four edges as I could need to put them on the left or right of an image as well now. I wasn't aware that an image could be held in memory so it's been a good learning curve.