2017-08-24 60 views
3

我有一个包含300多个配置文件的文件夹,我必须按照浅色至深色调的颜色进行分类。我可以创建一个动作来获取每个skintones的平均颜色,但我无法自动重命名文件以匹配每种颜色来标识。在Photoshop中查找所有图层/图像的平均颜色并使用平均颜色的文件名保存的脚本

是否可以创建一个脚本来查找文件夹中每个图像的平均颜色(整张照片的平均颜色;我通常只是滤镜>模糊>平均图层),然后使用RGB保存新图像或在原始文件名之前添加的平均颜色的十六进制名称?

EX:脚本过滤器>模糊>平均图层后。 skintone01.jpg的平均颜色是#ad8475,所以它会将文件重命名为ad8475-skintone01.jpg

另外,我不确定这是否可行,但是有没有办法按照所有图层进行排列以平均颜色使用脚本。我不认为它可以,但是因为我们正在讨论这个话题,所以不妨把它放在那里。

编辑:我刚刚测试了一些照片,发现由HEX排序并不理想,因为Windows按奇怪的顺序对十六进制代码进行排序。到目前为止,只要三个数字之间有空格,我发现按RGB数字排序是理想的。 EX:如果平均颜色RGB是110 73 58,那么脚本会将新文件命名为“110 73 58 skintone01.jpg”而不是“1107358 skintone01.jpg”。再次,这是由于Windows如何对文件进行排序。

** Bascially,这就是我想要的脚本文件夹中的每个照片的事:

  1. 复制图层
  2. 滤镜>模糊>平均
  3. 当前层复制RGB值
  4. 打开当前层(一个具有平均颜色)无形
  5. 与原来的文件名(与每个RBG值之间的空间)之前的RGB值保存图像。**
+0

这是一个有趣的问题。我想我知道你要去哪里。为了澄清,不知道你的源图像实际上是什么样子的:你有平均模糊之前和之后的皮肤石像的例子吗?您目前是否在手动选择您制作RGB值的图像上的位置?除了阶段3以外,剧本应该是直截了当的,这是棘手的部分。 –

+0

非常感谢你帮助我。以下是使用模糊的skintone [链接](https://imagez.to/i/B6vBxm5x.png)及其平均[链接](https://imagez.to/i/5CzOW8g9.jpg)的示例图像>整个图像的平均值。因为我对整个图像的重复图层进行了平均处理,所以从哪里获取RGB值并不重要。是的,第3部分和其他部分是棘手的部分,因为它不可能仅用于PSP操作,但我对脚本也不熟悉。 –

回答

2

非常感谢你,食尸鬼傻瓜!

我随着你的脚本一起玩了一些研究,并设法修复错误的Photoshop在我身上。我也做了一些调整,以我的喜好。这是产生的代码我使用:

// Set reference for active document 
var srcDoc = app.activeDocument; 

// get filename 
myFileName = srcDoc.name; 
//docName = myFileName.substring(0,myFileName.lastIndexOf(".")); 

//Duplicate Layer and call it "blurred" 
var layerName = "blurred"; 
srcDoc.activeLayer.duplicate().name = layerName; 

//Select "Blurred" Layer 
activeDocument.activeLayer = activeDocument.artLayers.getByName("blurred"); 

// Filter > Blur > Average 
srcDoc.activeLayer.applyAverage(); 

// remove any sample first 
srcDoc.colorSamplers.removeAll(); 

// get width and height of image 
var w = srcDoc.width.value; 
var h = srcDoc.height.value; 

// get positions of the center of the image 
//var x = 0; 
//var y = 0; 
var x = Math.round(w/2); 
var y = Math.round(h/2); 

// will pick a sample from the middle of the image 
var px = [UnitValue(x) , UnitValue(y)]; 
var skinSampler = srcDoc.colorSamplers.add(px); 

// Copy RGB Values of current layer with 3 decimal spaces 
var myColor = skinSampler.color; 
var rgb_R = Math.round(myColor.rgb.red*1000)/1000; 
var rgb_G = Math.round(myColor.rgb.green*1000)/1000; 
var rgb_B = Math.round(myColor.rgb.blue*1000)/1000; 

// remove that sample no we know it's value 
srcDoc.colorSamplers.removeAll(); 

// Turn current layer (one with the average color) invisible 
srcDoc.activeLayer.visible = false; 

// Save image with RGB values before the original filename (with a space between each RBG value). 
mySaveName = rgb_R + " " + rgb_G + " " + rgb_B + " " + myFileName; 

// Set filePath and fileName to source path 
var filePath = srcDoc.path + "/" + mySaveName; 

// save as jpeg 
jpegIt(filePath, 12); 

// function for saving as jpeg 
function jpegIt(filePath, myJpgQuality) 
{ 
    if(! myJpgQuality) myJpgQuality = 12; 

    // Flatten the jpg 
    activeDocument.flatten(); 

    // jpg file options 
    var jpgFile = new File(filePath); 
    jpgSaveOptions = new JPEGSaveOptions(); 
    jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE; 
    jpgSaveOptions.embedColorProfile = true; 
    jpgSaveOptions.matte = MatteType.NONE; 
    jpgSaveOptions.quality = myJpgQuality; 

    activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE); 

    //close without saving 
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
} 

