Anzeige

[CS4] Kalender per Java Script erstellen

[CS4] - Kalender per Java Script erstellen | PSD-Tutorials.de

Erstellt von magicsepp, 26.04.2010.

  1. magicsepp

    magicsepp Aktives Mitglied

    12
    Dabei seit:
    27.08.2009
    Beiträge:
    1.878
    Geschlecht:
    männlich
    Kalender per Java Script erstellen
    Referenz:
    Create a Calendar Using Scripting in Photoshop | Psdtuts+

    Nachdem ich festgestellt habe das in diesem Tutorial der August nicht passt (falscher Wochentag)

    hier das Script mit der Korrektur in Deutsch - Viel Spaß
    PHP:
    1. **
    2.  *    make a Calender
    3.  */
    4.  
    5. //DEFINE AUXILIARY FUNCTIONS
    6. function daysInMonth(month,year){
    7.     return 32- new Date(year, month, 32).getDate();
    8.     }
    9.  
    10. function makeDay (d) {  // convert the day from 0..31 to 00.31
    11.         if(d < 10)
    12.             d = "0"+d;
    13.         return d+"   ";
    14.     }
    15.  
    16. // Save the current preferences
    17. var startRulerUnits = app.preferences.rulerUnits;
    18. var startTypeUnits = app.preferences.typeUnits;
    19.  
    20. //DOC ATTRIBUTES
    21. width = 1280;
    22. height = 800;
    23. resolution = 72;
    24. docName = "PSD-Kalender"
    25. year = 2011;                     /* Kalenderjahr */
    26.  
    27.  
    28. //COLOR SCHEME
    29. normalColor = new SolidColor();
    30.     normalColor.rgb.hexValue = "ffffff";
    31. highlightColor = new SolidColor();
    32.     highlightColor.rgb.hexValue = "a4b1d1";
    33. backColor = new SolidColor();
    34.     backColor.rgb.hexValue = "1b4392";
    35.    
    36.  
    37.  
    38. //DEFINE VARIABLES FOR TEXT LAYERS
    39. monthHeader = "M     D    M    D     F      S\r\r"; //check SPACES
    40. sundayHeader = "S   \r\r";
    41. firstIndent = "        ";
    42. month = new Array("Januar","Februar","März","April","Mai","Juni",
    43. "Juli","August","September","Oktober","November","Dezember") ;
    44.  
    45. //CREATE NEW DOCUMENT
    46. app.preferences.rulerUnits = Units.POINTS; // set ruler units to points
    47. app.preferences.typeUnits = TypeUnits.POINTS //
    48. doc = app.documents.add(width, height, resolution,
    49.                                     docName, NewDocumentMode.RGB);
    50. doc.selection.selectAll();
    51. doc.selection.fill(backColor);
    52. doc.selection.deselect();
    53.  
    54.  
    55. //SELECT BACKGROUND
    56. file = app.openDialog();
    57. if (file[0]) {
    58.     app.load(file[0]);
    59.     backFile = app.activeDocument;
    60.     backFile.resizeImage(width,height);
    61.     backFile.selection.selectAll();
    62.     backFile.selection.copy();
    63.     backFile.close(SaveOptions.DONOTSAVECHANGES);
    64.     doc.paste();
    65.     doc.layers[0].name = "Hintergrund";  //country
    66.     }
    67.  
    68.  
    69.  
    70.  
    71. for (curr=0;curr<12;curr++){
    72.    
    73.         x = curr %4;
    74.         y = Math.floor(curr / 4);
    75.        
    76.         group = doc.layerSets.add();
    77.         group.name = month[curr];
    78.        
    79.         monthName = group.artLayers.add();
    80.         monthName.kind = LayerKind.TEXT;
    81.         monthName.name = month[curr];
    82.         monthName.textItem.color = normalColor;
    83.         monthName.textItem.size = 24;
    84.         monthName.textItem.kind = TextType.PARAGRAPHTEXT;
    85.         monthName.textItem.justification = Justification.RIGHT;
    86.         monthName.textItem.height = 35;
    87.         monthName.textItem.width = 145;
    88.         monthName.textItem.contents = month[curr];
    89.         monthName.rotate(-90);
    90.         monthName.textItem.position = new Array (55+300*x, (202+(210*y)));
    91.        
    92.         days = group.artLayers.add();
    93.         days.kind = LayerKind.TEXT;
    94.         days.name = "Tage";
    95.         days.textItem.justification = Justification.LEFT;
    96.         days.textItem.color = normalColor;
    97.         days.textItem.size = 18;
    98.         days.textItem.position = new Array (90+(300*x), 70+(210*y));
    99.  
    100.         sundays = group.artLayers.add();                              
    101.         sundays.kind = LayerKind.TEXT;                                
    102.         sundays.name = "Sonntage";                                    
    103.         sundays.textItem.justification = Justification.CENTER;        
    104.         sundays.textItem.color = highlightColor;                      
    105.         sundays.textItem.size = 18;                                    
    106.         sundays.textItem.position = new Array (287+(300*x), 70+(210*y));
    107.        
    108.         text = monthHeader;
    109.         textSun = sundayHeader;
    110.        
    111.         startDate = new Date(year, curr, 1);
    112.         n  =  startDate.getDay(); //0=M;1=T..S=6
    113.        
    114.         for(i=0; i<n-1; i++)
    115.             text +=firstIndent;
    116.  
    117.          if(n == 0)
    118.             i = 6;
    119.  
    120.             d = 1;
    121.  
    122.             while(d <= daysInMonth(curr, year)){
    123.             if(i == 6){
    124.                 textSun += makeDay(d) + "\r";
    125.                 text += "\r";
    126.                 }
    127.             else{
    128.                 text += makeDay(d);
    129.                 }
    130.          
    131.                 i++;
    132.                 d++;
    133.                 if(i ==7)
    134.                     i = 0;
    135.             }
    136.         days.textItem.contents = text;
    137.         sundays.textItem.contents = textSun;
    138.        
    139. }
    140.  
    141. //CREATE THE YEAR
    142. yearLayer = doc.artLayers.add();
    143. yearLayer.kind = LayerKind.TEXT;                                
    144. yearLayer.name = year;
    145. yearLayer.textItem.contents = year;
    146. yearLayer.textItem.size = 72;  
    147. yearLayer.textItem.color = highlightColor;
    148. yearLayer.textItem.position = new Array(1050, 730);
    149.  
    150. //CREATE THE BOTTOM LINE
    151. line = doc.artLayers.add();
    152. line.name = "Line";
    153. region = Array(Array(80,729), Array(1000,729), Array(1000,730), Array(80,730));
    154. doc.selection.select(region);
    155. doc.selection.fill(normalColor);
    156. doc.selection.deselect();
    157.  
    158. // Reset the application preferences
    159. app.preferences.rulerUnits = startRulerUnits;
    160. app.preferences.typeUnits = startTypeUnits;
    hier ein Bild für 2011:
    [​IMG]
     
    #1      
  2. Kalender per Java Script erstellen
    AW: Kalender per Java Script erstellen

    Vielen Dank dafür! Sowas hatte ich Anfang diesen Jahres gesucht, aber nicht wirklich gezielt genug geguckt. Jetzt bin ich gerüstet! :)
     
    #2      
x
×
×