Place (linked) with original with and height

When placing image files (jpg and raw) into a document using batch play, I want them to retain their original width and height in pixels and start at the top left of the canvas. Unfortunately, I did not find a documentation for the parameters of the batch play command, and have a number of questions:

  1. When I place raw files, the batch play command automatically uses the resolution set in Camera Raw Preferences / Image Sizing / Resolution. However, I would like to use the resolution of the document. Is there a way to include this request in the script?
  1. When recording the placement with Alchemist, the Set horizontal/vertical scale setting leads to the introduction of the the width and height parameters below. However the percentage value is not 100%, but an upscale from the image scaled to fit the canvas. Setting unit to pixelsUnit does not work for me either, it seems to still interpret the value as a percentage. Is there a way to avoid this scaling to canvas in the first place or an easy way to set the width and height parameters without additional calculations?

  2. Changing the Set horizontal/vertical position of the reference point to 0 results in a similarly “precalculated” value that shifts the center to upper left corner. Only after the placement, changing the Transform settings of the Linked Smart Object to 0px does the trick. However, the batch play move operation defines the position not in canvas coordinates but as an offset to the current position of the layer image. Again, is there a way to directly set the origin of the layer image to the top left corner of the canvas? If not, is there a a way to provide a canvas position instead of an offset to the batch play move command?

  1. Is there a documentation for the batch play commands somewhere?
const result = await batchPlay(
    [
        {
            _obj: "placeEvent",
            ID: 5,
            null: {
                _path: token,
                _kind: "local"
            },
            linked: true,
            openAs: {},
            freeTransformCenterState: {
                _enum: "quadCenterState",
                _value: "QCSAverage"
            },
            offset: {
                _obj: "offset",
                horizontal: {
                    _unit: "pixelsUnit",
                    _value: [some value]
                },
                vertical: {
                    _unit: "pixelsUnit",
                    _value: [some value]
                }
            },
            width: {
                _unit: "percentUnit",
                _value: [usually some value != 100]
             },
             height: {
                _unit: "percentUnit",
                _value: [usually some value != 100]
             },
            _options: {
                dialogOptions: "dontDisplay"
            }
        }
    ], {}
);

In general, Photoshop does only do scaling of places images when the placed image is larger than the available space. This can be turned off in the settings:


However, there’s another edge case where Photoshop does some scaling: When the resolution (ppi) of the document and the placed image doesn’t match. I don’t know if there’s a way to avoid that, otherwise you could adjust the image resolution before placing (given, that you know the resolution of the placed image).

Move (or transform in general) always works as a change on top of the current state. So it isn’t really possible to directly specify an absolute position or final coordinates. I also think it isn’t the greatest design decision, but to be honest the math to get the desired result isn’t the hardest one either. Even the UI inputs where you can set an absolute position will result in a relative move, if you record the respective BatchPlay code. Just subtract the current position from the target position and you get the necessary movement vector.

There are however two ways to (kind of) set the position directly:

  1. Use the alignment buttons
  2. For shape layers, I think it’s possible to adjust the rectangle that defines the shapes position and size directly.

Nope. Just record with Alchemist, do it again while changing tool settings etc. and evaluate the changes. Most descriptors keys are also self-explanatory.

1 Like

So, I’ve decided to go with a very generic solution by placing a linked file regardless of ppi and resize option and then translating and scaling it into place as follows:

  layer = ps.app.activeDocument.activeLayers[ 0 ]; 
  await layer.translate( -layer.bounds.left, -layer.bounds.top );
  await layer.scale( 100 * width / layer.bounds.right, 100 * height / layer.bounds.bottom, consts.AnchorPosition.TOPLEFT );

I guess the scale factor will be the same for width and height anyway, but the question is: Is there a way of getting the actual input width and height of the placed file? Given the following quote, I guess it might not be possible for the general case. So the followup question would be: Is there way to get the input dimensions for the specific case of a psd-file?