Skip to content

Instantly share code, notes, and snippets.

@sooop
Created July 23, 2013 15:46
Show Gist options
  • Save sooop/43f6fe2eab5c5152d369 to your computer and use it in GitHub Desktop.
Save sooop/43f6fe2eab5c5152d369 to your computer and use it in GitHub Desktop.
convert all .ai files in a folder into jpg files
// Adobe Illustrator Javascript to save multiple ai files into JPEG file.
// code by sooop
var defaultFolder = new Folder('C:/'); // 폴더 선택창에서 디폴트 폴더
var targetFolder = new Folder();
var sourceFiles;
function getSourceFiles() { //폴더를 선택하고 폴더 내의 ai 파일의 목록을 가져온다.
var sourceFolder = Folder.selectDialog("Select folder contains ai files...", defaultFolder);
if(sourceFolder != null) {
var sourceFiles = sourceFolder.getSourceFiles("*.ai");
if(sourceFiles.length) {
alert(sourceFiles.length + " ai files found");
return sourceFiles;
} else {
alert("No ai file found.");
return;
}
} else {
alert("Canceled.");
return;
}
}
function getTarget(aiDocumentName, targetFolderName) {
var newName = "";
var dot = aiDocumentName.lastIndexOf(".");
var ext = ".jpg";
newName = targetFolderName + "/" + aiDocumentName.substring(0, dot) + ext;
var targetFile = new File(newName);
return targetFile;
}
function getJPGOptions() {
var JPGSavingOptions = new ExportOptionsJPEG();
JPGSavingOptions.antiAliasing = true; // 안티앨리어싱 적용
JPGSavingOptions.artBoardClipping = false; // 아트보드 크기게 맞게 자르기 하지 않음
JPGSavingOptions.blurAmount = 0.0; // 블러 효과 적용하지 않음. (적용시 압축효과로 파일 크기가 작아짐)
JPGSavingOptions.qualitySetting = 100; // 이미지 품질은 최대 (기본값은 30, 최대는 100)
JPGSavingOptions.horizontalScale = 100; // 가로, 세로 배율 지정 (%값임)
JPGSavingOptions.verticalScale = 100;
}
sourceFiles = getSourceFiles();
if(sourceFiles) {
targetFolder = Folder.selectDialog("Select folder where JPG files are saved.", defaultFolder);
if(targetFolder) {
/* 파일을 차례로 열어서 JPG로 익스포트 한 다음 저장없이 닫음 */
for(i=0;i<sourceFiles.length;i++) {
var documentRef = app.open(sourceFiles[i]);
var savingOptions = getJPGOptions();
var targetJPGFileRef = getTarget(documentRef.name, targetFolder);
var type = ExportType.JPEG;
documentRef.exportFile(targetJPGFileRef, type, savingOptions);
documentRef.close(SaveOptions.DONOTSAVECHANGES);
documentRef = null;
}
} else {
alert ("No destination folder selected.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment