iPhone Asset Export

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Kukurykus, Tom, xbytor


iPhone Asset Export

Post by mycort »

I have this Android asset export script that works really great. You take a psd file with slices and it will make all 4 different asset types in separate folders.

Is it possible to add an iPhone export function in this same script? Pretty much handles both Anriod and iphone assets all at once? The iphone would make a folder and export 2 file types of normal and @2x versions........

Code: Select all// Output Android Assets.jsx
// 2012 Todd Linkner
// License: none (public domain)
// v1.0
// This scrip is for Photoshop CS6. It outputs Android XHDPI, HDPI, MDPI,
// and LDPI PNG assets from HDPI source files. The resulting PNGs will be
// placed in sub-folders within your target folder.
<name>$$$/JavaScripts/OutputAndroidAssets/MenuAlt=Output Android Assets</name>
// bring Photoshop into focus
#target Photoshop CS6
function main() {
/*var cleanup = confirm("This script outputs Android XHDPI, HDPI, MDPI, "
+ "and LDPI PNG assets from HDPI source files.\r\r"
+ "Do you want to delete your original files when "
+ "complete?");*/

// Ask user for input folder
var inputFolder = Folder.selectDialog("Select a folder to process");
if (inputFolder == null) throw "No folder selected. Exting script.";
// get all files in the input folder
var fileList = inputFolder.getFiles("*.psd");
// Make output folders
var dirxhdpi = Folder(inputFolder+"/drawable-xhdpi");
if(!dirxhdpi.exists) dirxhdpi.create();
var dirhdpi = Folder(inputFolder+"/drawable-hdpi");
if(!dirhdpi.exists) dirhdpi.create();
var dirmdpi = Folder(inputFolder+"/drawable-mdpi");
if(!dirmdpi.exists) dirmdpi.create();
var dirldpi = Folder(inputFolder+"/drawable-ldpi");
if(!dirldpi.exists) dirldpi.create();
// Open each file in turn
for (var i = 0; i < fileList.length; i++) {
// Open file
// Make XHDPI
// Make HDPI
// Make MDPI
// Close and do not save
// Make LDPI
// Delete the original
/*if (cleanup) fileList.remove();*/
function resize(dir,percent) {
// Setup file name
var fname = app.activeDocument.name.replace(/\s+/g, '_').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase();
// Set export options
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.transparency = true;
opts.interlaced = 0;
opts.includeProfile = false;
opts.optimized = true;
// Duplicate, resize and export
var tempfile = app.activeDocument.duplicate();
if (undefined != percent) tempfile.resizeImage(percent,percent);
file = new File(dir+"/"+fname);
tempfile.exportDocument(file, ExportType.SAVEFORWEB, opts);

Posts: 1
Joined: Thu May 27, 2021 8:58 am

Re: iPhone Asset Export

Post by billyjhnson »

if this script only works for android then what about iPhone?

Check this gbwhatsapp