//#target photoshop
function copyDoc(toDoc, fromDoc){
app.activeDocument=fromDoc;
/*如果背景不存在,則標記左上角的 1px*/
if(!fromDoc.backgroundLayer){
var white = new SolidColor();
white.rgb.hexValue = 'FFFFFF';
art.selection.select([ [1,0],[1,1],[0,1],[0,0],[1,0] ]);
art.selection.fill(white, ColorBlendMode.NORMAL, 1);// 填滿
}
//複製圖層
fromDoc.selection.selectAll()
fromDoc.selection.copy()
//貼上圖層
app.activeDocument=toDoc;
return toDoc.paste();
}
function main(){
/*取得多個的檔案路徑*/
var filePathList = File.openDialog("開啟圖檔","*",true);
if(filePathList.length == 0){return;}
//新增 Temp 文件
var newDoc = app.documents.add(
1, 1, 72,
"temp",
NewDocumentMode.RGB,
DocumentFill.TRANSPARENT
);
var maxWidth=1, maxHeight=1;
var filePath, i=0;
while(filePath=filePathList[i++]){
/*開啟圖檔*/
try {
var atDoc=open(new File(filePath));
} catch (e) { continue; }
/*最大高度&寬度*/
if(maxWidth<atDoc.width){ maxWidth=atDoc.width;}
if(maxHeight<atDoc.height){ maxHeight=atDoc.height;}
/*複製檔案*/
copyDoc(newDoc, atDoc);
/*關閉檔案*/
atDoc.close(SaveOptions.DONOTSAVECHANGES);
}
/*變更圖片尺寸*/
app.activeDocument=newDoc;
newDoc.resizeCanvas(maxWidth, maxHeight, AnchorPosition.TOPLEFT);
}
//把Photoshop推到最上層
app.bringToFront();
//設定使用的單位為「像素(Pixel)」
app.preferences.rulerUnits = Units.PIXELS;
//執行主程式
main();
2011-04-06 13:03
[JSX] 開啟檔案到圖層
這個程式會將選取的圖檔開啟,並全部複製到一個新的圖片文件中。
相關文章 :
訂閱:
張貼留言 (Atom)
0 回應:
張貼留言