Photoshop - 基于当前位置的RGB信息在图像中着色的脚本

时间:2016-08-25 20:29:47

标签: javascript photoshop

想看看我们可以放入办公室的一些艺术作品是否可行。我有一些基于一些非常古老的工程图纸的复杂线条图。它们基本上是2层文件,白线细节和黑色背景层。

我希望随机地为图像着色,并想知道是否可以制作脚本而不是手动完成。我制作了一些photoshop脚本,但这超出了我的编程技巧。

我很好奇是否可以制作以下内容的脚本......

  1. 将鼠标移动到图像上的随机X,Y%位置
  2. 检查颜色是否为0,0,0(黑色)
  3. 如果是,则用给定颜色涂抹桶填充并返回步骤1
  4. 如果否,返回步骤1
  5. 重复100次

    因此,如果当前光标位置的颜色为黑色,脚本会在图像周围移动并且存储桶会填充颜色。希望这将随机填写这些图像的所有工程细节,而不会意外填写白色/灰色而非黑色的前景细节。

    理论上可以做到这一点吗?

    由于

1 个答案:

答案 0 :(得分:0)

这些方法来自我10年前制作的旧Photoshop脚本,但它们可能会有所帮助。有两个功能,一个用于执行吸管点击x,y点以获取颜色,另一个用于执行魔术棒点击x,y点。对于你的例子,你可以对一个点进行滴眼,如果它返回黑色,你可以使用魔棒同一点来选择该区域,然后对该选择进行填充。

function eyedropper(doc,x,y) {
// don't mess with spacing inside function, seesm to braek it
Stdlib = function() {}; 
Stdlib.selectBounds = function(doc, b, type, feather, antialias) { 
    doc.selection.select([[ b[0], b[1] ], 
                          [ b[2], b[1] ], 
                          [ b[2], b[3] ], 
                          [ b[0], b[3] ]], 
                      type, feather, antialias); 
    }; 

    // getColorAt 
    // based on: 
    //     fazstp@adobeforums.com wrote: 
    //     news://adobeforums.com:119/3bb84060.0@webx.la2eafNXanI 
    // 

       // make new 1 pixel selection 
        x = Math.floor(x); 
        y = Math.floor(y); 

        Stdlib.selectBounds(doc, [x, y, x+1, y+1]); 

        try { 
            function findPV(h) { 
                for (var i = 0; i <= 255; i++ ) { 
                    if (h[i]) { return i; } 
                } 
             return 0; 
        } 

        var pColour = new SolidColor(); 

        pColour.rgb.red   = findPV(doc.channels["Red"].histogram); 
        pColour.rgb.green = findPV(doc.channels["Green"].histogram); 
        pColour.rgb.blue  = findPV(doc.channels["Blue"].histogram); 

        } finally { 
            doc.selection.deselect(); 
        } 
    return pColour; 
};

此外,这是我执行魔杖的功能:

function wand(x,y,tol,option)
{
    // options:
    // setd = initial selection
    // AddT = add to selection

    var id9466 = charIDToTypeID( option );
        var desc1828 = new ActionDescriptor();
        var id9467 = charIDToTypeID( "null" );
            var ref1340 = new ActionReference();
            var id9468 = charIDToTypeID( "Chnl" );
            var id9469 = charIDToTypeID( "fsel" );
            ref1340.putProperty( id9468, id9469 );
        desc1828.putReference( id9467, ref1340 );
        var id9470 = charIDToTypeID( "T   " );
            var desc1829 = new ActionDescriptor();
            var id9471 = charIDToTypeID( "Hrzn" );
            var id9472 = charIDToTypeID( "#Pxl" );
            desc1829.putUnitDouble( id9471, id9472, x );
            var id9473 = charIDToTypeID( "Vrtc" );
            var id9474 = charIDToTypeID( "#Pxl" );
            desc1829.putUnitDouble( id9473, id9474, y );
        var id9475 = charIDToTypeID( "Pnt " );
        desc1828.putObject( id9470, id9475, desc1829 );
        var id9476 = charIDToTypeID( "Tlrn" );
        desc1828.putInteger( id9476, tol );
        var id9477 = charIDToTypeID( "AntA" );
        desc1828.putBoolean( id9477, true );
    executeAction( id9466, desc1828, DialogModes.NO );
};