-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsavepng3x.jsx
54 lines (44 loc) · 1.79 KB
/
savepng3x.jsx
1
var pngName = prompt ("enter file name", "", "")if (pngName) { var docRef = app.activeDocument docRef.selection.selectAll() docRef.selection.copy (true) const iPhone6PlusSize = 2208 // create temporary document with maximum possible design size var newDoc = app.documents.add (iPhone6PlusSize, iPhone6PlusSize, 72, "temp", NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1.0, BitsPerChannelType.EIGHT) newDoc.paste (false) var folderPath = docRef.path+'/export/' var folder = new Folder (folderPath) if (!folder.exists) { folder.create() } var oldUnits = app.preferences.rulerUnits //save settings app.preferences.rulerUnits = Units.PERCENT; const fileExtension = '.png' // 3x var docPath = folderPath + pngName +'@3x' + fileExtension SavePNG(newDoc ,docPath) // 2x const scalePercent3xTo2x = 100.0/1.5 activeDocument.resizeImage(scalePercent3xTo2x, undefined, undefined, ResampleMethod.BICUBIC); docPath = folderPath + pngName +'@2x' + fileExtension SavePNG(newDoc ,docPath) // 1x const scalePercent2xTo1x = 50 activeDocument.resizeImage(scalePercent2xTo1x, undefined, undefined, ResampleMethod.BICUBIC); docPath = folderPath + pngName + fileExtension SavePNG(newDoc ,docPath) app.preferences.rulerUnits = oldUnits; // restore settings newDoc.close (SaveOptions.DONOTSAVECHANGES) }function SavePNG(doc, saveFile){ pngFile = new File(saveFile); doc.trim(TrimType.TRANSPARENT, true , true, true , true) var pngOpts = new ExportOptionsSaveForWeb; pngOpts.format = SaveDocumentType.PNG pngOpts.PNG8 = false; pngOpts.transparency = true; pngOpts.interlaced = false; pngOpts.quality = 100; doc.exportDocument (pngFile, ExportType.SAVEFORWEB, pngOpts)}