【问题标题】:How can I retrieve the color in a Photoshop Fill Layer如何在 Photoshop 填充图层中检索颜色
【发布时间】:2013-10-17 03:05:27
【问题描述】:

我正在尝试编写一个脚本来自动化从我们根据使用情况自定义的 Photoshop 文件中的多个填充图层中提取颜色的过程。 问题是似乎没有办法读取填充层的指定颜色。

我已经尝试了所有我能想到的方法,但没有任何效果。这是迄今为止我得到的最接近的:

this 论坛中,我找到了一种读取样本值和名称的方法。我使用了 Scripting Listener 插件来记录动作,但是当双击填充层缩略图并点击“添加到色板”时,我得到的只是这样的:

var idMk = charIDToTypeID( "Mk  " );
var desc90 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
    var ref42 = new ActionReference();
    var idClrs = charIDToTypeID( "Clrs" );
    ref42.putClass( idClrs );
desc90.putReference( idnull, ref42 );
var idUsng = charIDToTypeID( "Usng" );
    var desc91 = new ActionDescriptor();
    var idNm = charIDToTypeID( "Nm  " );
    desc91.putString( idNm, """Swatch 3""" );
    var idClr = charIDToTypeID( "Clr " );
        var desc92 = new ActionDescriptor();
        var idRd = charIDToTypeID( "Rd  " );
        desc92.putDouble( idRd, 229.000397 );
        var idGrn = charIDToTypeID( "Grn " );
        desc92.putDouble( idGrn, 137.001801 );
        var idBl = charIDToTypeID( "Bl  " );
        desc92.putDouble( idBl, 135.997925 );
    var idRGBC = charIDToTypeID( "RGBC" );
    desc91.putObject( idClr, idRGBC, desc92 );
var idClrs = charIDToTypeID( "Clrs" );
desc90.putObject( idUsng, idClrs, desc91 );
executeAction( idMk, desc90, DialogModes.NO );

也就是说,我得到了我当时选择的具体值,但没有办法在循环中实现它(至少我能想到)。

另外,如果我能找到一种方法让每个填充层的颜色依次成为前景色,那么我知道我可以阅读,但我该如何做到呢?吸管似乎是一种选择,但我想不出一种使它起作用的方法。

有什么想法吗?

【问题讨论】:

    标签: javascript colors photoshop


    【解决方案1】:

    我猜它一直都在那里。在the forum thread mentioned above 中,它说:

    这基本上就是调整层的工作方式。有一个“Adjs”列表 通常有一个 Adjustment 对象,在这种情况下是一个 固体颜色层。里面是颜色描述符。

    我能够将每个填充层视为调整层,并从那里提取颜色数据:

    //@include "C:/Program Files/Adobe/Adobe Photoshop CC/Presets/Scripts/xlib/stdlib.js"
    
    //Create CSV file to record palette
    var skinColors = File ("c:/Skinpalette.txt");
    if (skinColors.exists) {
        skinColors.remove();
    }    
    skinColors = new File ("c:/Skinpalette.txt");
    
    //Function to extract color from Layer
    function getAdjustmentLayerColor(doc, layer) { 
        var desc = Stdlib.getLayerDescriptor(doc, layer);
        var adjs = desc.getList(cTID('Adjs'));
    
        var clrDesc = adjs.getObjectValue(0);
        var color= clrDesc.getObjectValue(cTID('Clr '));
    
        var red = Math.round(color.getDouble(cTID('Rd  ')));
        var green = Math.round(color.getDouble(cTID('Grn ')));
        var blue = Math.round(color.getDouble(cTID('Bl  ')));
    
        var createdSolidColor = Stdlib.createRGBColor(red, green, blue);
        var createdRGBColor = createdSolidColor.rgb;
        return createdRGBColor.hexValue;
    };
    
    //Function to cycle through layers and output to external file
    function getColors(layerNode) {    
        for (var i=0; i<layerNode.length; i++) {
            getColors(layerNode[i].layerSets);
            for(var layerIndex=0; layerIndex < layerNode[i].artLayers.length; layerIndex++) {
                var layer=layerNode[i].artLayers[layerIndex];
                app.activeDocument.activeLayer = layer;
    
                 if (layer.kind == LayerKind.SOLIDFILL) {
                    skinColors.open ("a");
                    skinColors.write(layer.name + " = " + getAdjustmentLayerColor(app.activeDocument, layer) + ";\n");
                    skinColors.close ();
                 }
            }
        }
    }
    
    getColors(app.activeDocument.layerSets);
    

    我希望这对某人有用,尽管正如我所说,我希望我早点注意到!

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 2018-05-21
      • 2021-07-14
      • 2021-03-23
      • 2019-12-11
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 2014-03-06
      相关资源
      最近更新 更多