Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ A Photoshop script for exporting assets for Android projects.

The script works by duplicating the selected layer (or layergroup) to a new document, then scaling it to each of the 5 most common Android sizes (XXXHDPI, XXHDPI, XHDPI, HDPI, and MDPI) and then placing the files inside a folder next to the PSD.

After starting the script you are asked for giving a qualifier to your export.
- The qulifier list is here: https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules
- If you choose "port" as example , for the xhdpi resuoltion the forlder name will be "drawable-port-xhdpi"


## Installation
1. Download the script here

2. Move the **.jsx** file to your Photoshop scripts folder:

- Mac: **/Applications/Adobe Photoshop.../Presets/Scripts/**
- PC 64bit: **C:\Program Files\Adobe\Adobe Photoshop... (64 Bit)\Presets\Scripts\**
- PC 32bit: **C:\Program Files\Adobe\Adobe Photoshop...\Presets\Scripts\**
- PC 32bit: **C:\Program Files\Adobe\Adobe Photoshop...\Presets\Scripts\**

21 changes: 16 additions & 5 deletions us-android-export.jsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ init();

function init() {

var qualifier = prompt('Enter qualifier names ( land , port , etc) . Leave empty for normal qualifier.')


// save current ruler unit settings, so we can restore it
var ru = app.preferences.rulerUnits;

Expand All @@ -51,7 +54,7 @@ function init() {

if(!isDocumentNew()) {
for(resolution in resolutionsObj) {
saveFunc(resolution);
saveFunc(resolution,qualifier);
}
} else {
alert("Please save your document before running this script.");
Expand Down Expand Up @@ -139,22 +142,30 @@ function dupToNewFile() {
// Center the layer
activeLayer2.translate(-activeLayer2.bounds[0],-activeLayer2.bounds[1]);
}

function saveFunc(resolution) {
/*
* resolution: the target resolution
* qualifier: the quallifiler to add in the forlder name:
* Qulifier list : https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules
* Example: If qualifier is "port"> export forlder name will be "drawable-port-xhdpi'
*/
function saveFunc(resolution,qualifier) {
dupToNewFile();

var tempDoc = app.activeDocument;

resizeDoc(tempDoc, resolution);


var tempDocName = tempDoc.name.replace(/\.[^\.]+$/, ''),
docFolder = Folder(docPath + '/' + docName + '-assets/' + 'drawable-' + resolution);

if(qualifier!=undefined && qualifier.length>0){
tempDocName = tempDoc.name.replace(/\.[^\.]+$/, ''),
docFolder = Folder(docPath + '/' + docName + '-assets/' + 'drawable-'+qualifier+'-' + resolution);
}
if(!docFolder.exists) {
docFolder.create();
}

alert(docFolder);

var saveFile = File(docFolder + "/" + tempDocName + ".png");

Expand Down