Help Needed! Crop and Padding with script
Hi Everyone!
I have one Photoshop document 3600Px (W) X 3600px (H) x 300 dpi which contain one product with overall photoshop path.
Now I get a selection from the path & expand 50px and crop the image 1760x1760x300.
Subsequently, I check the padding was not 50 px from the edge of the product.
If suppose I expand 40px and crop the image. the image padding 50px around the image.
How do I get exact expand pixel value? Please suggest me.
-yajiv
Code:
if ( app.documents.length <= 0 ) alert( strAlertDocumentMustBeOpened,"Smart Size" );
else{ main(); }
function main(){
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;
var docRef = app.activeDocument;
var dname = docRef.name;
var fileName=dname.replace(/\.[^\.]+$/, '');
var filePath=activeDocument.path;
var myLayers=docRef.layers
docRef.pathItems[0].makeSelection(0,true,SelectionType.REPLACE);
docRef.selection.expand(50)
docRef.crop(docRef.selection.bounds);
var imgW=docRef.width;
var imgH=docRef.height;
if(imgW>imgH){
docRef.resizeImage(new UnitValue(1760,'Px'), undefined, 300, ResampleMethod.AUTOMATIC);
docRef.resizeCanvas( undefined,new UnitValue(1760,'Px'),AnchorPosition.MIDDLECENTER);
}else{
docRef.resizeImage(undefined, new UnitValue(1760,'Px'),300, ResampleMethod.AUTOMATIC);
docRef.resizeCanvas( new UnitValue(1760,'Px'),undefined,AnchorPosition.MIDDLECENTER);
}
}