Skip to content

Instantly share code, notes, and snippets.

@ku-suke
Created September 19, 2012 08:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ku-suke/3748402 to your computer and use it in GitHub Desktop.
Save ku-suke/3748402 to your computer and use it in GitHub Desktop.
透過を含んだ写真画像を、PNGではなくJPEG+マスクPNGにすることで軽量化するテクニックの補助用にPSDスクリプト書いてみた。
// Export JPEG for WEB with Selection Mask (as PNG)
// Written by ku-suke <gachasan@gmail.com>
var flag = confirm("Export Selection to PNG.Export original to JPEG.");
if(flag){
var docObj = activeDocument;
var baseName = docObj.name.substring(0,String(docObj.name).length - 4 );
var folderPath = docObj.path + "/" + baseName;
var folderObj = new Folder(folderPath);
folderObj.create();
// Save Original JPEG Image
var exp = new ExportOptionsSaveForWeb();
exp.format = SaveDocumentType.JPEG;
exp.quality = 80; ///////// Fixed Value. You can change quality.
var imgFile = new File(folderPath + "/" + baseName + ".jpg");
docObj.exportDocument(imgFile, ExportType.SAVEFORWEB, exp);
// Save Selection mask to PNG
activeDocument.channels.add();
var fillColor = new SolidColor();
fillColor.gray.gray = 0;
activeDocument.selection.fill(fillColor);
activeDocument.selection.selectAll();
activeDocument.activeLayer.copy();
/* アルファチャンネルを生成後新規レイヤーにコピペ */
var tempLayer = activeDocument.artLayers.add();
activeDocument.paste(false);
tempLayer.name = "Generated mask image";
exp.format = SaveDocumentType.PNG;
var maskFile = new File(folderPath + "/" + baseName + "_mask.png");
docObj.exportDocument(maskFile, ExportType.SAVEFORWEB, exp);
alert("Saved:\n"+folderPath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment