调整Photoshop转换JavaScript以包含缩放变量

时间:2014-09-19 16:42:14

标签: extendscript photoshop-script

所以在环顾四周之后,我终于找到了一些几乎可以满足需要的东西。我计划使用applescript传递变量。那说我们得到了javascript。我不太了解它,仍然试图捡起它。

任何人都可以帮我添加一些代码,以便在定义锚点后缩放图像。当前代码还需要用户确认设置。由于我传递变量,我不需要它来做到这一点。我认为我需要做的就是改变" DialogModes.ALL" to" DialogModes.NO"

function transform( x, y) {// anchor position as pixels  
    var desc = new ActionDescriptor();  
        var ref = new ActionReference();  
        ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
    desc.putReference( charIDToTypeID('null'), ref );  
    desc.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsi') );  
        var desc7 = new ActionDescriptor();  
        desc7.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Rlt'), x );  
        desc7.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Rlt'), y );  
    desc.putObject( charIDToTypeID('Pstn'), charIDToTypeID('Pnt '), desc7 );  
    desc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Prc'), 100 );  
    desc.putUnitDouble( charIDToTypeID('Hght'), charIDToTypeID('#Prc'), 100 );  
    desc.putBoolean( charIDToTypeID('Lnkd'), true );  
    desc.putEnumerated( charIDToTypeID('Intr'), charIDToTypeID('Intp'), charIDToTypeID('Bcbc') );  
    executeAction( charIDToTypeID('Trnf'), desc, DialogModes.ALL );  
};  

transform( 584, 330)

我正在寻找最终看起来像这样的函数输入。

transform( 584, 330, 50, 50) 

这将使得584 = X,330 = y像素锚,而50,50将是x,y比例的百分比。

任何帮助抛光这一点将不胜感激。我需要将其用作10,000个图像的批处理操作的一部分......

1 个答案:

答案 0 :(得分:0)

将功能定义更改为

function transform(x, y, w, h) {

并将以desc.putUnitDouble开头的行更改为以下内容:

desc.putUnitDouble( charIDToTypeID('Wdth'), charIDToTypeID('#Prc'), w );  
desc.putUnitDouble( charIDToTypeID('Hght'), charIDToTypeID('#Prc'), h );