2017-08-02 79 views
-1

我是所有新来的Photoshop脚本,我似乎无法找到非常多的文档。我知道一些Applescript脚本,但正如我读过的,Photoshop脚本最像是JAVA脚本?Photoshop脚本来确定颜色或黑白照片

Anyhoo,我需要一个脚本来决定Photoshop中的活动文档是彩色照片还是黑白照片。我知道我认为它会起作用,但我不知道如何写它。我需要这个打印行动,我打印JPG文件。所以它总是完成这个脚本运行的JPG文件。

这里就是我想的理论,使其工作:

  1. 复制背景图层。 (可以用动作完成)
  2. 添加滤镜 - 模糊 - 平均到新图层(可以用动作完成)
  3. 如果在新图层上红色通道等于蓝色通道,并且蓝色通道等于绿色在新图层上的任何地方都会有相同的颜色和亮度,做'黑白动作',否则做'颜色动作'。 (我需要一个脚本)

背后的想法,正如你已经想到的,就是在任何地方都可以测量一层图像,以确定图像中是否有任何颜色。 这是我能想到的最好的方法,使一个脚本,将工作在所有图像(不是多层图像,但)。

任何人都可以帮我用这段代码?

回答

0

我想通了。

#target photoshop 

var savePathSH = "Macintosh HD:PATH1:" 
var savePathFarve = "Macintosh HD:Users:PATH2:" 
var doc = app.activeDocument 
var fname = doc.name.split(".jpg") 
var fname = fname[0] 
var halfHeight = (app.activeDocument.height)/2; 
var halfWidth = (app.activeDocument.width)/2; 
var newLayer = doc.activeLayer.duplicate(); 

function saveJPG(name, savepath){ 
var doc = app.activeDocument; 
    var file = new File(savepath + name + ".jpg"); 
var opts = new JPEGSaveOptions(); 
opts.quality = 12; 

doc.saveAs(file, opts, true); 
} 

newLayer; 

doc.activeLayer = doc.layers[0]; 

doc.activeLayer.applyAverage(); 

app.activeDocument.colorSamplers.removeAll(); 

var theSampler = app.activeDocument.colorSamplers.add([halfWidth,halfHeight]); 

var currentColor = theSampler.color; 

var redValue = theSampler.color.rgb.red; 
var greenValue = theSampler.color.rgb.green; 
var blueValue = theSampler.color.rgb.blue; 

app.activeDocument.colorSamplers.removeAll(); 

doc.activeLayer.remove(); 

if (redValue == greenValue && greenValue == blueValue) { 

    var BW = true 
    } else { 
    var BW = false 
    } 

    if (BW == true) { 
saveJPG(fname, savePathSH); 
} else { 
saveJPG(fname, savePathFarve); 
} 
相关问题