Skip to content

Instantly share code, notes, and snippets.

@sacrifs
Last active December 19, 2015 23:49
Show Gist options
  • Save sacrifs/6037195 to your computer and use it in GitHub Desktop.
Save sacrifs/6037195 to your computer and use it in GitHub Desktop.
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