forked from BenoitFreslon/MobileMedias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate_Screenshots.jsx
executable file
·172 lines (147 loc) · 6.17 KB
/
Create_Screenshots.jsx
1
#target photoshop/* Ultimate phone tablet screenshots exporter Script by Benoit Freslon * based on work of Hannes Delbeke 22/05/2013 * based on work of Tomek Cejner (tomek (at) japko dot info) (support of nested layer groups, and exports single layers in addition to groups) * based on work of Damien van Holten: http://www.damienvanholten.com/blog/export-groups-to-files-photoshop/ */var outFolder;function main(){ app.preferences.rulerUnits = Units.PIXELS ; app.preferences.typeUnits = TypeUnits.PIXELS ; if(!documents.length) return; var doc = activeDocument; var oldPath = activeDocument.path; outFolder = createFolder( oldPath + "/Screenshots"); scanLayerSets(doc); function scanLayerSets(el) { // find layer groups for(var a=0;a<el.layerSets.length;a++) { var groupScreen = el.layerSets[a] ; groupname = groupScreen.name; //check name for every layer if (groupname.substr(-4) == ".png" || groupname.substr(-4) == ".jpg") //if name ends in jpg or png { //find txt group for(var b=0; b< groupScreen.layerSets.length; b++) //layersets are groups { var txtgroup = groupScreen.layerSets[b] ; var txtname = txtgroup.name; if (txtname == "txt") //if name is txt { var LanguageLayer; for(var c=0; c < txtgroup.artLayers.length; c++) //check all layers in the txt file { LanguageLayer = txtgroup.artLayers[c] ; LanguageLayer.visible = false; } for( var d=0;d<txtgroup.artLayers.length;d++) //check all layers in the txt file { LanguageLayer = txtgroup.artLayers[d] ; LanguageLayer.visible = true; //put 1 txt layer on visible saveLayer(groupScreen,LanguageLayer,oldPath);//save the file LanguageLayer.visible = false; //put it back invisible for next layer } } } } } alert("Screenshots created!"); } function saveLayer(layer, lname, path) { trace("saveLayer: "+layer+" "+path); doc.activeLayer = layer; createScreenshot(layer, lname, "IPad_Pro", 2732, 2048); createScreenshot(layer, lname, "IPad_Retina", 2048, 1536); createScreenshot(layer, lname, "IPad", 1024, 768); createScreenshot(layer, lname, "IPhone_6+", 2208, 1242); createScreenshot(layer, lname, "IPhone_6", 1334, 750); createScreenshot(layer, lname, "IPhone_5", 1136, 640); createScreenshot(layer, lname, "IPhone_4", 960, 640); createScreenshot(layer, lname, "Android_Tablet_7\"", 1920, 1200); createScreenshot(layer, lname, "Android_Tablet_10\"", 2560, 1600); //createScreenshot(layer, lname, "Android Nexus 5X", 1920, 1080); //createScreenshot(layer, lname, "Android Nexus 6P", 2560, 1440); //createScreenshot(layer, lname, "Android Nexus 9", 2048, 1536); // Same as IPad Retina // Add more devices here }}; main(); function createScreenshot(layer, lname, namedevice, width, height) { createFolder(namedevice); dupLayers(); var w = setOrientationW(width, height); var h = setOrientationH(width, height); resizeImageAndCanvas(w,h); var screenName = layer.name; screenName = screenName.substring(0,screenName.length-4 ); var exportName = "/" + lname.name + "_"+ screenName + "_"+ namedevice + "_"+ w + "x"+ h + ".png"; activeDocument.mergeVisibleLayers(); //activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true); var folder = createFolder ( outFolder +"/"+ lname.name + "/" + namedevice+"_" + w + "x"+ h); var saveFile = File(folder + exportName); SavePNG(saveFile); app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);} function trace ( msg ) { $.writeln( msg );}function createFolder ( folderName ) { var folder = new Folder ( folderName ); if ( !folder.exists ) { folder.create (); } return folder;}function resizeImageAndCanvas(w, h) { if (activeDocument.height > activeDocument.width) { activeDocument.resizeImage( null , h ); } else { activeDocument.resizeImage( w , null ); } activeDocument.resizeCanvas( w , h , AnchorPosition.MIDDLECENTER);} function setOrientationW ( w, h ) { if (activeDocument.height > activeDocument.width) { return h; } return w;}function setOrientationH ( w, h ) { if (activeDocument.height > activeDocument.width) { return w; } return h;} function dupLayers() { var desc143 = new ActionDescriptor(); var ref73 = new ActionReference(); ref73.putClass( charIDToTypeID('Dcmn') ); desc143.putReference( charIDToTypeID('null'), ref73 ); desc143.putString( charIDToTypeID('Nm '), activeDocument.activeLayer.name ); var ref74 = new ActionReference(); ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); desc143.putReference( charIDToTypeID('Usng'), ref74 ); executeAction( charIDToTypeID('Mk '), desc143, DialogModes.NO );}function SaveJPG( saveFile, jpegQuality ) { var sfwOptions = new ExportOptionsSaveForWeb(); sfwOptions.format = SaveDocumentType.JPEG; sfwOptions.includeProfile = false; sfwOptions.interlaced = 0; sfwOptions.optimized = true; sfwOptions.quality = jpegQuality; //0-100 activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);}function SavePNG(saveFile) { trace("SavePNG: "+saveFile); var pngOpts = new ExportOptionsSaveForWeb; pngOpts.format = SaveDocumentType.PNG pngOpts.PNG8 = false; pngOpts.transparency = false; pngOpts.interlaced = false; pngOpts.quality = 100; activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts); }