首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图标日历生成器

图标日历生成器
EN

Stack Overflow用户
提问于 2015-09-02 17:13:06
回答 1查看 6.1K关注 0票数 2

是否有日历Photoshop/illustrator脚本可以自动生成与此日历图标图像类似的日期编号?

我需要类似的图标与日期(1,2,3..31)和名称的每个月,但在.png格式。我不能使用html/css3和jquery来创建图标。

感谢您的回答和帮助

EN

回答 1

Stack Overflow用户

发布于 2016-07-14 03:43:10

是的,这是可能的。我喜欢挑战:)

首先打开模板图像

其次,创建文件夹C:\temp\calendar (或在脚本中更改目标路径)

运行下面的脚本,它将生成由sdate & eDate (开始和结束日期)定义的日期-当前为11月30日至12月01日

代码语言:javascript
复制
// Load in background image before running script

// call the source document
var srcDoc = app.activeDocument;

var sDate = new Date("November, 30, 2016 00:00:00");
var eDate = new Date("January,  01, 2017 00:00:00");

var myPath = "c:\\temp\\calendar"

printDate(sDate, eDate, myPath, srcDoc);

//-----------------------------
function printDate(start, end, apath, sauce)
{
  if (start == undefined) return;
  if (end == undefined) return;

  // set long month names
  var monthNames = ["January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"
  ];

  str = "";

  // main loop here
  while(start <= end)
  {

    // Display the month, day, and year.
    // getMonth() returns a 0-based number.
    var monthNum = start.getMonth()+1;
    var month = monthNames[monthNum-1].toUpperCase();
    var day   = start.getDate();
    var year  = start.getFullYear();

    // alert(month + " " + day + " " + year);

    // num padding
    if (monthNum < 10) monthNum = "0" + monthNum;
    if (day < 10) day = "0" + day;

    var theDate = "cal_" + monthNum + "_" + day + "_" + year;

    duplicateIt(theDate);

    var day = start.getDate();
    str = (day);         

    var newDate = start.setDate(start.getDate() + 1);

    // fontface, size, R,G,B, text, X, Y
    // print bigmonth
    createText("Arial-BoldMT", 38.0,255, 255, 255, month, 582, 460);

    // print big day
    createText("Arial-BoldMT", 176.0, 0, 0, 0, day, 582, 1144);

    var f  = apath + "\\" + theDate + ".png";

    // alert(f)
    saveAsPNG(f, 10);

    // close that saved png
    app.activeDocument.close();

    // get the original source doc
    app.activeDocument = sauce;

    // reset start
    start = new Date(newDate);
  }
}

// function DUPLICATE IT (str)
// --------------------------------------------------------
function duplicateIt(str)
{
  // duplicate image into new document
  if (arguments.length == 0) str = "temp";

  var id428 = charIDToTypeID( "Dplc" );
  var desc92 = new ActionDescriptor();
  var id429 = charIDToTypeID( "null" );
  var ref27 = new ActionReference();
  var id430 = charIDToTypeID( "Dcmn" );
  var id431 = charIDToTypeID( "Ordn" );
  var id432 = charIDToTypeID( "Frst" );
  ref27.putEnumerated( id430, id431, id432 );
  desc92.putReference( id429, ref27 );
  var id433 = charIDToTypeID( "Nm  " );
  desc92.putString( id433, str ); // name
  executeAction( id428, desc92, DialogModes.NO );
}

// function SAVE JPEG(file name & path)
// --------------------------------------------------------
function saveAsPNG(afilePath)
{
  // flatten it
  activeDocument.flatten();

  // save as a png
  var pngFile = new File(afilePath);
  pngSaveOptions = new PNGSaveOptions();
  pngSaveOptions.embedColorProfile = true;
  pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
  pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1;

  activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);
}

// function CREATE TEXT(typeface, size, R, G, B, content, Xpos, Ypos, justify)
// --------------------------------------------------------
function createText(fface, size, colR, colG, colB, content, X, Y)
{

  // Add a new layer in the new document
  var artLayerRef = app.activeDocument.artLayers.add()

  // Specify that the layer is a text layer
  artLayerRef.kind = LayerKind.TEXT;
  artLayerRef.name = content;

  //This section defines the color of the text
  textColor = new SolidColor();
  textColor.rgb.red = colR;
  textColor.rgb.green = colG;
  textColor.rgb.blue = colB;

  //Get a reference to the text item so
  // that we can add the text and format it a bit
  textItemRef = artLayerRef.textItem
  textItemRef.font = fface;
  textItemRef.contents = content;
  textItemRef.color = textColor;
  textItemRef.size = size;
  //pixels from the left, pixels from the top
  textItemRef.position = new Array(X, Y)

  just = Justification.CENTER;

  activeDocument.activeLayer.textItem.justification = just;
}

它将它们保存为以日期命名的.PNG文件。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32349106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档