ãåºæ¬æ©è½ã
Photoshopã®ã¹ã¯ãªããã使ã£ã¦ããã©ã«ãå
ã®ãã¡ã¤ã«ãä¸æ¬å¤æãã¾ãã
èªã¿è¾¼ãããã¡ã¤ã«ï¼å¤æåã®ãã¡ã¤ã«ï¼ã¯ãã©ã«ãå
ã®å
¨ãã¡ã¤ã«ããããã¯æ¡å¼µåã§æå®ãããã¡ã¤ã«ã«å¶éãããã¨ãã§ãã¾ãã
åºåè¨å®ã¯psdãjpgãpngã®3å½¢å¼ã«å¯¾å¿ãã¦ãã¾ãã
ãã¹ã¯ãªããã®æºåã
ã½ã¼ã¹ã«è¨è¿°ããã¹ã¯ãªãããããã¹ããã¡ã¤ã«ã«è²¼ãä»ãããã¡ã¤ã«åãããã¡ã¤ã«å¤æ.jsxãã¨ãã¦ä¿åãã¾ãã
ãpsd→jpgå¤æ.jsxãã¨ãã¦ãåãããããã§ããæ¡å¼µåããå¤æ´ããªããã°ããã¡ã¤ã«åã¯èªç±ã«ä»ãã¦ãã ããã
Photoshopãå
¥ã£ã¦ããªãã¨èµ·åãã¾ããã
ãèµ·åæ¹æ³ã
ãã®ï¼ï¼ã¹ã¯ãªãããå¼ã³åºãã¦ããéããã¤ã¢ãã°ã§ãã©ã«ããé¸æãã¾ãã
ãã®ï¼ï¼å¦çããããã©ã«ãã«ãããã¡ã¤ã«ãï¼ã¤éãã¦ããã¹ã¯ãªãããå®è¡ããã¨ããã®ãã©ã«ããé¸æãããã¨ã«ãªãã¾ãã
ãè¨å®å¤æ´ã
ç¾å¨ã¯PSDå½¢å¼ããJPEGå½¢å¼ã¸ã®å¤æè¨å®ã«ãªã£ã¦ãã¾ãã
fe1ã¨fe2ãå¤æ´ãããã¨ã§å¦çãã¡ã¤ã«ã®å¯¾è±¡ãå¤æ´ã§ãã¾ãããã®ä»ãåºåã®ç´°ããªè¨å®ã¯ãä¿åãªãã·ã§ã³ã®è¨å®ãã§è¡ã£ã¦ãã ããã
ãã½ã¼ã¹ã
//ãã¡ã¤ã«å¤æ
#target photoshop
//è¨å®é
ç®(psd,jpg,png)
fileExp = new Array("*","psd","jpg","png");
fe1 = 1; //å¤æåã®æ¡å¼µå
fe2 = 2; //å¤æå¾ã®æ¡å¼µå
//ä¿åãªãã·ã§ã³ã®è¨å®
if (fe2 == 1) {
//PSD
var saveOpt = new PhotoshopSaveOptions;
saveOpt.alphaChannels = true; //αãã£ã³ãã«ãä¿å
saveOpt.annotations = true; //注é
saveOpt.embedColorProfile = true; //ã«ã©ã¼ãããã¡ã¤ã«ãä¿å
saveOpt.layers = true; //ã¬ã¤ã¤ã¼ä¿å
saveOpt.spotColors = true; //ã¹ãããã«ã©ã¼ä¿å
} else if (fe2 == 2) {
//JPEG
var saveOpt = new JPEGSaveOptions();
saveOpt.embedColorProfile = true; //ã«ã©ã¼ãããã¡ã¤ã«ãä¿å
saveOpt.quality = 10; //å質ï¼0ï½12ï¼12ãæé«ç»è³ªï¼
saveOpt.formatOptions = FormatOptions.STANDARDBASELINE //ãã¼ã¹ã©ã¤ã³ï¼æ¨æºï¼
//saveOpt.formatOptions = FormatOptions.OPTIMIZEDBASELINE; //ãã¼ã¹ã©ã¤ã³ï¼æé©åï¼
//saveOpt.formatOptions = FormatOptions.PROGRESSIVE; //ããã°ã¬ãã·ã
//saveOpt.scans = 3; //ããã°ã¬ãã·ãæã®ã¹ãã£ã³æ°ï¼3ï½5
saveOpt.matte = MatteType.NONE;
} else if (fe2 == 3) {
//PNG
saveOpt = new PNGSaveOptions();
saveOpt.interlaced = false; //ã¤ã³ã¿ã¼ã¬ã¼ã¹
}
selFolder();
//ãã©ã«ããé¸æ
function selFolder() {
var n = documents.length; //éãã¦ãããã¼ã¿ã®æ°
if (n > 0) {
//ã¢ã¯ãã£ãããã¥ã¡ã³ãã®ãã¹ãåå¾
var folderPath = activeDocument.path;
var folderObj = new Folder(folderPath);
} else {
//ãã¤ã¢ãã°ã®è¡¨ç¤º
var folderObj = Folder.selectDialog("ãã©ã«ããé¸æãã¦ãã ããã");
}
//ãã©ã«ãã®ç¢ºèª
if (folderObj) {
//å
¨ã¦ã®ãã¡ã¤ã«
fileList = folderObj.getFiles("*." + fileExp[fe1]); //ãã¡ã¤ã«ã¯ã¢ã«ãã¡ãããé ã«ãªã£ã¦ãã
//alert(fileList.length+"åã®ãã¡ã¤ã«ãããã¾ã");
//ãã©ã«ãåããã³ã¼ã
pathName = decodeURIComponent(folderObj.name);
//ãã¡ã¤ã«æ°ã®åå¾
edPage = fileList.length;
//ãã¡ã¤ã«æ°ã®ç¢ºèª
if (edPage > 0) {
//éå§ãã¡ã¤ã«ã¨çµäºãã¡ã¤ã«
stPage = 1;
stFile = decodeURI(fileList[stPage-1].name);
edFile = decodeURI(fileList[edPage-1].name);
//ãã¤ã¢ãã°åæå
var newDialog = new createDialog_DLG();
initializeBuilder(newDialog);
//å¦çãããã¡ã¤ã«åã®ãªã¹ã
text_fileNames = "";
//ãã¤ã¢ãã°è¡¨ç¤º
if(runBuilder(newDialog)){
with(newDialog){
//ãã¼ã¸çªå·åå¾
//stPage = parseInt(pnl.start_page.text,10);
//edPage =parseInt(pnl.end_page.text,10);
}
for (var i=stPage-1; i < fileList.length; i++) {
var doc = fileList[i];
//ãã¡ã¤ã«ãéã
open(doc);
//ã«ã©ã¼ã¢ã¼ã確èª
fileConvert(doc);
}
}
//çµæå ±å
if (text_fileNames != "") {
alert(text_fileNames);
}
} else {
alert("å¦ç対象ã®ãã¡ã¤ã«ãè¦ã¤ããã¾ããã");
}
}
}
//ãã¤ã¢ãã°ï¼ä¸æ¬å¤æå¦çï¼
function createDialog_DLG(){
var dialogResource = "dialog { text:'ä¸æ¬å¤æå¦ç', bounds:[0, 0, 260, 200], ";
dialogResource += " pnl: Panel { text:'ãã©ã«ãæ
å ±', bounds:[15, 8, 245, 136], ";
dialogResource += " str: StaticText { text:'ãã©ã«ãï¼', bounds:[10, 23, 90, 36], }, ";
dialogResource += " str: StaticText { text:'" + pathName + "', bounds:[60, 23, 220, 41], }, ";
dialogResource += " start_file: StaticText { text:'" + stFile + "', bounds:[110, 57, 220, 70], }, ";
dialogResource += " str: StaticText { text:'éå§ï¼', bounds:[20, 57, 90, 70], }, ";
dialogResource += " start_page: EditText { bounds:[60, 57, 100, 75], }, ";
dialogResource += " end_file: StaticText { text:'" + edFile + "', bounds:[110, 90, 220, 103], }, ";
dialogResource += " str: StaticText { text:'çµäºï¼', bounds:[20, 90, 90, 103], }, ";
dialogResource += " end_page: EditText { bounds:[60, 90, 100, 108], }, ";
dialogResource += " }," ;
dialogResource += " cancel: Button { text:'ãã£ã³ã»ã«', bounds:[50, 158, 112, 182], }, ";
dialogResource += " running: Button { text:'å®è¡', bounds:[150, 158, 212, 182], }, ";
dialogResource += " }";
var dlg = new Window( dialogResource );
dlg.center();
return dlg;
}
// ãã¤ã¢ãã°ï¼åä½è¨å®ï¼=============================
function initializeBuilder(builder){
with(builder){
//ãã¼ã¸çªå·ãã§ãã¯
function pageCheck() {
stPage = parseInt(pnl.start_page.text,10)
edPage = parseInt(pnl.end_page.text,10);
//æ°å¤ä»¥å¤ã®å ´å
if (isNaN(stPage)) {stPage = 1;}
if (isNaN(edPage)) {edPage = fileList.length;}
//大å°ãéã®å ´åãå
¥ãæ¿ã
if (stPage > edPage) {
var n = stPage;
stPage = edPage;
edPage = n;
}
//æå°å¤ã¨æ大å¤
if (stPage < 1) {stPage = 1;}
if (edPage > fileList.length) {edPage = fileList.length;}
//表示å¤æ´
pnl.start_page.text = stPage;
pnl.end_page.text = edPage;
pnl.start_file.text = decodeURI(fileList[stPage-1].name);
pnl.end_file.text = decodeURI(fileList[edPage-1].name);
}
//åæå¤
pnl.start_page.text = stPage;
pnl.end_page.text = edPage;
//ãã¿ã³ã¤ãã³ã
cancel.onClick = function(){ this.parent.close( false ); };
running.onClick = function(){ this.parent.close( true ); };
//ãã¡ã¤ã«åå¤æ´
pnl.start_page.onChange = function() {pageCheck();};
pnl.end_page.onChange = function() {pageCheck();};
}
}
// ãã¤ã¢ãã°ï¼èµ·åã»å®è¡ï¼===================================================
function runBuilder(builder){
return builder.show();
}
function fileConvert(builder) {
//ã¢ã¯ãã£ãããã¥ã¡ã³ããåå¾
var doc = activeDocument;
//ãã¹åå¾
var docPath = doc.fullName.fsName.toString();
docPath = docPath.substring(0,docPath.lastIndexOf("\\")+1);
//alert(docPath);
//ãã¡ã¤ã«ååå¾
var docOldName = doc.name;
var docName = docOldName.substring(0,docOldName.lastIndexOf("."));
//å
ãã¼ã¿ã2é調ã®å ´å
if ((fe2 == 1) || (fe2 == 2)) {
if (doc.mode == DocumentMode.BITMAP) {
doc.changeMode(ChangeMode.GRAYSCALE);
}
}
//å¥åä¿åã®è¨å®
var docNewName = docName + "." + fileExp[fe2]
var saveFileObj = new File(docPath + docNewName);
//å¥åã§ä¿å
try {
activeDocument.saveAs(saveFileObj, saveOpt, true, Extension.LOWERCASE);
//è¨é²
text_fileNames += docOldName + " → " + docNewName + "\n";
//ãã¡ã¤ã«ãéãã
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
} catch(msg) {
alert(msg + " Can't save it.");
}
}
â»ã³ã¡ã³ãæ稿è ã®ããã°IDã¯ããã°ä½æè ã®ã¿ã«éç¥ããã¾ã