代码之家  ›  专栏  ›  技术社区  ›  Jarrett G.

Photoshop水印脚本?

  •  0
  • Jarrett G.  · 技术社区  · 13 年前

    我不确定这是AppleScript的东西,还是用实际语言会更好(Photoshop记录操作很糟糕),但我想知道Photoshop中是否有办法:

    • 拍摄图像
    • 将另一个图像粘贴到上面
    • 从右下角开始,将图像向左移动X像素,向上移动Y像素
    • 将不透明度更改为40%
    • 将图像保存到旧图像上
    1 回复  |  直到 13 年前
        1
  •  0
  •   Ghoul Fool    13 年前

    通常,Stack Overflow就是提出问题并得到答案。更重要的是,如果你已经努力尝试自己的问题;而不是满足要求。但既然你指出,写下你的想法而不是执行一个动作是有益的,我已经为你写了一些基本知识。也许你可以选择它,带着它跑步。

    首先,有三种语言可以编写Photoshop脚本。他们是 苹果脚本 , JavaScript语言 和 Visual Basic语言 尽管VB是少数。JavaScript是首选武器。

    这是一个JavaScript,它将移动水印并保存在现有文件上。 并不是说通过脚本粘贴可能有点棘手;因为除非您事先立即剪切或复制图像,否则它可能无法工作。粘贴两次似乎不起作用,所以你必须复制图像 就在之前 你运行脚本。您可以更改脚本以加载到所需的文件中,并将其放置在其他文档中:

    // call the source document
    var srcDoc = app.activeDocument;
    
    //get the image with and height
    var w = srcDoc.width.value;
    var h = srcDoc.height.value;
    
    // paste into current document
    app.activeDocument.paste();
    
    // set the name
    srcDoc.activeLayer.name = "watermark"
    
    // set the distance the watermark needs to move
    var offsetX = 40;
    var offsetY = 20;
    
    //call the function to offset the image
    moveActiveLayer(w, h, offsetX, offsetY)
    
    //set opacity
    srcDoc.activeLayer.opacity = 40
    
    //flatten the image
    srcDoc.flatten();
    
    //save the image
    app.activeDocument.close(SaveOptions.SAVECHANGES)
    
    // function MOVE ACTIVE LAYER (layer name, deltaX, deltaY)
    // ----------------------------------------------------------------
    function moveActiveLayer(imageWidth, imageHeight, dX, dY)
    {
        var x = parseFloat(srcDoc.activeLayer.bounds[0])
        var y = parseFloat(srcDoc.activeLayer.bounds[1])
        var x1 = parseFloat(srcDoc.activeLayer.bounds[2])
        var y1 = parseFloat(srcDoc.activeLayer.bounds[3])
    
        var moveX = (imageWidth - x1) - dX;
        var moveY = (imageHeight- y1) - dY;
    
        // coords from bottom right
    
        // Transform layer
        // =======================================================
        var id442 = charIDToTypeID( "Trnf" );
        var desc93 = new ActionDescriptor();
        var id443 = charIDToTypeID( "null" );
        var ref64 = new ActionReference();
        var id444 = charIDToTypeID( "Lyr " );
        var id445 = charIDToTypeID( "Ordn" );
        var id446 = charIDToTypeID( "Trgt" );
        ref64.putEnumerated( id444, id445, id446 );
        desc93.putReference( id443, ref64 );
        var id447 = charIDToTypeID( "FTcs" );
        var id448 = charIDToTypeID( "QCSt" );
        var id449 = charIDToTypeID( "Qcsa" );
        desc93.putEnumerated( id447, id448, id449 );
        var id450 = charIDToTypeID( "Ofst" );
        var desc94 = new ActionDescriptor();
        var id451 = charIDToTypeID( "Hrzn" );
        var id452 = charIDToTypeID( "#Pxl" );
        desc94.putUnitDouble( id451, id452, moveX );
        var id453 = charIDToTypeID( "Vrtc" );
        var id454 = charIDToTypeID( "#Pxl" );
        desc94.putUnitDouble( id453, id454, moveY );
        var id455 = charIDToTypeID( "Ofst" );
        desc93.putObject( id450, id455, desc94 );
        executeAction( id442, desc93, DialogModes.NO );
    }