├── README.md ├── LICENSE ├── ExportDocument2xPNG.jsx └── ExportDocument3xPNG.jsx /README.md: -------------------------------------------------------------------------------- 1 | # Scripts to export your Photoshop document to a PNG at 2x and 3x 2 | Allows you to keep your sanity and work at 1x. Full explanation and sample PSD files on my blog: http://murdochcarpenter.com/why-you-shouldnt-design-to-retina/. 3 | 4 | ## To install 5 | Copy and paste these scripts into your Photoshop Scripts folder. On Windows this is *‘\Program Files\Adobe\Adobe Photoshop CC 2014\Presets\Scripts\’* and on Mac *‘\Applications\Adobe\Photoshop CC 2014\Presets\Scripts\’*. Then anytime you want to export a 2x PNG just click **File > Scripts > ExportDocument2xPNG** or a 3x PNG click **File > Scripts > ExportDocument3xPNG**. 6 | 7 | ## What the script does 8 | - Resizes your PSD to 200% or 300% 9 | - Creates a folder ‘retina’ in the same place as your PSD 10 | - Saves the PNG as documentname_2x.png or documentname_2x.png 11 | - Clears and purges the history (Undo) 12 | - Saves the document exactly how it was before the script ran 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Murdoch Carpenter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /ExportDocument2xPNG.jsx: -------------------------------------------------------------------------------- 1 | // Murdoch Carpenter 2 | // http://murdochcarpenter.com/blog/ 3 | // Tested in Photoshop CC (2014) 4 | // V1.1 5 | 6 | var doc = app.activeDocument; 7 | var docName = doc.name.replace(/\.[^\.]+$/, ''); 8 | var docPath = doc.path; 9 | var scale = "200%"; 10 | var folderName = "retina"; 11 | var extensionName = "_2x.png"; 12 | 13 | // where the action happens 14 | function exportScaledPNG() { 15 | // resize the document 16 | doc.resizeImage(scale, scale, doc.resolution, ResampleMethod.BICUBIC); 17 | // check if a folder has already been created or not - create if not 18 | var retinaFolder = Folder(docPath + "/" + folderName); 19 | if(!retinaFolder.exists) retinaFolder.create(); 20 | // check if the PNG already exists or not - delete if so 21 | pngFile = File(docPath + "/" + folderName + "/" + docName + extensionName); 22 | if(pngFile.exists) pngFile.remove(); 23 | // save the PNG 24 | pngSaveOptions = new PNGSaveOptions(); 25 | pngSaveOptions.compression = 9; 26 | doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE) 27 | // undo the history and purge 28 | doc.activeHistoryState = doc.historyStates[doc.historyStates.length-2]; 29 | app.purge(PurgeTarget.HISTORYCACHES); 30 | // save the document (to avoid having to do it manually) 31 | doc.save(); 32 | } 33 | 34 | // wrap in a try/catch for errors 35 | try { 36 | exportScaledPNG(); 37 | } catch (e) { 38 | if (DialogModes.NO != app.playbackDisplayDialogs) { 39 | alert(e + " : " + e.line); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ExportDocument3xPNG.jsx: -------------------------------------------------------------------------------- 1 | // Murdoch Carpenter 2 | // http://murdochcarpenter.com/blog/ 3 | // Tested in Photoshop CC (2014) 4 | // V1.1 5 | 6 | var doc = app.activeDocument; 7 | var docName = doc.name.replace(/\.[^\.]+$/, ''); 8 | var docPath = doc.path; 9 | var scale = "300%"; 10 | var folderName = "retina"; 11 | var extensionName = "_3x.png"; 12 | 13 | // where the action happens 14 | function exportScaledPNG() { 15 | // resize the document 16 | doc.resizeImage(scale, scale, doc.resolution, ResampleMethod.BICUBIC); 17 | // check if a folder has already been created or not - create if not 18 | var retinaFolder = Folder(docPath + "/" + folderName); 19 | if(!retinaFolder.exists) retinaFolder.create(); 20 | // check if the PNG already exists or not - delete if so 21 | pngFile = File(docPath + "/" + folderName + "/" + docName + extensionName); 22 | if(pngFile.exists) pngFile.remove(); 23 | // save the PNG 24 | pngSaveOptions = new PNGSaveOptions(); 25 | pngSaveOptions.compression = 9; 26 | doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE) 27 | // undo the history and purge 28 | doc.activeHistoryState = doc.historyStates[doc.historyStates.length-2]; 29 | app.purge(PurgeTarget.HISTORYCACHES); 30 | // save the document (to avoid having to do it manually) 31 | doc.save(); 32 | } 33 | 34 | // wrap in a try/catch for errors 35 | try { 36 | exportScaledPNG(); 37 | } catch (e) { 38 | if (DialogModes.NO != app.playbackDisplayDialogs) { 39 | alert(e + " : " + e.line); 40 | } 41 | } 42 | --------------------------------------------------------------------------------