1

我整天都在谷歌搜索,以找到一种方法将转换为智能对象中心的图层与通过脚本进行的画布对齐,但到目前为止还没有找到解决方案。我最终得到了下面的代码,但它没有完成这项工作。有人可以帮忙吗?

var baseFile = new File(openDialog()); //open base JPEG file
var workFile = new File(openDialog()); //open work JPEG file
var baseDoc = app.open(baseFile);
var workDoc = app.open(workFile);

createSO(workDoc.layers[0]);
workDoc.resizeImage(280,280);
workDoc.artLayers[0].duplicate(baseDoc, ElementPlacement.INSIDE);
app.activeDocument = baseDoc;

var Hoffset = (baseDoc.width - workDoc.width) / 2;
var Voffset = (baseDoc.height - workDoc.height) / 2;
baseDoc.layers[1].position = Array(Hoffset, Voffset);

function createSO(){
    var doc = app.activeDocument;
    var idnewPlacedLayer = stringIDToTypeID( "newPlacedLayer" );
    executeAction( idnewPlacedLayer, undefined, DialogModes.NO );
    return doc.activeLayer;
}
4

1 回答 1

0

我认为您可以通过这种方式简化一点:

var baseFile = new File(openDialog()); //open base JPEG file
var workFile = new File(openDialog()); //open work JPEG file
var baseDoc = app.open(baseFile);
var workDoc = app.open(workFile, undefined, true);

workDoc.resizeImage(280, 280);
var duplicated = workDoc.artLayers[0].duplicate(baseDoc, ElementPlacement.INSIDE);
var Hoffset = (baseDoc.width - workDoc.width) / 2;
var Voffset = (baseDoc.height - workDoc.height) / 2;

app.activeDocument = baseDoc;

duplicated.translate(Hoffset, Voffset);

这里的重点是使用translate方法;但是,您也可以避免 使用(即)createSO的第三个参数来创建函数。app.openasSmartObject

于 2013-10-27T20:16:52.123 回答