I need to know the dimensions of a masked layer with transparent area to resize it to the same dimensions of another layer. If use the bounds data I get the dimensions of the pixels, but not the dimensions of the full layer (when not masked).

With this script I would like to resize the "mask" layer and the "frame" layer to the same size of the picture layer, like I would with the Transform command (+T).

How to do it?

var doc = app.activeDocument
var thisLayer = doc.activeLayer;

// got the group of layers
var thisGroup = thisLayer.parent;

//main layer (photo)
var thisPict = thisGroup.layers[2];
var ThisPictBounds = thisPict.bounds;
var thisPictW = ThisPictBounds[2].as('px')-ThisPictBounds[0].as('px');
var thisPictH = ThisPictBounds[3].as('px')-ThisPictBounds[1].as('px');

//mask layer
var thisMask = thisGroup.layers[1];
var ThisMaskBounds = thisMask.bounds;
var thisMaskW = ThisMaskBounds[2].as('px')-ThisMaskBounds[0].as('px');
var thisMaskH = ThisMaskBounds[3].as('px')-ThisMaskBounds[1].as('px');

// frame layer
var thisFrame = thisGroup.layers[0];
var ThisFrameBounds = thisFrame.bounds;
var thisFrameW = ThisFrameBounds[2].as('px')-ThisFrameBounds[0].as('px');
var thisFrameH = ThisFrameBounds[3].as('px')-ThisFrameBounds[1].as('px');

// rename all layers
thisPict.name = thisGroup.name + '>' + 'Pict';
thisMask.visible = false;
thisMask.name = thisGroup.name + '>' + 'Mask';
thisFrame.name = thisGroup.name + '>' + 'Frame';

// resize mask and frame layers
thisMask.resize ((thisPictW/thisMaskW)*100,(thisPictH/thisMaskH)*100, AnchorPosition.MIDDLECENTER);
thisFrame.resize ((thisPictW/thisFrameW)*100,(thisPictH/thisFrameH)*100, AnchorPosition.MIDDLECENTER);

// ### example ###
// thisMaskW = 489 (974 - 485 ) >> Real width layer dimension usig CTRL+ T command
// thisMaskH = 316 (519 - 203) >> Real height layer dimension usig CTRL+ T command

// thisMaskW = 258 (769 - 511 ) >> Pixel width dimension got by bouds data
// thisMaskH = 259 (492 - 233) >> Pixel height dimension got by bouds data


  • Can You Elaborate More?or if possible can you attack your psd file so that i can see what you trying to achieve? – Mr.Online Apr 5 at 11:38
  • @DesignPhoenix good questions should be answerable without having to look at the source files, just ask for more details. – Luciano Apr 5 at 12:16
  • @Luciano Well I'm Just Confused About That 2 Layer Mask and cant understand clearly about which thing he want to resize since you may know if the black layer mask will be resized on full scale whole image will be invisible :) – Mr.Online Apr 5 at 12:22
  • @Luciano Thanks For Clearation Though So basically its not vector mask at all; the stuff we talking is clipping mask right? Well will see if can do something to help out :) I'm just new and seems peoples liking my answers ; Just want to be helpful – Mr.Online Apr 5 at 12:33
  • 1
    [SOLVED] forums.adobe.com/thread/2455423 – Gonario Sirboni Apr 8 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.