multiDensityExportForAndroid.jsx

안드로이드 앱 제작시 사용될 화면 밀도별 이미지 리소스들을 한 번에 리사이즈해서 각각의 폴더에 내보내기를 실행하는 스크립트입니다.
포토샵 및 일러스트레이터에서 파일 > 스크립트 메뉴를 통해 실행할 수 있으며, CS6 버전에서 테스트되었습니다.
http://www.roundrect.kr/desktop/multi-density-export/
아래 코드의 WORK_FOLDER에 지정된 경로를 작업 환경에 맞게 사용자가 미리 수정해야 합니다. 또한, 해당 폴더 아래에 drawable_mdpi, drawable_hdpi등 출력 파일들이 저장될 폴더들도 미리 만들어 두어야 합니다.
실행시 사용자에게 mdpi로 출력할 이미지의 가로 픽셀 크기를 물어봅니다. 이 값을 기준으로 각각의 화면 밀도에 맞게 리사이즈 됩니다. 출력될 파일명은 현재 활성화된 레이어의 이름을 사용합니다.


  1. /*
  2. * multiDensityExportForAndroid.jsx
  3. *
  4. * Copyright (c) 2014. RoundRect Co.,Pte.
  5. * Author: Elex
  6. * http://www.roundrect.kr/desktop/multi-density-export/
  7. *
  8. * licensed under a Creative Commons BY-NC-SA
  9. * http://creativecommons.org/licenses/by-nc-sa/4.0/
  10. *
  11. * This script file is to export resized files for multiple densities in a single process
  12. * from Adobe Photoshop and/or Illustrator mainly for Android application development.
  13. * It's been tested with both Adobe Photoshop CS 6 and Adobe Illustrator CS 6.
  14. *
  15. *
  16. * Before running this script, users must edit the variable 'WORK_FOLDER'
  17. * to their preferred working folder name first. And also, users have to
  18. * make child folders such as 'drawable-mdpi', 'drawable-hdpi', etc.
  19. * under the work folder.
  20. * If you're not running this script on Windows OS,
  21. * please check the file path separator too.
  22. *
  23. * The script can be run by
  24. * [In Photoshop] File > Scripts > Browse...
  25. * [In Illustrator] File > Scripts > Other script
  26. * Or, you can google for some documents about
  27. * adding a script as a menu item on Photoshop/Illustrator.
  28. *
  29. * The active layer's name is used as an output file name,
  30. * so please check the layer is activated and its name is properly set.
  31. *
  32. * When prompted to ask you an output size,
  33. * type a width of a mdpi image in pixel.
  34. *
  35. * If it's useful to you, please donate and support further developments.
  36. * https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LXC8U85PSUZL8
  37. *
  38. */
  39.  
  40. // app's name
  41. var PHOTOSHOP = "Adobe Photoshop";
  42. var ILLUSTRATOR = "Adobe Illustrator";
  43.  
  44. // users can comment a line for an unwanted density.
  45. var DENSITIES = [
  46. {"name":"LDPI", "scaleFactor":0.75, "folder":"drawable-ldpi"},
  47. {"name":"MDPI", "scaleFactor":1.0, "folder":"drawable-mdpi"},
  48. {"name":"HDPI", "scaleFactor":1.5, "folder":"drawable-hdpi"},
  49. {"name":"XHDPI", "scaleFactor":2.0, "folder":"drawable-xhdpi"},
  50. {"name":"XXHDPI", "scaleFactor":3.0, "folder":"drawable-xxhdpi"},
  51. {"name":"XXXHDPI", "scaleFactor":4.0, "folder":"drawable-xxxhdpi"}
  52. ];
  53.  
  54. // users have to edit this to match with their OS
  55. var PATH_SEPARATOR = "\\";
  56.  
  57. // users must edit following line to their work folder path.
  58. // this should be ended with a path separator.
  59. var WORK_FOLDER = "D:\\work\\res\\";
  60. // if you prefer to use a folder picker dialog, uncomment following line.
  61. // WORK_FOLDER = pickWorkFolder();
  62.  
  63. var targetWidth = prompt( 'Output pixel width for mdpi', 48 );
  64.  
  65. // this is the main loop,
  66. for (var i=0; i<DENSITIES.length; i++) {
  67. var scale = targetWidth * DENSITIES[i].scaleFactor / getDocumentWidth();
  68. exportFileAsPNG24(WORK_FOLDER + DENSITIES[i].folder + PATH_SEPARATOR + getActiveLayerName(), scale);
  69. }
  70.  
  71. // this function is the core part of this script,
  72. // users can edit some output options to their preference
  73. function exportFileAsPNG24 (outFileName, scale) {
  74. if (app.name == PHOTOSHOP) {
  75. var exportOptions = new ExportOptionsSaveForWeb();
  76. var type = ExportType.SAVEFORWEB;
  77. var outFile = new File(outFileName + ".png");
  78. exportOptions.format = SaveDocumentType.PNG;
  79. exportOptions.PNG8 = false;
  80. exportOptions.transparency = true;
  81. exportOptions.includeProfile = false;
  82. exportOptions.interlaced = false;
  83. var copyDoc = app.activeDocument.duplicate();
  84. var width = copyDoc.width.as("px") * scale;
  85. var height = copyDoc.height.as("px") * scale;
  86. copyDoc.resizeImage(width, height, copyDoc.resolution, ResampleMethod.BICUBIC);
  87. copyDoc.exportDocument(outFile, type, exportOptions);
  88. copyDoc.close(SaveOptions.DONOTSAVECHANGES);
  89. } else if (app.name == ILLUSTRATOR) {
  90. var exportOptions = new ExportOptionsPNG24();
  91. var type = ExportType.PNG24;
  92. var outFile = new File(outFileName);
  93. exportOptions.antiAliasing = true;
  94. exportOptions.artBoardClipping = true;
  95. exportOptions.transparency = true;
  96. exportOptions.saveAsHTML = false;
  97. exportOptions.matte = false;
  98. exportOptions.horizontalScale = scale * 100;
  99. exportOptions.verticalScale = scale * 100;
  100. app.activeDocument.exportFile( outFile, type, exportOptions );
  101. }
  102. }
  103.  
  104. // name of current layer
  105. function getActiveLayerName(){
  106. return app.activeDocument.activeLayer.name;
  107. }
  108.  
  109. // document size(width) of current document
  110. function getDocumentWidth() {
  111. if (app.name == PHOTOSHOP) {
  112. return app.activeDocument.width.as("px");
  113. } else if (app.name == ILLUSTRATOR) {
  114. return app.activeDocument.width;
  115. }
  116. }
  117.  
  118. // folder chooser dialog
  119. function pickWorkFolder() {
  120. if (app.name == PHOTOSHOP) {
  121. var folder = new Folder(app.activeDocument.path);
  122. return folder.selectDlg( 'Pick a folder for output', app.activeDocument.path );
  123. } else if (app.name == ILLUSTRATOR) {
  124. return Folder.selectDialog( 'Pick a folder for output', app.activeDocument.path );
  125. }
  126. }
  127.  
  128. // End of File

댓글

이 블로그의 인기 게시물

자바 암호화 확장 (JCE) 관련 자바 1.8.0_151 이후 변경 사항

좌표 변환: 회전 이동

Apache Commons CSV