Created
March 30, 2014 01:57
-
-
Save nissuk/9866141 to your computer and use it in GitHub Desktop.
Photoshop: スクリプト経由でPNG保存する(サンプル)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main() { | |
// 現在のドキュメント | |
var doc = app.activeDocument; | |
// 保存先フォルダの選択 | |
var folder = Folder.selectDialog("保存先フォルダの選択"); | |
if (folder == null) { | |
return; | |
} | |
// saveAsで保存 | |
saveAsPng(doc, folder, "test-save.png"); | |
// exportDocumentで保存 | |
exportAsPng(doc, folder, "test-export.png"); | |
} | |
/** | |
* ドキュメントをPNG画像として保存します(別名で保存相当)。 | |
* | |
* @param {Document} doc | |
* @param {Folder} folder | |
* @param {string} name | |
* | |
*/ | |
function saveAsPng(doc, folder, name) { | |
// フォルダが存在しない場合作成 | |
if (!folder.exists) { | |
folder.create(); | |
} | |
var file = new File(folder.fsName + "/" + name); | |
// PNG保存のためのオプション | |
var options = new PNGSaveOptions(); | |
var asCopy = true; | |
// 保存 | |
doc.saveAs(file, options, asCopy, Extension.LOWERCASE); | |
} | |
/** | |
* ドキュメントをPNG画像として保存します(Web用に保存相当)。 | |
* | |
* @param {Document} doc | |
* @param {Folder} folder | |
* @param {string} name | |
* | |
*/ | |
function exportAsPng(doc, folder, name) { | |
// フォルダが存在しない場合作成 | |
if (!folder.exists) { | |
folder.create(); | |
} | |
var file = new File(folder.fsName + "/" + name); | |
// 「Web用に保存」のためのオプション | |
var options = new ExportOptionsSaveForWeb(); | |
// PNGで保存 | |
options.format = SaveDocumentType.PNG; | |
// 最適化有効 | |
options.optimized = true; | |
// インターレース無効 | |
options.interlaced = false; | |
// エクスポート | |
doc.exportDocument(file, ExportType.SAVEFORWEB, options); | |
} | |
// main()実行 | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment