안드로이드 앱 제작시 사용될 화면 밀도별 이미지 리소스들을 한 번에 리사이즈해서 각각의 폴더에 내보내기를 실행하는 스크립트입니다.
포토샵 및 일러스트레이터에서 파일 > 스크립트 메뉴를 통해 실행할 수 있으며, CS6 버전에서 테스트되었습니다.
http://www.roundrect.kr/desktop/multi-density-export/
아래 코드의 WORK_FOLDER에 지정된 경로를 작업 환경에 맞게 사용자가 미리 수정해야 합니다. 또한, 해당 폴더 아래에 drawable_mdpi, drawable_hdpi등 출력 파일들이 저장될 폴더들도 미리 만들어 두어야 합니다.
실행시 사용자에게 mdpi로 출력할 이미지의 가로 픽셀 크기를 물어봅니다. 이 값을 기준으로 각각의 화면 밀도에 맞게 리사이즈 됩니다. 출력될 파일명은 현재 활성화된 레이어의 이름을 사용합니다.
- /*
- * 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();
-
- var targetWidth = prompt( 'Output pixel width for mdpi', 48 );
-
- // this is the main loop,
- for (var i=0; i<DENSITIES.length; i++) {
- var scale = targetWidth * DENSITIES[i].scaleFactor / getDocumentWidth();
- exportFileAsPNG24(WORK_FOLDER + DENSITIES[i].folder + PATH_SEPARATOR + 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 );
- }
- }
-
- // End of File
댓글
댓글 쓰기