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

mycort

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.
 
/*
// BEGIN__HARVEST_EXCEPTION_ZSTRING
<javascriptresource>
<name>$$$/JavaScripts/OutputAndroidAssets/MenuAlt=Output Android Assets</name>
<category>mobile</category>
</javascriptresource>
// END__HARVEST_EXCEPTION_ZSTRING
*/
 
// bring Photoshop into focus
#target Photoshop CS6
 
main();
 
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
open(fileList);
// Make XHDPI
resize(dirxhdpi);
// Make HDPI
resize(dirhdpi,'75%');
// Make MDPI
resize(dirmdpi,'50%');
// Close and do not save
// Make LDPI
resize(dirldpi,'37.5%');
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// Delete the original
/*if (cleanup) fileList.remove();*/
}
alert("Done!");
}
 
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);
tempfile.close(SaveOptions.DONOTSAVECHANGES);
}

billyjhnson
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