Multiple Density Export: A Script For Photoshop & Illustrator


간단하지만 강력한 포토샵 / 일러스트레이터용 스크립트입니다.
안드로이드 어플리케이션의 개발에 사용되는 보조 도구이며, 단 한 번의 실행만으로
포토샵 또는 일러스트레이터의 작업 파일로부터 각각의 화면 밀도별로 다양한 크기로 리사이즈해서
이미지 파일로 출력하는 포토샵 및 일러스트레이터용 스크립트 파일입니다. 포토샵 및 일러스트레이터 CS 6에서 테스트 되었습니다.
궁금하신 사항은 블로그를 통해 알려주세요.
- 일괄 처리
- 단 한번의 실행만으로 화면 밀도에 따른 다양한 크기의 이미지들을 출력할 수 있습니다.
- 최소화된 사용자 입력
- mdpi로 출력될 이미지의 크기 하나만 물어 봅니다. 나머지는 스크립트 내에 모두 정의되어 있습니다.
- 포토샵 & 일러스트레이터
- 하나의 스크립트 파일로 포토샵과 일러스트레이터 모두에서 실행할 수 있습니다.
- 무료!
- 이 스크립트는 무료로 제공됩니다. 사용자는 기부를 통해 이 소프트웨어의 제작을 후원할 수 있습니다.
사용법
파일을 다운로드 받아서 컴퓨터에 저장해 둡니다. 실행하기 전에 스크립트를 수정할 필요가 있습니다.
먼저, 'WORK_FOLDER' 변수의 값을 작업 폴더의 경로명으로 수정합니다.
만일, 작업 폴더 및 'drawable-mdpi', 'drawable-hdpi' 등의 폴더들이
존재하지 않으면 해당 위치에 자동으로 생성됩니다.
만일, 윈도우즈 OS에서 실행하는 경우가 아니라면, 파일 경로 구분자도 수정해야 합니다.
스크립트는 다음과 같은 방식으로 실행할 수 있습니다.
포토샵에서, File > Scripts > Browse...
일러스트레이터에서, File > Scripts > Other script
또는, 포토샵 /
일러스트레이터의
메뉴에 추가해서 실행하는 방법도 있습니다.
활성 레이어 이름을 출력 파일의 이름으로 사용하므로, 원하는 레이어가 선택되어 있고 이름이 적절히 지정되어 있는지 확인해야 합니다.
스크립트가 출력 파일의 크기를 물어보면, mdpi로 출력할 이미지의 가로 픽셀 크기를 입력합니다.
multiDensityExportForAndroid.jsx
/* * multiDensityExportForAndroid.jsx * * Copyright (c) 2014. RoundRect Co.,Pte. * Author: Elex * http://www.roundrect.kr/desktop/multi-density-export/ * * licensed under a Creative Commons BY-NC-SA * http://creativecommons.org/licenses/by-nc-sa/4.0/ * * This script file is to export resized files for multiple densities in a single process * from Adobe Photoshop and/or Illustrator mainly for Android application development. * It's been tested with both Adobe Photoshop CS 6 and Adobe Illustrator CS 6. * * * Before running this script, users must edit the variable 'WORK_FOLDER' * to their preferred working folder name first. And also, users have to * make child folders such as 'drawable-mdpi', 'drawable-hdpi', etc. * under the work folder. * If you're not running this script on Windows OS, * please check the file path separator too. * * The script can be run by * [In Photoshop] File > Scripts > Browse... * [In Illustrator] File > Scripts > Other script * Or, you can google for some documents about * adding a script as a menu item on Photoshop/Illustrator. * * The active layer's name is used as an output file name, * so please check the layer is activated and its name is properly set. * * When prompted to ask you an output size, * type a width of a mdpi image in pixel. * * If it's useful to you, please donate and support further developments. * https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LXC8U85PSUZL8 * */ // app's name var PHOTOSHOP = "Adobe Photoshop"; var ILLUSTRATOR = "Adobe Illustrator"; // users can comment a line for an unwanted density. var DENSITIES = [ {"name":"LDPI", "scaleFactor":0.75, "folder":"drawable-ldpi"}, {"name":"MDPI", "scaleFactor":1.0, "folder":"drawable-mdpi"}, {"name":"HDPI", "scaleFactor":1.5, "folder":"drawable-hdpi"}, {"name":"XHDPI", "scaleFactor":2.0, "folder":"drawable-xhdpi"}, {"name":"XXHDPI", "scaleFactor":3.0, "folder":"drawable-xxhdpi"}, {"name":"XXXHDPI", "scaleFactor":4.0, "folder":"drawable-xxxhdpi"} ]; // users have to edit this to match with their OS var PATH_SEPARATOR = "\\"; // users must edit following line to their work folder path. // this should be ended with a path separator. var WORK_FOLDER = "D:\\work\\res\\"; // if you prefer to use a folder picker dialog, uncomment following line. // WORK_FOLDER = pickWorkFolder(); mkdir(WORK_FOLDER); var targetWidth = prompt( 'Output pixel width for mdpi', 48 ); // this is the main loop, // (@2014-4-21) a folder will be created if it does not exist for (var i=0; i<DENSITIES.length; i++) { var scale = targetWidth * DENSITIES[i].scaleFactor / getDocumentWidth(); var folder = WORK_FOLDER + DENSITIES[i].folder + PATH_SEPARATOR; mkdir(folder); exportFileAsPNG24(folder + getActiveLayerName(), scale); } // this function is the core part of this script, // users can edit some output options to their preference function exportFileAsPNG24 (outFileName, scale) { if (app.name == PHOTOSHOP) { var exportOptions = new ExportOptionsSaveForWeb(); var type = ExportType.SAVEFORWEB; var outFile = new File(outFileName + ".png"); exportOptions.format = SaveDocumentType.PNG; exportOptions.PNG8 = false; exportOptions.transparency = true; exportOptions.includeProfile = false; exportOptions.interlaced = false; var copyDoc = app.activeDocument.duplicate(); var width = copyDoc.width.as("px") * scale; var height = copyDoc.height.as("px") * scale; copyDoc.resizeImage(width, height, copyDoc.resolution, ResampleMethod.BICUBIC); copyDoc.exportDocument(outFile, type, exportOptions); copyDoc.close(SaveOptions.DONOTSAVECHANGES); } else if (app.name == ILLUSTRATOR) { var exportOptions = new ExportOptionsPNG24(); var type = ExportType.PNG24; var outFile = new File(outFileName); exportOptions.antiAliasing = true; exportOptions.artBoardClipping = true; exportOptions.transparency = true; exportOptions.saveAsHTML = false; exportOptions.matte = false; exportOptions.horizontalScale = scale * 100; exportOptions.verticalScale = scale * 100; app.activeDocument.exportFile( outFile, type, exportOptions ); } } // name of current layer function getActiveLayerName(){ return app.activeDocument.activeLayer.name; } // document size(width) of current document function getDocumentWidth() { if (app.name == PHOTOSHOP) { return app.activeDocument.width.as("px"); } else if (app.name == ILLUSTRATOR) { return app.activeDocument.width; } } // folder chooser dialog function pickWorkFolder() { if (app.name == PHOTOSHOP) { var folder = new Folder(app.activeDocument.path); return folder.selectDlg( 'Pick a folder for output', app.activeDocument.path ); } else if (app.name == ILLUSTRATOR) { return Folder.selectDialog( 'Pick a folder for output', app.activeDocument.path ); } } // create a folder if exists not // (@2014-4-21) function mkdir(folder){ var dir = new Folder(folder); if (!dir.exists) { dir.create(); } } // End of file