2013-05-31 89 views
3

例如,我有一個有兩層的項目。第一層是透明的。第二層有一個矩形,其不透明度爲50%。Photoshop腳本忽略保存爲PNG的透明度(Mac OS)

保存在保存的文件中後,圖片看起來像不透明度爲100%(完全不透明)。如何解決這個問題?我用下面的功能,節省:

function SavePNG(saveFile){ 
    var opts = new ExportOptionsSaveForWeb(); 
    opts.format = SaveDocumentType.PNG; 
    opts.PNGB = false; 
    opts.quality = 100; 
    pngFile = new File(saveFile); 
    opts.includeProfile = true; 
    app.activeDocument.exportDocument(pngFile, ExportType.SAVEFORWEB, opts); 
} 

我使用的Photoshop CS6

回答

3

我發現在Photoshop論壇的解決方案:

function SavePNG(saveFile){ 
    pngFile = new File(saveFile); 

    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG 
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = false; 
    pngOpts.quality = 100; 
    activeDocument.exportDocument(pngFile,ExportType.SAVEFORWEB,pngOpts); 
} 

至少該解決方案還沒有問題的透明度和自動工作,而不顯示對話框

2

嘗試增加這選項

opts.transparency = true 

好清單,儘量ExportOptionsSave

function SavePNG(saveFile) 
{ 
    var pngFile = new File(filePath); 
    opts = new PNGSaveOptions(); 
    opts.format = SaveDocumentType.PNG; 
    opts.transparency = true 
    opts.PNGB = false; 
    opts.quality = 100; 
    opts.includeProfile = true; 

    activeDocument.saveAs(pngFile, opts, false, Extension.LOWERCASE); 
} 

我通常沿着這些線使用一些東西:

// call the source document 
var srcDoc = app.activeDocument; 
var fileName = app.activeDocument.name; 
var docName = fileName.substring(0,fileName.length -4) 

// Set filePath and fileName to source path 
filePath = srcDoc.path + '/' + app.activeDocument.name + '.png'; 

// duplicate image into new document 
// ======================================================= 
var id2784 = charIDToTypeID("Mk "); 
var desc707 = new ActionDescriptor(); 
var id2785 = charIDToTypeID("null"); 
var ref508 = new ActionReference(); 
var id2786 = charIDToTypeID("Dcmn"); 
ref508.putClass(id2786); 
desc707.putReference(id2785, ref508); 
var id2787 = charIDToTypeID("Nm "); 
desc707.putString(id2787, docName); 
var id2788 = charIDToTypeID("Usng"); 
var ref509 = new ActionReference(); 
var id2789 = charIDToTypeID("Lyr "); 
var id2790 = charIDToTypeID("Ordn"); 
var id2791 = charIDToTypeID("Trgt"); 
ref509.putEnumerated(id2789, id2790, id2791); 
desc707.putReference(id2788, ref509); 
executeAction(id2784, desc707, DialogModes.NO); 

// save out the image 
var pngFile = new File(filePath); 
pngSaveOptions = new PNGSaveOptions(); 
pngSaveOptions.embedColorProfile = true; 
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 
pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1; 

activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE); 

// close that saved png 
app.activeDocument.close() 
+0

還是同樣的問題 – user2412679

+0

當然的了第二種方式起作用,因爲我需要手動保存它,因爲保存對話框出現。但是,至少可以在此對話框中添加如何設置文件的名稱?它需要正確的名稱,但如果它是在這個目錄中的同名的東西,那麼名稱變成「... copy.png」 – user2083364

+0

這不是優雅的,但我通過複製圖像並保存該圖像來解決該問題。 –