Skip to main content
Stephen Marsh
Community Expert
Community Expert
August 23, 2023
Question

Scripts to Place Embedded & Place Linked at 1:1 Scale (Ignoring PPI)

  • August 23, 2023
  • 2 replies
  • 1833 views

When placing a 600 PPI resolution document into a 300 PPI document, the Smart Object layer is initially sized at 50%. Both Place Embedded and Place Linked behave this way, it is by design.

 

Users sometimes want to place images at their original pixel size, regardless of mismatching PPI values.

 

A recent post on the forum has reminded me that I created the following scripts over a year ago, however, I don't believe that I ever posted them. 

 

The scripts have not been exhaustively tested, so please let me know if there are any issues. Code below!

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
May 12, 2024

Yet another option is automation via the Script Events Manager:

 

https://prepression.blogspot.com/2021/10/photoshop-script-events-manager.html

 

Setup a new event that listens for the  placeEvent  (embedded or linked) operation:

 

 

Then create an an action to reset transformations after placing a smart object (found in the Properties panel):

 

 

Alternatively, a .jsx ExtendScript version of the same command:

 

#target photoshop
executeAction( stringIDToTypeID( "placedLayerResetTransforms" ), undefined, DialogModes.NO );

 

The placed image will be automatically reset to its original pixel values directly after placing it.

Stephen Marsh
Community Expert
Community Expert
August 23, 2023

Place Embedded Retaining Pixel Size:

 

/*
Place Embedded Retaining Pixel Size.jsx
v1.0 - 13th June 2022, Stephen Marsh
v1.1 - 5th April 2024: Added a conditional version check
v1.2 - 5th April 2024: Added a conditional layer bounds vs. canvas check
*/

#target photoshop

function main() {

    // Ensure that version 2021 or later is being used
    var versionNumber = app.version.split(".");
    var versionCheck = parseInt(versionNumber);

    // Fail
    if (versionCheck <= 21) {
        alert("This script is for Photoshop 2021 or later...");

    // Pass
    } else {

        var savedRuler = app.preferences.rulerUnits;
        app.preferences.rulerUnits = Units.PIXELS;

        // Conditionally activate "Skip Transform When Placing" General Preference
        var ref = new ActionReference();
        ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        var applicationDesc = executeActionGet(ref);
        var skipTransformPref = applicationDesc.getObjectValue(stringIDToTypeID("generalPreferences")).getBoolean(stringIDToTypeID("skipTransformSOFromLibrary"));
        if (skipTransformPref === false) {
            skipTransform(true);
        }

        // Conditionally deactivate "Resize During Place" General Preference
        var aref = new ActionReference();
        aref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        var appDesc = executeActionGet(aref);
        var resizePlacePref = appDesc.getObjectValue(stringIDToTypeID("generalPreferences")).getBoolean(stringIDToTypeID("resizePastePlace"));
        if (resizePlacePref === true) {
            resizeDuringPlace(false);
        }

        // Call the place embedded dialog
        placeEmbedded();

        // Set the active layer
        var theSO = app.activeDocument.activeLayer;

        // Reset the SO transform
        var idplacedLayerResetTransforms = stringIDToTypeID("placedLayerResetTransforms");
        executeAction(idplacedLayerResetTransforms, undefined, DialogModes.NO);

        // Get the layer bounds
        var layWidth = app.activeDocument.activeLayer.bounds[2].value - app.activeDocument.activeLayer.bounds[0].value;
        var layHeight = app.activeDocument.activeLayer.bounds[3].value - app.activeDocument.activeLayer.bounds[1].value;

        // Optionally handle oversized content
        if (layWidth > app.activeDocument.width.value || layHeight > app.activeDocument.height.value) {
            if (confirm("Convert Background to layer & reveal all content?", true)) {
                // Select the Background layer if it exists (silently fails if there is no such layer)
                try {
                    app.activeDocument.activeLayer = app.activeDocument.backgroundLayer;
                } catch (error) { }
                // Convert the Background layer to a normal layer
                if (app.activeDocument.activeLayer.isBackgroundLayer) {
                    app.activeDocument.activeLayer.isBackgroundLayer = false;
                    app.activeDocument.activeLayer.name = "Background";
                }
                app.activeDocument.revealAll();
                app.activeDocument.activeLayer = theSO;
            }
        }

        // Reset General Preferences back to their original state
        skipTransform(skipTransformPref);
        resizeDuringPlace(resizePlacePref);

        app.preferences.rulerUnits = savedRuler;
    }
}

