Skip to main content
Participant
March 18, 2024
Answered

Embedding image using a script - wrong size

  • March 18, 2024
  • 1 reply
  • 237 views

Hi,

 

Using the following script I try to embed an image from one file to an image from another file. The files are at the same resolution (px and dpi). When embedded manually, it inserts correctly, filling the whole picture. But when embedded via scrip, it is resize to something around 10% of the original dimensions.

 

How can I fix it?

 

placeEmbeded(filePath);


function placeEmbeded(filePath) {

    var actDesc = new ActionDescriptor();

    actDesc.putPath(charIDToTypeID('null'), filePath);

    actDesc.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa'));

    executeAction(charIDToTypeID('Plc '), actDesc, DialogModes.NO);

 

This topic has been closed for replies.
Correct answer Stephen Marsh

Your code doesn't work for me (even when adding the missing closing brace).

 

This works for me:

 

placeFile(new File("~/Desktop/place.psd"), false, 0, 0);

function placeFile(thePath, linked, xPosition, yPosition) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var AD = new ActionDescriptor();
    AD.putInteger(s2t("ID"), 1);
    AD.putPath(s2t("null"), thePath); // file path
    AD.putBoolean(s2t("linked"), linked); // false for embedded
    AD.putEnumerated(s2t("freeTransformCenterState"), s2t("quadCenterState"), s2t("QCSAverage")); // transform
    AD.putUnitDouble(s2t("horizontal"), s2t("pixelsUnit"), xPosition); // x coordinate position
    AD.putUnitDouble(s2t("vertical"), s2t("pixelsUnit"), yPosition); // y coordinate position
    executeAction(s2t("placeEvent"), AD, DialogModes.NO);
}

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
March 18, 2024

Your code doesn't work for me (even when adding the missing closing brace).

 

This works for me:

 

placeFile(new File("~/Desktop/place.psd"), false, 0, 0);

function placeFile(thePath, linked, xPosition, yPosition) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var AD = new ActionDescriptor();
    AD.putInteger(s2t("ID"), 1);
    AD.putPath(s2t("null"), thePath); // file path
    AD.putBoolean(s2t("linked"), linked); // false for embedded
    AD.putEnumerated(s2t("freeTransformCenterState"), s2t("quadCenterState"), s2t("QCSAverage")); // transform
    AD.putUnitDouble(s2t("horizontal"), s2t("pixelsUnit"), xPosition); // x coordinate position
    AD.putUnitDouble(s2t("vertical"), s2t("pixelsUnit"), yPosition); // y coordinate position
    executeAction(s2t("placeEvent"), AD, DialogModes.NO);
}
Participant
March 19, 2024

Thank you! It worked 🙂