Questions about annotations

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?".
Post Reply
Wimweb

Questions about annotations

Post by Wimweb »

Hello,

I've got 2 questions about annotations :
1) How can I give an annotation a image background?
2) How can I get place where my last annotation ended? (I need to need to put text with images through eachother on an image)

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Questions about annotations

Post by fmw42 »

For question 1) see -background using label or caption at http://www.imagemagick.org/Usage/text/
also see -undercolor for -draw or -annotate

For question 2) I don't think you can, once the image has been created, but you could use -debug annotate with -annotate to get Font Metrics. See same page above.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Questions about annotations

Post by anthony »

annotate draws on top of an existing image, backgroudn is that image.

label: and caption; creates and image and background can be set using -background before the image creation operator.

See http://www.imagemagick.org/Usage/text/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Wimweb

Re: Questions about annotations

Post by Wimweb »

Background is only for colors, I need an image.
EDIT : I got an idea. Can I solve this by making a seperate image with the textback and the text, and then put it on the main image? I'll try it this way.

Still, any suggestions for question 2?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Questions about annotations

Post by Bonzo »

Just write the text on the image:

Code: Select all

convert image.jpg -fill black -pointsize 20 -font verdana -gravity center -annotate +0+0 "Some text" output.jpg
As Fred says question 2 is not easy. If you are still using php you may be able to calculate it:
Draw the text onto an image - find the size of the text image with getimagesize() - get size of image you are going to put the text onto again with getimagesize()- take the width of the text image away from the position of the text image on the background image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Questions about annotations

Post by anthony »

For question 2 you need to find out how big the test is and how far the 'caret' moves.
This can be difficult without using an API.

See IM Examples, Determining Font Metrics
http://www.imagemagick.org/Usage/text/#font_info

Note label can get something like that info, but it is not exact, See the next section...
IM Examples, Creating Lines of Mixed Font Styles
http://www.imagemagick.org/Usage/text/#mixed_font_lines

You can generate a label or test on a transparent background -background none, and then overlay that text onto the image. This is actually very common as it give you far more control, and allows you to do other things to the text before it is overlaid onto the image.


Finally if you plan to do a LOT of this then IM may not be the right tool. The TeX and the higher level tools LaTeX and its GUI tool LyX, is designed to actually do text and font layouts, spacing, justifications, word wrapping, and pagation of characters, words, sentantaces paragraphs, etc etc etc. If you are serious about text handling in batch processing, than these are the tools to use.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Wimweb

Re: Questions about annotations

Post by Wimweb »

Wat you say there about seperate images with a -background none, is a very good idea. I can then get there width via php, and determine the x and y for the next image.

Problems solved. Thanks everyone!
Post Reply