Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Photoshop用。CS6/CC確認。選択中のレイヤーを切り出し。レイヤー名がファイル名になります。
/**
* clipCurrentLayer
* レイヤー切り出し
*
* @version 0.1.1
* @author sacrifs
*/
preferences.rulerUnits = Units.PIXELS;
var ADOC = activeDocument;
var RESOLUTION = 72;
var W = ADOC.width;
var H = ADOC.height;
//処理
main();
/**
* メイン処理
*/
function main(){
cliplayer(ADOC.activeLayer);
}
/**
* レイヤを切り抜き
* @param layer:Layer
*
*/
function cliplayer(layer){
var b = layer.bounds;
var x1 = parseInt(b[0], 10);
var y1 = parseInt(b[1], 10);
var x2 = parseInt(b[2], 10);
var y2 = parseInt(b[3], 10);
try{
var name = layer.name;
var newDoc = documents.add(W, H, RESOLUTION, name, NewDocumentMode.RGB, DocumentFill.TRANSPARENT);
activeDocument = ADOC;
layer.duplicate(newDoc);
activeDocument = newDoc;
newDoc.crop([x1,y1,x2,y2]);
}
catch(err){
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.