2017-08-02 77 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); 
} 
相關問題