app.activeDocument.suspendHistory("Place Embedded Retaining Pixel Size.jsx", "main()");


// Functions

function placeEmbedded() {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("menuItemClass"), s2t("menuItemType"), s2t("placeEnum"));
    descriptor.putReference(s2t("null"), reference);
    executeAction(s2t("select"), descriptor, DialogModes.ALL);
}

/*
Preference functions based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-change-photoshop-preferences-by-script-resize-image-during-place/m-p/12544913
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-you-also-read-a-photoshop-preference-like-quot-resize-image-during-place-quot/m-p/12752645
*/

function skipTransform(setBoolean) {
    sTT = stringIDToTypeID;
    (ref = new ActionReference()).putProperty(
        sTT("property"),
        (gP = sTT("generalPreferences"))
    );
    ref.putClass(sTT("application"));
    (dsc1 = new ActionDescriptor()).putReference(sTT("null"), ref);
    (dsc2 = new ActionDescriptor()).putBoolean(sTT("skipTransformSOFromLibrary"), setBoolean);
    dsc1.putObject(sTT("to"), gP, dsc2), executeAction(sTT("set"), dsc1);
}

function resizeDuringPlace(setBoolean) {
    sIDtID = stringIDToTypeID;
    (aref = new ActionReference()).putProperty(
        sIDtID("property"),
        (genPref = sIDtID("generalPreferences"))
    );
    aref.putClass(sIDtID("application"));
    (adsc1 = new ActionDescriptor()).putReference(sIDtID("null"), aref);
    (adsc2 = new ActionDescriptor()).putBoolean(sIDtID("resizePastePlace"), setBoolean);
    adsc1.putObject(sIDtID("to"), genPref, adsc2), executeAction(sIDtID("set"), adsc1);
}

 

 

Place Linked Retaining Pixel Size:

 

/*
Place Linked Retaining Pixel Size.jsx
v1.0 - 13th June 2022, Stephen Marsh
v1.1 - 5th April 2024: Added a version check
v1.2 - 5th April 2024: Added a conditional layer bounds vs. canvas check
*/

#target photoshop

