콘텐츠로 건너뛰기
Home » 일러스트레이터 자동화 스크립트 – .ai 파일을 JPG로 일괄 변환

일러스트레이터 자동화 스크립트 – .ai 파일을 JPG로 일괄 변환

요즘 일러스트레이터 버전에서는 이런게 지원되는지 모르겠는데, 간혹 필요하시다는 분들이 있어서 다시 올립니다.  특정한 폴더 내의 모든 일러스트레이터 파일을 자동으로  JPG로 변환하여 다른 폴더에 저장해주는 스크립트입니다.

파일 다운로드 링크 : https://app.box.com/s/nefi9wjejb2jnsgfsh848abmiog7hvqz

사용방법

  1. 다운로드 받은 파일을 압축을 풀어둡니다.
  2. 일러스트레이터를 실행합니다.
  3. File > Script > Other Scripts… 를 선택하여 압축을 풀어서 나온 스크립트 선택
  4. 원본 .ai 파일들이 들어있는 폴더를 묻는 대화상자가 나옵니다. 원본 파일 폴더를 선택합니다.
  5. jpg 파일을 저장할 폴더를 묻는 대화상자가 나옵니다. 대상 폴더를 선택합니다.
  6. 자동으로 한 개씩 파일이 열리며 jpg 파일로 저장합니다. 저장되는 파일 이름은 원본 파일과 같은 대신에 .jpg 로 끝나게 됩니다.

예전에 작성했던 코드가 워낙에 엉망이어서 정리를 좀 했고,원본 파일명에 한글 등이 들어있는 경우에 경고 박스가 뜨면서 동작이 중지되는 문제를 해결했습니다.
참고로 실행중에는 상당히 많은 메모리를 쓰는데, 이 때 일러스트레이터를 최소화 시키면 메모리 부족으로 중단될 수 있습니다.그리고 원본 파일이 1000개를 넘는 경우에 중간에 일러스트레이터가 자동으로 꺼졌다가 재시작할 수 있습니다.
아래는 소스코드.


// 지정한 폴더내의 모든 .ai 파일을 JPG 파일로 변환하여 일괄 저장한다.
// coded by sooop – 2017.07.12
// 파일이름에 한글이 들어있더라도 경고를 표시하지 않는다.
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
main();
function main(){
var sourceFiles = getSourceFiles();
if(sourceFiles != null){
var targetFolder = Folder.selectDialog("Select destination folder", new Folder('C:/'));
for(var i=0; i<sourceFiles.length; i++){
processFile(sourceFiles[i], targetFolder);
}
}
}
// 원본폴더로부터 처리할 파일의 배열을 리턴하는 함수
function getSourceFiles(){
var sourceFolder = Folder.selectDialog("Select source folder", new Folder('C:/')); // 폴더 지정 대화상자
if(sourceFolder != null){
var sfiles = sourceFolder.getFiles("*.ai");
if(sfiles != null && sfiles.length > 0){
alert(sfiles.length + " AI files found"); // ai 파일의 갯수를 보고한다.
return sfiles;
}
else{
alert("No AI file found. Process canceled."); //ai 파일이 없으면 장난치냐며 작업 종료.
}
}
return null;
}
// 파일 하나를 처리하는 함수
function processFile(aFile, destinationFolder) {
if(destinationFolder == undefined){
destinationFolder = Folder.selectDialog("Select destination folder", new Folder('C:/'));
}
var currentDoc = app.open(aFile, DocumentColorSpace.RGB);
var savingOptions = (function (){
var opts = new ExportOptionsJPEG();
opts.antiAliasing = true; //안티앨리어싱 적용
opts.artBoardClipping = false; //대지에 맞게 자르기 안함
opts.blurAmount = 0.0; //블러 없음
opts.qualitySetting = 100; //퀄리티는 100으로 (기본값이 30)
//opts.horizontalScale = 100; //가로크기지정
//opts.verticalScale = 100; //세로크기지정
return opts;
})();
var targetFile = makeFilePath(currentDoc.name, destinationFolder)
currentDoc.exportFile(targetFile, ExportType.JPEG, savingOptions);
currentDoc.close(SaveOptions.DONOTSAVECHANGES);
}
function makeFilePath(title, path){ //문서의 이름과 목적폴더를 파라메터로 받음
var newName = title.substring(0,title.lastIndexOf('.')) + '.jpg';
return new File(path + '/' + newName);
}