4

In the drawing below I have e.g., a rectangle.

screenshot showing coordinates in GUI and XML

In the GUI, Inkscape says the rectangle is at Y position 0, but in the XML for that element it says 873. Why is that and how do I get the "real" number?

Background: When exporting the image (scripted), I want to add 10 pixels border on all four sides. I thought I could just look for the largest / smallest coordinates in XML and add the 10 pixels for border, but I end up exporting an all white background instead of the image. Working with the XML comes natural here because I get other (meta) information from that.

I can query the image origin with inkscape -X and inkscape -Y and the image dimensions with inkscape -H and inkscape -W. That also gets me the numbers from the GUI. Exporting with these values works. However, that requires forking a new Inkscape process 4 times per image, and hence slows the whole export down. (Lots of images on old hardware.)

This is Inkscape 0.91 on Linux, in case that matters.

8

Usually SVG units are expressed in pixel, and if Inkscape coordinates are set to pixel, they should coincide (see also here and here).

In your example the difference in width (236.185 vs 234.869) and height (180.000 vs 178.6805) is due to the border width of the rectangle, which is included in Inkscape W and H and not included in SVG width and height.

For example, with a border stroke of 1 px:

rectangle with a border

The same rectangle without a border:

rectangle without a border

Note that the border is centered on the path. In my example we have:

Inkscape W = SVG width (199px) + half stroke left (0.5px) + half stroke right (0.5px) = 200 px

the stroke is centered on the path

Be aware that the Y coordinate in Inkscape has the zero on the bottom of the document, while in SVG the zero is on the top of the document.

Y = 0 in Inkscape means an object at the bottom of the document:

Y=0 in Inkscape

Y = 0 in SVG means an object at the top of the document:

Y=o in SVG

This means that your "real" number is something like:

Y coordinate in SVG (px) = Page height (px) - Y coordinate in Inkscape (px) - Object and borders height (px)

(Note that the inversion of the Y axis will be fixed at some time in the future according to this issue.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.