Skip to main content
dublove
Legend
Nov 1, 2026 5:10 PM UTC
Question

How is the width "W" value of the image on the control bar calculated?

After copying the same image and rotating it by 10 degrees, the "W" value on the control bar does not change, and the rotated W is not obtained using gb [3] - gb [1].
I found a script that should be correct in principle, but it will mention 'undified':

var d = app.activeDocument;
var item = app.selection[0];
//No rotation, obtain directly from the boundary
var gb = item.geometricBounds;
var width = gb[3] - gb[1];

// If the object has rotation, use transformValues to obtain the actual size
var tv = item.transformValuesOf(CoordinateSpaces.INNER_COORDINATES);
var w = tv.horizontalScale;
var h = tv.verticalScale;
alert(w);

 

    24 replies

    KohakuNekotarou
    Inspiring
    Nov 5, 2026 12:46 PM UTC
    // the W and H of the last selected object, the same values InDesign's
    // Control panel and Transform panel show.
    //
    // geometricBounds is the upright box around the object as it stands on the page, so it grows
    // when the object is rotated. W and H are the lengths of the object's own edges: this script
    // maps three corners of the object's own box onto the pasteboard with resolve() and measures
    // the two edges between them. Rotation does not change them; scaling and shearing do, as in
    // the panel. Nothing is rotated back to 0, and nothing in the document changes.
    // It follows "Dimensions Include Stroke Weight" in the Transform panel's menu.
    //
    // Use: select an object - with the Direct Selection tool, an image inside its frame - and run.
    // If several objects are selected, the one selected last is measured.
    // Made with Claude Code (Anthropic).
    #target indesign

    (function () {
    var sel = app.documents.length > 0 ? app.selection : [];
    var item = sel.length > 0 ? sel[sel.length - 1] : null;
    if (item === null || !item.hasOwnProperty("geometricBounds")) {
    alert("Select an object first (not text).");
    return;
    }

    // The object's own box, with or without the stroke, as the panel measures it.
    var limits = app.transformPreferences.dimensionsIncludeStrokeWeight
    ? BoundingBoxLimits.OUTER_STROKE_BOUNDS
    : BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS;

    // A corner of that box on the pasteboard, in points: [0, 0] top left, [1, 0] top right, [0, 1] bottom left.
    function corner(x, y) {
    return item.resolve([[x, y], limits, CoordinateSpaces.INNER_COORDINATES],
    CoordinateSpaces.PASTEBOARD_COORDINATES)[0];
    }
    function distance(p, q) {
    return Math.sqrt(Math.pow(q[0] - p[0], 2) + Math.pow(q[1] - p[1], 2));
    }
    var topLeft = corner(0, 0);
    var w = distance(topLeft, corner(1, 0)); // points
    var h = distance(topLeft, corner(0, 1));

    // In the ruler units, as the panel shows them (points for any unit not listed here).
    function inRulerUnits(points, unit) {
    var table = [
    [MeasurementUnits.MILLIMETERS, "mm", 72 / 25.4],
    [MeasurementUnits.CENTIMETERS, "cm", 72 / 2.54],
    [MeasurementUnits.INCHES, "in", 72],
    [MeasurementUnits.INCHES_DECIMAL, "in", 72],
    [MeasurementUnits.PICAS, "pc", 12],
    [MeasurementUnits.Q, "Q", 72 / 25.4 / 4],
    [MeasurementUnits.HA, "H", 72 / 25.4 / 4],
    [MeasurementUnits.PIXELS, "px", 1]
    ];
    for (var i = 0; i < table.length; i++) {
    if (unit == table[i][0]) {
    return Math.round(points / table[i][2] * 1000) / 1000 + " " + table[i][1];
    }
    }
    return Math.round(points * 1000) / 1000 + " pt";
    }
    var view = app.activeDocument.viewPreferences;
    alert(item.constructor.name
    + "\nW: " + inRulerUnits(w, view.horizontalMeasurementUnits)
    + "\nH: " + inRulerUnits(h, view.verticalMeasurementUnits));
    })();

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 2, 2026 2:00 PM UTC

    Hi ​@rob day 

    I actually really want to know the method of using InDesign software itself.
    It is definitely not using the method of copying a copy.


    I have sporadically reviewed some materials, and it seems that  need to calculate the resolution of the monitor?
    Convert using the relationship between dimensions, actual Ppi, effective Ppi, and horizontal scale.

    Translate
    rob day
    Community Expert
    Community Expert
    Nov 1, 2026 8:26 PM UTC

    In case you missed my explanation of the geometricBounds property in the other post:

    You are misinterpreting the geometricBounds property—it’s the geometric bounds of the selection including any rotation or other transforms. As you rotate a rectangle, its geometric bounds change, but its width and height remain the same. In this example the width of the geometric bounds is 3.2889, not the rectangle’s 3.00 width

     

    var sel = app.selection[0];
    var gb = sel.geometricBounds
    alert(gb)

     

     

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 2, 2026 2:42 AM UTC

    Hi ​@rob day 

    I know what you mean.


    What I have always wanted to know is how to obtain the width of a shape after rotation.
    How is the current value of "W" calculated.
    You see my screenshot, this is clearly not gb [3] - gb [0] (I don't need this value, it's unreliable), it should be related to horizontalScale.

     

    When a picture has no deformation or rotation, its W=gb [3] - gb [1]
    But how to calculate the value of W when the graph has a rotation angle?

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 1, 2026 6:02 PM UTC

    I searched online.
    But I don't know how to find it in indesignjs.de

    TransformationMatrix is a read-only object in the InDesign scripting API that describes object transformation matrices, including horizontal/vertical scaling, rotation, cutting, translation, and other components, as well as raw matrix values and unit triangle mappings. ‌‌

    📐  Core Attributes
    MatrixValues: Matrix values of type Array of 2 Arrays of 2 Reals, which is a 2x2 matrix that records the core transformation components of scaling, rotation, and shearing.

    HorizontalScaleFactor: Horizontal scaling factor, of type Number.

    VerticalScaleFactor: Vertical scaling factor, of type Number.

    CounterclockwiseRotationAngle: counterclockwise rotation angle, of type Number.

    ClockwiseShearAngle: Clockwise Shear Angle, of type Number.

    HorizontalTranslation: Horizontal translation distance, of type Number.

    VerticalTranslation: Vertical translation distance, of type Number.

    MatrixMapping: The mapping of a matrix to a unit triangle, which returns the Array of 2 Arrays of 2 Reals, which are the mapping coordinates of three vertices.

    Name: Matrix name, of type String. ‌‌

    Translate