Skip to main content
added 76 characters in body
Source Link

I'm having problems figuring out why my layer does not resize to match the dimensions of the source layer. I set signatureLayer equal to the layer named "signature" and pass it and the layer I want changed into the function changeSizeto. It looks like it's taking the dimensions of the background layer instead. I can't see where I messed up. This is just a small bit of the script I'm working on but essentially I will be reading in an image location from a txt file, resizing it according to the source layer "signature" dimensions, saving the psd out as an image, then read in another image location and repeat.

#target photoshop

// must have source psd open to start with.

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

// call the source document
var srcDoc = app.activeDocument;
var signatureLayer = srcDoc.layers.getByName("signature");  

//var sourceFile= new File("E:/Signatures/sig1.tif");
var sourceFile= new File("C:/Users/harry/OneDrive/Desktop/Replace/test.jpg");
var idPlc = charIDToTypeID( "Plc " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, sourceFile);
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
executeAction( idPlc, desc3, DialogModes.NO );

var replacementImage = srcDoc.layers[0]

changeSizeto(signatureLayer,replacementImage)

function changeSizeto(source,chngLayer){
    startRulerUnits = app.preferences.rulerUnits;
    //pref pixels
    app.preferences.rulerUnits = Units.PIXELS
    
    // Calculate length and width based on the rectangular bounds of the selected layer
    var sourceHeight = source.bounds[2].value-source.bounds[0].value; //Grab the length
    var sourceWidth = source.bounds[3].value-source.bounds[1].value; //Grab the width

    var newWidth=sourceWidth;
    var newHeight=sourceHeight;
    
    chngLayer.resize(newWidth,newHeight,AnchorPosition.MIDDLECENTER);

}

Edit:

test

I'm having problems figuring out why my layer does not resize to match the dimensions of the source layer. I set signatureLayer equal to the layer named "signature" and pass it and the layer I want changed into the function changeSizeto. It looks like it's taking the dimensions of the background layer instead. I can't see where I messed up. This is just a small bit of the script I'm working on but essentially I will be reading in an image location from a txt file, resizing it according to the source layer "signature" dimensions, saving the psd out as an image, then read in another image location and repeat.

#target photoshop

// must have source psd open to start with.

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

// call the source document
var srcDoc = app.activeDocument;
var signatureLayer = srcDoc.layers.getByName("signature");  

//var sourceFile= new File("E:/Signatures/sig1.tif");
var sourceFile= new File("C:/Users/harry/OneDrive/Desktop/Replace/test.jpg");
var idPlc = charIDToTypeID( "Plc " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, sourceFile);
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
executeAction( idPlc, desc3, DialogModes.NO );

var replacementImage = srcDoc.layers[0]

changeSizeto(signatureLayer,replacementImage)

function changeSizeto(source,chngLayer){
    startRulerUnits = app.preferences.rulerUnits;
    //pref pixels
    app.preferences.rulerUnits = Units.PIXELS
    
    // Calculate length and width based on the rectangular bounds of the selected layer
    var sourceHeight = source.bounds[2].value-source.bounds[0].value; //Grab the length
    var sourceWidth = source.bounds[3].value-source.bounds[1].value; //Grab the width

    var newWidth=sourceWidth;
    var newHeight=sourceHeight;
    
    chngLayer.resize(newWidth,newHeight,AnchorPosition.MIDDLECENTER);

}

I'm having problems figuring out why my layer does not resize to match the dimensions of the source layer. I set signatureLayer equal to the layer named "signature" and pass it and the layer I want changed into the function changeSizeto. It looks like it's taking the dimensions of the background layer instead. I can't see where I messed up. This is just a small bit of the script I'm working on but essentially I will be reading in an image location from a txt file, resizing it according to the source layer "signature" dimensions, saving the psd out as an image, then read in another image location and repeat.

#target photoshop

// must have source psd open to start with.

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

// call the source document
var srcDoc = app.activeDocument;
var signatureLayer = srcDoc.layers.getByName("signature");  

//var sourceFile= new File("E:/Signatures/sig1.tif");
var sourceFile= new File("C:/Users/harry/OneDrive/Desktop/Replace/test.jpg");
var idPlc = charIDToTypeID( "Plc " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, sourceFile);
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
executeAction( idPlc, desc3, DialogModes.NO );

var replacementImage = srcDoc.layers[0]

changeSizeto(signatureLayer,replacementImage)

function changeSizeto(source,chngLayer){
    startRulerUnits = app.preferences.rulerUnits;
    //pref pixels
    app.preferences.rulerUnits = Units.PIXELS
    
    // Calculate length and width based on the rectangular bounds of the selected layer
    var sourceHeight = source.bounds[2].value-source.bounds[0].value; //Grab the length
    var sourceWidth = source.bounds[3].value-source.bounds[1].value; //Grab the width

    var newWidth=sourceWidth;
    var newHeight=sourceHeight;
    
    chngLayer.resize(newWidth,newHeight,AnchorPosition.MIDDLECENTER);

}

Edit:

test

Source Link

Layer doesn't resize properly

I'm having problems figuring out why my layer does not resize to match the dimensions of the source layer. I set signatureLayer equal to the layer named "signature" and pass it and the layer I want changed into the function changeSizeto. It looks like it's taking the dimensions of the background layer instead. I can't see where I messed up. This is just a small bit of the script I'm working on but essentially I will be reading in an image location from a txt file, resizing it according to the source layer "signature" dimensions, saving the psd out as an image, then read in another image location and repeat.

#target photoshop

// must have source psd open to start with.

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

// call the source document
var srcDoc = app.activeDocument;
var signatureLayer = srcDoc.layers.getByName("signature");  

//var sourceFile= new File("E:/Signatures/sig1.tif");
var sourceFile= new File("C:/Users/harry/OneDrive/Desktop/Replace/test.jpg");
var idPlc = charIDToTypeID( "Plc " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, sourceFile);
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
executeAction( idPlc, desc3, DialogModes.NO );

var replacementImage = srcDoc.layers[0]

changeSizeto(signatureLayer,replacementImage)

function changeSizeto(source,chngLayer){
    startRulerUnits = app.preferences.rulerUnits;
    //pref pixels
    app.preferences.rulerUnits = Units.PIXELS
    
    // Calculate length and width based on the rectangular bounds of the selected layer
    var sourceHeight = source.bounds[2].value-source.bounds[0].value; //Grab the length
    var sourceWidth = source.bounds[3].value-source.bounds[1].value; //Grab the width

    var newWidth=sourceWidth;
    var newHeight=sourceHeight;
    
    chngLayer.resize(newWidth,newHeight,AnchorPosition.MIDDLECENTER);

}