Created
August 4, 2011 09:24
-
-
Save Layzie/1124825 to your computer and use it in GitHub Desktop.
make 9patch file using PhotoShop
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
//rulerはpx指定にしておく | |
//9patch変換前のpngファイルを開いてから、このスクリプトを使用する | |
// vim:set ft=javascript: | |
#target photoshop | |
var doc = app.activeDocument; | |
function changeCanvas() { | |
var w = activeDocument.width.value, | |
h = activeDocument.height.value; | |
//9patch用に1pxずつカンバスを拡張 | |
doc.resizeCanvas(w + 2, h + 2); | |
} | |
function saveFile() { | |
var fileName = doc.name, | |
filePath = doc.path, | |
dirPath = filePath.fsName, | |
originalName = fileName.split('.'), | |
patchDir = new Folder(dirPath + '/9patch/'), | |
fileObj, pngOpt; | |
if (!patchDir.exists) { | |
patchDir.create(); | |
} | |
//同階層の"9patch"フォルダに拡張子を"filename.9.png"としてインタレース無しで別名保存 | |
fileObj = new File(filePath + '/9patch/' + originalName[0] + '.9.' + originalName[1]); | |
pngOpt = new PNGSaveOptions(); | |
pngOpt.interlaced = false; | |
doc.saveAs(fileObj, pngOpt, true, Extension.LOWERCASE); | |
//元ファイルを保存せずに閉じる | |
doc.close(SaveOptions.DONOTSAVECHANGES); | |
//9patchファイルを開く | |
app.open(fileObj); | |
} | |
changeCanvas(); | |
saveFile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment