Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

stretching/translating a layer into another document

$
0
0

I probably just have my math wrong, but given a selection box boundary (or boundaries), I'm trying to resize it so that it's the size of a target document and then translate it so it's in the top-left corner taking up the whole screen (so what's in square selection takes up whole screen.  Now if I duplicate the layer in the same document and scale it using the document's dimensions and translate, it fills the whole screen.  However, if duplicate the layers into a target document and scale and translate according to its dimensions, the layer is the correct size, but wildly off position (most of the time off the page).  I would think the translation would be independent of the destination doc and based just on the scale and (minX,minY) of the selection box. 

 

Is my math off or is there something funny about duplicating a layer into another document?  I'm guessing it's the former, but I keep doing it in my head and the math looks sensible. 

 

 

    var layer = app.activeDocument.activeLayer;
    //layer.isBackgroundLayer = false;
    var layers = new Array(thumbnails.length);
    //layers[0] = layer;
    for (var i = 0; i < layers.length; i++) {
            layers[i] = layer.duplicate(documentTarget);
    }
 
    var srcDocument = app.activeDocument;
    app.activeDocument = documentTarget;
 
    // for every layer, go through translating and resizing based on the box size
    for (var i = 0; i < layers.length; i++) {
            var selectionBox = thumbnails[i];
   

    var scaleX = documentTarget.width.as("px") / (selectionBox["maxX"] - selectionBox["minX"]);
             var scaleY = documentTarget.height.as("px") / (selectionBox["maxY"] - selectionBox["minY"]);


       
       
   
       
       
   
            layers[i].resize(scaleX * 100, scaleY * 100, AnchorPosition.TOPLEFT);
            layers[i].translate(new UnitValue(-selectionBox["minX"] * scaleX, "px"),
                                                                   new UnitValue(-selectionBox["minY"] * scaleY, "px"));
    }


   


 


}

}


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>