<commit_before>﻿/*
	Photoshop script to generate all iOS App Icon PNGs
	https://github.com/jessesquires/iOS-icons-script

	See included README and LICENSE for details.

	Modifications 
		Copyright (c) 2014 <NAME>
		Copyright (c) 2012 <NAME>

	Copyright (c) 2010 <NAME>
*/

//	Turn debugger on
//	0 is off.
// 	$.level = 1;

try {

	//	prompt user to select source file, cancel returns null
	var sourceFile = File.openDialog("Select a 1:1 sqaure PNG file that is at least 1024x1024.", "*.png", false);

	if (sourceFile !== null)  { 
		var doc = open(sourceFile, OpenDocumentType.PNG);
		
		if (doc == null) {
			throw "Oh shit!\nSomething is wrong with the file. Make sure it is a valid PNG file.";
		}

		//	save for undo
		var startState = doc.activeHistoryState; 

		//	will restore at end
		var initialPrefs = app.preferences.rulerUnits; 
		
		app.preferences.rulerUnits = Units.PIXELS;

		if (doc.width != doc.height || doc.width < 1024 || doc.height < 1024) {
			throw "What the fuck is this?!\nImage failed validation. Please select a 1:1 sqaure PNG file that is at least 1024x1024.";
		}
		
		//	folder selection dialog
		var destFolder = Folder.selectDialog("Choose an output folder");

		if (destFolder == null) {
			// user canceled, just exit
			throw "";
		}

		//	save icons in PNG-24 using Save for Web
		var saveForWeb = new ExportOptionsSaveForWeb();
		saveForWeb.format = SaveDocumentType.PNG;
		saveForWeb.PNG8 = false;
		saveForWeb.transparency = true;

		//	delete metadata
		doc.info = null;
		
		var icons = [
			{"name": "iTunesArtwork@2x", "size":1024},
			{"name": "iTunesArtwork", "size":512},
			
			{"name": "Icon-29", "size":29},
			{"name": "Icon-29@2x", "size":58},
			{"name": "Icon-29@3x", "size":87},
			
			{"name": "Icon-40", "size":40},
			{"name": "Icon-40@2x", "size":80},
			{"name": "Icon-40@3x", "size":120},
			
			{"name": "Icon-50", "size":50},
			{"name": "Icon-50@2x", "size":100},
			
			{"name": "Icon-57", "size":57},
			{"name": "Icon-57@2x", "size":114},
			
			{"name": "Icon-60@2x", "size":120},
			{"name": "Icon-60@3x", "size":180},

			{"name": "Icon-72", "size":72},
			{"name": "Icon-72@2x", "size":144},
			
			{"name": "Icon-76", "size":76},
			{"name": "Icon-76@2x", "size":152},
			
			{"name": "Icon-120", "size":120}
		];

		for (var i = 0; i < icons.length; i++) {
			var eachIcon = icons[i];

			doc.resizeImage(eachIcon.size, eachIcon.size, null, ResampleMethod.BICUBICSHARPER);

			var destFileName = eachIcon.name + ".png";

			if (eachIcon.name == "iTunesArtwork@2x" || eachIcon.name == "iTunesArtwork") {
				// iTunesArtwork files don't have an extension
				destFileName = eachIcon.name;
			}

			doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, saveForWeb);

			// undo resize
			doc.activeHistoryState = startState;
		}

		alert("Success!\nAll iOS icons created and saved. Fuck yeah. 🎉 🍺");
	}
}
catch (exception) {
	//	show degbug message and then quit
	if (exception != null && exception != "") {
		alert(exception);
	}
}
finally {
	if (doc != null) {
		doc.close(SaveOptions.DONOTSAVECHANGES);
	}

	//	restore prefs
	app.preferences.rulerUnits = initialPrefs; 
}
<commit_msg>clean up and optimize script<commit_after>﻿/*
	Photoshop script to generate all iOS App Icon PNGs
	https://github.com/jessesquires/iOS-icons-script

	See included README and LICENSE for details.

	Modifications 
		Copyright (c) 2014 <NAME>
		Copyright (c) 2012 <NAME>

	Copyright (c) 2010 <NAME>
*/

