var defaultRulerUnits = preferences.rulerUnits; preferences.rulerUnits = Units.PIXELS; width = 1280; height = 800; resolution = 72; year = prompt("'Indica el año’, "); year = parseInt(year); docName = "Calendario " + year + " Photoshop"; /* Establecer colores */ normalColor = new SolidColor(); highlightColor = new SolidColor(); backColor = new SolidColor(); normalColor.rgb.hexValue = "ffffff"; highlightColor.rgb.hexValue = "a4b1d1"; backColor.rgb.hexValue = "1b4392"; /* Definición para diferentes capas de texto */ weekdays = new Array ("L","M","X","J","V","S","D"); months = new Array ("Enero","Febrero","Marzo","Abril", "Mayo","Junio","Julio","Agosto", "Septiembre","Octubre","Noviembre","Diciembre"); /* Creación de un nuevo documento PSD */ doc = app.documents.add(width, height, resolution, docName, NewDocumentMode.RGB); doc.selection.selectAll(); doc.selection.fill(backColor); doc.selection.deselect(); /* Imagen de fondo. Aparecerá una ventana. */ file = app.openDialog(); if (file[0]) { app.load(file[0]); backFile = app.activeDocument; backFile.resizeImage(width, height); backFile.selection.selectAll(); backFile.selection.copy(); backFile.close(SaveOptions.DONNOTSAVECHANGES); doc.paste(); doc.layers[0].name = "Background Image"; } /* Generador de la malla del calendario */ for (currentMonth = 0; currentMonth < 12; currentMonth++) { x = currentMonth % 4; y = Math.floor(currentMonth/4); group = doc.layerSets.add(); group.name = months[currentMonth]; for (currentWeekday = 0; currentWeekday < 7; currentWeekday++) { z = currentWeekday days = group.artLayers.add(); days.kind = LayerKind.TEXT; days.name = weekdays[currentWeekday]; days.textItem.color = normalColor; days.textItem.size = 18; days.textItem.kind = TextType.PARAGRAPHTEXT; days.textItem.justification = Justification.CENTER; days.textItem.height = 18; days.textItem.width = 24; days.textItem.contents = weekdays[currentWeekday]; days.textItem.position = new Array( (65+(300*x)+(24*(z+1))), (57+(210*y))); } var first = new Date(year, currentMonth, 1).getDay() + 6; var totalDays = new Date (year, (currentMonth + 1), 0).getDate(); for (numDate = 0; numDate < totalDays; numDate ++) { m = ((first + numDate) % 7); n = Math.floor((first + numDate) / 7); text = numDate + 1; if (text < 10) { text = "0" + text; } numeralDate = group.artLayers.add(); numeralDate.kind = LayerKind.TEXT; numeralDate.name = "Numeral"; numeralDate.textItem.color = normalColor; numeralDate.textItem.size = 18; numeralDate.textItem.kind = TextType.PARAGRAPHTEXT; numeralDate.textItem.justification = Justification.CENTER; numeralDate.textItem.height = 18; numeralDate.textItem.width = 24; numeralDate.textItem.contents = text; if (first <= 6) { numeralDate.textItem.position = new Array( (89+(300*x)+(24*m)), (93+(210*y)+(18*n))); } else { numeralDate.textItem.position = new Array( (89+(300*x)+(24*m)), (75+(210*y)+(18*n))); } } monthName = group.artLayers.add(); monthName.kind = LayerKind.TEXT; monthName.name = months[currentMonth]; monthName.textItem.color = normalColor; monthName.textItem.size = 28; monthName.textItem.kind = TextType.PARAGRAPHTEXT; monthName.textItem.justification = Justification.RIGHT; monthName.textItem.height = 35; monthName.textItem.width = 145; monthName.textItem.contents = months[currentMonth]; monthName.rotate(-90); monthName.textItem.position = new Array( (55+(300*x)), (202+(210*y))); app.activeDocument.flatten(); } /* Capa para el año */ yearLayer = doc.artLayers.add(); yearLayer.kind = LayerKind.TEXT; yearLayer.name = year; yearLayer.textItem.contents = year; yearLayer.textItem.size = 72; yearLayer.textItem.color = highlightColor; yearLayer.textItem.position = new Array(1050, 730); /* Línea decorativa*/ line = doc.artLayers.add(); line.name = "Line"; region = Array(Array(80,729), Array(1000, 729), Array(1000, 730), Array(80, 730)); doc.selection.select(region); doc.selection.fill(normalColor); doc.selection.deselect();