我所做的只是让平均之前的“模糊”层激活,然后更改编码复制RGB值从抽样码,适合的值。然后,我添加了代码,以便将结果舍入为小数点后3位。

当我试图看看我是否可以获得脚本来将所有新图像保存到一个新文件夹,但无法弄清楚如何。大声笑。但至少我得到了它的工作。

非常感谢您的帮助。如果没有你,我无法做到这一点,而且可能会坐在电脑前几个小时。 :D

1

好了,这里的你需要什么:

// Set reference for active document 
var srcDoc = app.activeDocument; 

// get filename 
myFileName = srcDoc.name; 
//docName = myFileName.substring(0,myFileName.lastIndexOf(".")); 

//Duplicate Layer and call it "blurred" 
var layerName = "blurred"; 
srcDoc.activeLayer.duplicate().name = layerName; 

// Filter > Blur > Average 
srcDoc.activeLayer.applyAverage(); 


// remove any sample first 
srcDoc.colorSamplers.removeAll(); 

// get width and height of image 
var w = srcDoc.width.value; 
var h = srcDoc.height.value; 

// get positions of the center of the image 
//var x = 0; 
//var y = 0; 
var x = Math.round(w/2); 
var y = Math.round(h/2); 

// will pick a sample from the middle of the image 
var px = [UnitValue(x) , UnitValue(y)]; 
var skinSampler = srcDoc.colorSamplers.add(px); 

// Copy RGB Values of current layer 
var myColour = myColorSampler.color; 
var rgb_R = myColor.rgb.red; 
var rgb_G = myColor.rgb.green; 
var rgb_B = myColor.rgb.blue; 

// remove that sample no we know it's value 
srcDoc.colorSamplers.removeAll(); 

// Turn current layer (one with the average color) invisible 
srcDoc.activeLayer.visible = false; 

// Save image with RGB values before the original filename (with a space between each RBG value). 
mySaveName = rgb_R + " " + rgb_G + rgb_B + myFileName; 

// Set filePath and fileName to source path 
var filePath = srcDoc.path + "/" + mySaveName; 

// save as jpeg 
jpegIt(filePath, 12); 

// function for saving as jpeg 
function jpegIt(filePath, myJpgQuality) 
{ 
    if(! myJpgQuality) myJpgQuality = 12; 

    // Flatten the jpg 
    activeDocument.flatten(); 

    // jpg file options 
    var jpgFile = new File(filePath); 
    jpgSaveOptions = new JPEGSaveOptions(); 
    jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE; 
    jpgSaveOptions.embedColorProfile = true; 
    jpgSaveOptions.matte = MatteType.NONE; 
    jpgSaveOptions.quality = myJpgQuality; 

    activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE); 

    //close without saving 
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
} 

我这样做盲目的,应该工作,虽然。

+0

哦,非常感谢你!我刚刚完成了测试,Adobe正在抛出一个错误“srcDoc.activeLayer.applyAvergeBlur(avg);”不是一个功能。 –

+0

我已将它更改为applyAverage();代替。立即给它一个 –

+0

修复工程,但现在它扔回这个错误:[链接](https://imagez.to/i/pT8J29gF.jpg)。我认为它可能不得不做一些事情,它是模糊底层而不是重复的。 –