//	Turn debugger on
//	0 is off.
// 	$.level = 1;

var initialPrefs = app.preferences.rulerUnits;

function main() {
	//	prompt user to select source file, cancel returns null
	var sourceFile = File.openDialog("Select a 1:1 sqaure PNG file that is at least 1024x1024.", "*.png", false);
	if (sourceFile == null)  { 
		// user canceled
		return;
	}

	var doc = open(sourceFile, OpenDocumentType.PNG);
	if (doc == null) {
		alert("Oh shit!\nSomething is wrong with the file. Make sure it is a valid PNG file.");
		return;
	}

	app.preferences.rulerUnits = Units.PIXELS;

	if (doc.width != doc.height || doc.width < 1024 || doc.height < 1024) {
		alert("What the fuck is this?!\nImage failed validation. Please select a 1:1 sqaure PNG file that is at least 1024x1024.");
		restorePrefs();
		return;
	}

	//	folder selection dialog
	var destFolder = Folder.selectDialog("Choose an output folder.\n*** Warning! ***\nThis will overwrite any existing files with the same name in this folder.");
	if (destFolder == null) {
		// user canceled
		restorePrefs();
		return;
	}

	//	save icons in PNG-24 using Save for Web
	var saveForWeb = new ExportOptionsSaveForWeb();
	saveForWeb.format = SaveDocumentType.PNG;
	saveForWeb.PNG8 = false;
	saveForWeb.transparency = true;

	//	delete metadata
	doc.info = null;
	
	var icons = [
		{"name": "iTunesArtwork@2x", "size":1024},
		{"name": "iTunesArtwork", "size":512},
		
		{"name": "Icon-29", "size":29},
		{"name": "Icon-29@2x", "size":58},
		{"name": "Icon-29@3x", "size":87},
		
		{"name": "Icon-40", "size":40},
		{"name": "Icon-40@2x", "size":80},
		{"name": "Icon-40@3x", "size":120},
		
		{"name": "Icon-50", "size":50},
		{"name": "Icon-50@2x", "size":100},
		
		{"name": "Icon-57", "size":57},
		{"name": "Icon-57@2x", "size":114},
		
		{"name": "Icon-60@2x", "size":120},
		{"name": "Icon-60@3x", "size":180},

		{"name": "Icon-72", "size":72},
		{"name": "Icon-72@2x", "size":144},
		
		{"name": "Icon-76", "size":76},
		{"name": "Icon-76@2x", "size":152},
		
		{"name": "Icon-120", "size":120}
	];

	var initialState = doc.activeHistoryState; 

	for (var i = 0; i < icons.length; i++) {
		var eachIcon = icons[i];

		doc.resizeImage(eachIcon.size, eachIcon.size, null, ResampleMethod.BICUBICSHARPER);

		var destFileName = eachIcon.name + ".png";

		if (eachIcon.name == "iTunesArtwork@2x" || eachIcon.name == "iTunesArtwork") {
			// iTunesArtwork files don't have an extension
			destFileName = eachIcon.name;
		}

		doc.exportDocument(new File(destFolder + "/" + destFileName), ExportType.SAVEFORWEB, saveForWeb);

		// undo resize
		doc.activeHistoryState = initialState;
	}

	alert("Success!\nAll iOS icons created and saved. Fuck yeah. 🎉 🍺");

	doc.close(SaveOptions.DONOTSAVECHANGES);
	
	restorePrefs();
}

function restorePrefs() {
	app.preferences.rulerUnits = initialPrefs;
}

main();

{'fraction_non_alphanumeric': 0.1748262792166772, 'fraction_numerical': 0.04485154769425142, 'mean_word_length': 3.599128540305011, 'pattern_counts': {'":': 76, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1735734', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2251, 'n_words': 604}