var message = "Hi, I am now going to create an image for you and save it on your desktop. Would you like to continue?"; var answer = confirm (message); if(answer) { createImage(); } function createImage() { // Set units to pixels app.preferences.rulerUnits = Units.PIXELS; app.preferences.typeUnits = TypeUnits.PIXELS; // Define document properties var width = 1024; var height = 768; var res = 72; var name = "AsyncJS"; var mode = NewDocumentMode.RGB; var fill = DocumentFill.TRANSPARENT; var ratio = 1; // Create new document var doc = app.documents.add(width, height, res, name, mode, fill, ratio); // Set up the background layer var backgroundLayer = doc.artLayers[0]; backgroundLayer.name = "Background"; // Create random colors app.foregroundColor.rgb.red = Math.random() * 255; app.foregroundColor.rgb.green = Math.random() * 255; app.foregroundColor.rgb.blue = Math.random() * 255; app.backgroundColor.rgb.red = 0; app.backgroundColor.rgb.green = 0; app.backgroundColor.rgb.blue = 0; // Apply clouds to the background layer based on these random colors backgroundLayer.applyClouds(); // applyLensFlare(brightness, flareCenter[], LensType // Add a text layer var textLayer = doc.artLayers.add(); textLayer.name = "Text"; textLayer.kind = LayerKind.TEXT; // Create the text item var textItem = textLayer.textItem; textItem.contents = "Async.js"; textItem.font = "Helvetica"; textItem.size = 128; textItem.fauxBold = true; textItem.position = [width/2, height/2]; textItem.justification = Justification.CENTER; // Set the color to white textItem.color.rgb.red = 255; textItem.color.rgb.green = 255; textItem.color.rgb.blue = 255; // Apply a blend mode textLayer.blendMode = BlendMode.SOFTLIGHT; // Name of the file we are going to ExportOptions var filename = "~/Desktop/async-" + new Date().getTime() + ".png"; var file = File(filename); // Type of export we are doing var exportType = ExportType.SAVEFORWEB; // Save for web options var options = new ExportOptionsSaveForWeb(); options.format = SaveDocumentType.PNG; options.quality = 100; // Export to disk doc.exportDocument (file, ExportType.SAVEFORWEB, options); // Close the document without saving doc.close(SaveOptions.DONOTSAVECHANGES); }