function main() {

    // Ensure that version 2021 or later is being used
    var versionNumber = app.version.split(".");
    var versionCheck = parseInt(versionNumber);

    // Fail
    if (versionCheck <= 21) {
        alert("This script is for Photoshop 2021 or later...");

        // Pass
    } else {

        var savedRuler = app.preferences.rulerUnits;
        app.preferences.rulerUnits = Units.PIXELS;

        // Conditionally activate "Skip Transform When Placing" General Preference
        var ref = new ActionReference();
        ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        var applicationDesc = executeActionGet(ref);
        var skipTransformPref = applicationDesc.getObjectValue(stringIDToTypeID("generalPreferences")).getBoolean(stringIDToTypeID("skipTransformSOFromLibrary"));
        if (skipTransformPref === false) {
            skipTransform(true);
        }

        // Conditionally deactivate "Resize During Place" General Preference
        var aref = new ActionReference();
        aref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        var appDesc = executeActionGet(aref);
        var resizePlacePref = appDesc.getObjectValue(stringIDToTypeID("generalPreferences")).getBoolean(stringIDToTypeID("resizePastePlace"));
        if (resizePlacePref === true) {
            resizeDuringPlace(false);
        }

        // Call the place linked dialog
        placeLinked();

        // Set the active layer
        var theSO = app.activeDocument.activeLayer;

        // Reset the SO transform
        var idplacedLayerResetTransforms = stringIDToTypeID("placedLayerResetTransforms");
        executeAction(idplacedLayerResetTransforms, undefined, DialogModes.NO);

        // Get the layer bounds
        var layWidth = app.activeDocument.activeLayer.bounds[2].value - app.activeDocument.activeLayer.bounds[0].value;
        var layHeight = app.activeDocument.activeLayer.bounds[3].value - app.activeDocument.activeLayer.bounds[1].value;

        // Optionally handle oversized content
        if (layWidth > app.activeDocument.width.value || layHeight > app.activeDocument.height.value) {
            if (confirm("Convert Background to layer & reveal all content?", true)) {
                // Select the Background layer if it exists (silently fails if there is no such layer)
                try {
                    app.activeDocument.activeLayer = app.activeDocument.backgroundLayer;
                } catch (error) { }
                // Convert the Background layer to a normal layer
                if (app.activeDocument.activeLayer.isBackgroundLayer) {
                    app.activeDocument.activeLayer.isBackgroundLayer = false;
                    app.activeDocument.activeLayer.name = "Background";
                }
                app.activeDocument.revealAll();
                app.activeDocument.activeLayer = theSO;
            }
        }

        // Reset General Preferences back to their original state
        skipTransform(skipTransformPref);
        resizeDuringPlace(resizePlacePref);

        app.preferences.rulerUnits = savedRuler;
    }
}

app.activeDocument.suspendHistory("Place Linked Retaining Pixel Size.jsx", "main()");


// Functions

function placeLinked() {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    descriptor.putBoolean(s2t("linked"), true);
    executeAction(s2t("placeEvent"), descriptor, DialogModes.ALL);
}

/*
Preference functions based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-change-photoshop-preferences-by-script-resize-image-during-place/m-p/12544913
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-you-also-read-a-photoshop-preference-like-quot-resize-image-during-place-quot/m-p/12752645
*/

function skipTransform(setBoolean) {
    sTT = stringIDToTypeID;
    (ref = new ActionReference()).putProperty(
        sTT("property"),
        (gP = sTT("generalPreferences"))
    );
    ref.putClass(sTT("application"));
    (dsc1 = new ActionDescriptor()).putReference(sTT("null"), ref);
    (dsc2 = new ActionDescriptor()).putBoolean(sTT("skipTransformSOFromLibrary"), setBoolean);
    dsc1.putObject(sTT("to"), gP, dsc2), executeAction(sTT("set"), dsc1);
}

function resizeDuringPlace(setBoolean) {
    sIDtID = stringIDToTypeID;
    (aref = new ActionReference()).putProperty(
        sIDtID("property"),
        (genPref = sIDtID("generalPreferences"))
    );
    aref.putClass(sIDtID("application"));
    (adsc1 = new ActionDescriptor()).putReference(sIDtID("null"), aref);
    (adsc2 = new ActionDescriptor()).putBoolean(sIDtID("resizePastePlace"), setBoolean);
    adsc1.putObject(sIDtID("to"), genPref, adsc2), executeAction(sIDtID("set"), adsc1);
}

 

Info on downloading and installing/running scripts:

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html?m=1

NicNamSam
Participating Frequently
April 5, 2024

Unfortunately, this no longer works. It throws an error.

 

Stephen Marsh
Community Expert
Community Expert
April 6, 2024

It's awesome that you put the work in to address this issue. However, I have photoshop 2024, version 25.6.0 and it is giving me the error that I showed. Although weirdly it now seems to be correctly inserting the image at the original size, even though it throws the error. But I haven't tested it thoroughly with other documents.


@NicNamSam 

 

Thank you for the feedback.

 

Are you referring to the two original place embedded and place linked scripts?

 

Or are you referring to the new 2020 specific place embedded version?