import -annotate question

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
ktenney

import -annotate question

Post by ktenney »

Howdy,

I want to put text on a screen grab, the doc seems to say that
$ import -annotate 10,10 "pasted text" anno.png

should put text onto anno.png

I haven't been able to get it to work.
What am I missing?

Thanks,
Kent
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: import -annotate question

Post by Bonzo »

Should -annotate 10,10 be -annotate +10+10
ktenney

Re: import -annotate question

Post by ktenney »

Bonzo wrote:Should -annotate 10,10 be -annotate +10+10
That doesn't work either.

I've searched a fair amount and not found any example of using
'import' with '-annotate'
ktenney

Re: import -annotate question

Post by ktenney »

ktenney wrote:
Bonzo wrote:Should -annotate 10,10 be -annotate +10+10
That doesn't work either.

I've searched a fair amount and not found any example of using
'import' with '-annotate'

It seems that the coordinates passed to -annotate are of the
screen itself, so If I grab an image of the top left part of the
screen I can see the annotation text.

Any idea whether coordinates could be relative to the image
grabbed by 'import' ?

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

Re: import -annotate question

Post by fmw42 »

I don't see any import function in IM?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: import -annotate question

Post by anthony »

Its a command simular to reading from image format x:

Try this
convert x: -annotate +10+10 "pasted text" anno.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ktenney

Re: import -annotate question

Post by ktenney »

anthony wrote:Its a command simular to reading from image format x:

Try this
convert x: -annotate +10+10 "pasted text" anno.png
Did that work for you?

I'm getting the same thing, the pasted text only appears if I'm
grabbing the top left corner of the screen.

I'll next try chaining operations, grabbing first, then annotating.
Does that sound right?

Thanks,
Kent
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: import -annotate question

Post by anthony »

The annotation appear in the grabbed window image for BOTH "import" and the "convert x:" versions for me. No problem.

By default using either method arranged for the mouse to select the window to grab.

For a specific window titled "mage" (a black xterm so I changed the text color)

Code: Select all

convert x:mage -fill white -annotate +10+10 "pasted text" anno.png
the text also appeared, without any problems.

NOTE: -fill is NOT available in "import"
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ktenney

Re: import -annotate question

Post by ktenney »

anthony wrote:The annotation appear in the grabbed window image for BOTH "import" and the "convert x:" versions for me. No problem.

By default using either method arranged for the mouse to select the window to grab.

For a specific window titled "mage" (a black xterm so I changed the text color)

Code: Select all

convert x:mage -fill white -annotate +10+10 "pasted text" anno.png
the text also appeared, without any problems.

NOTE: -fill is NOT available in "import"
Ah, I am not grabbing a window, but doing click and drag to select
an area of the screen.
Does it require 2 steps to annotate a screen grab if using a selection
instead of the entire window?

Thanks,
Kent
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: import -annotate question

Post by anthony »

Okay then. a dragged selection....

Hmmmm

Code: Select all

convert x:  info:
x: X 275x230 1600x1200+383+227 16-bit DirectClass
Okay a image read from a dragged selection returns an image with a virtual canvas and offset relative to the whole screen. But as -annotate draws things relative to the virtual canvas, it will end up drawing somewhere OFF the image selected.

Solution 1: If you use -draw instead of -annotate, then it will draw things relative to the actual image. This will also preserve the virtual information of the 'grab'.

Code: Select all

convert x: -fill black -draw 'text 10,10 "pasted text"' anno.png
Solution 2: Junk the virtual canvas size and offset before using -annotate.

Code: Select all

convert x: +repage -fill black -annotate +10+10 "pasted text" anno.png
You can also output the grab information if you want by saving to a separate file...

Code: Select all

convert x: -format '%wx%h%O' -identify +repage -fill black -annotate +10+10 "pasted text" anno.png >anno_offset.txt
Adding this info to IM Examples under "import"
http://imagemagick.org/Usage/basics/#import
and the special "x:" file format
http://imagemagick.org/Usage/files/#x
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ktenney

Re: import -annotate question

Post by ktenney »

The first one still writes to screen coordinates for me,
the other 2 are exactly what I hoped for, great stuff!

Thanks,
Kent
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: import -annotate question

Post by anthony »

You are right. However my understanding was that -draw ignored the virtual canvas (real image coordinates), while -annotate didn't (virtual image coordinates).

For example this does the right thing...

Code: Select all

convert x: -fill black -draw 'circle 35,35 20,30' circle_grab.png
As such we have an inconsistency been these two draw MVG primitives.
this probably should be reported as a bug.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply