IJ Macros - Inconsistent text writing behaviour

Hi all,

I just discovered that there is an inconsistency in the 3 different ways of drawing text onto an image - at least with 1.52i (I’m on fiji, using 1.52i)

Overlay.drawString and drawString both consider the x,y coordinates to be in the lower left corner. However makeText considers x,y to be in the top left corner.

Is this by design? In the macro function reference I couldn’t find anything indicating which location the x,y coordinates are meant to be.

You can see this behaviour with the following:

x = 50
y = 300

makePoint(x,y); Overlay.addSelection(“blue”)
Overlay.drawString(“here”, x,y)

y += 20
makePoint(x,y); Overlay.addSelection(“blue”)
drawString(“here”, x,y)

y += 20
makePoint(x,y); Overlay.addSelection(“blue”)
makeText(“here”, x,y)

The drawString() and Overlay.drawString() macro functions are designed to be consistent with Java’s Graphics.drawString() method. The makeText() function is designed to be consistent with the makeRectangle() function.

I updated the master copy of the documentation at
to make it clearer where the text is drawn.

Here is an updated version of the example that has each function draw two lines:

newImage("Untitled", "8-bit black", 350, 350, 1);
x = 50
y = 50
setFont("Sanserif", 32);

makePoint(x, y, "white large cross add");
Overlay.drawString("first line\nsecond line", x, y)

y += 100
makePoint(x, y, "white large cross add");
drawString("first line\nsecond line", x, y)

y += 70
makePoint(x,y, "white large cross add");
makeText("first line\nsecond line", x, y)
run("Select None");


1 Like

Awesome - gotcha

Thanks Wayne!

Hey Wayne,

I did a bit more digging into this today, because I was still seeing some strange behaviour.

I tested your script above running on both mac and linux (1.52j) and got the same behaviour:
When you run your script from within Fiji (Run->macro menu if you save it as a macro file) you see the behaviour above. (makeText is the only call that draws below the point - as in your picture).

However if you run the same macro from the command line via … -macro then both overlay calls draw below the point - ie Overlay.drawString and makeText behave the same way.

So the behaviour of Overlay.drawString is seemingly different depending on whether its run as a macro invoked on the command line, or if it’s run interactively within the app.

I tested this on Linux and Mac and got the same behaviour. I also tested running the script from the command line with -macro both with and without --headless and got the same behaviour.

Below is the output of the same script, one interactively called, one from the cmd line:

interactive cmd-line