简单的自动化脚本,方便批量作业。
// This script is used to add creation date for each .jpg // in folder specified as workDir and save it with the same // name in another folder specified as saveDir. var workDir = 'C:/Users/ABC/Pictures/Camera/' var saveDir = 'C:/Users/ABC/Pictures/output/' // Get all .jpg files in folder. var processFolder = Folder(workDir) var fileList = processFolder.getFiles(/\.(jpg)$/i); app.bringToFront(); // Loop through files for (var i = 0; i < fileList.length; i++) { // Only process the returned file objects // The filter 'should' have missed out any folder objects if (fileList[i] instanceof File && fileList[i].hidden == false) { addCreationDateAndSave(fileList[i], new File(saveDir + fileList[i].name)) //$.writeln(fileList[i].name) } } function addCreationDateAndSave(srcFile, saveFile) { // Remember current unit settings and then set units to // the value expected by this script var originalUnit = preferences.rulerUnits preferences.rulerUnits = Units.INCHES var fileRef = srcFile var docRef = app.open(fileRef) // Create a new art layer containing text var artLayerRef = docRef.artLayers.add() artLayerRef.kind = LayerKind.TEXT // Set the contents of the text layer. var textItemRef = artLayerRef.textItem // Set text color, font and size textColor = new SolidColor(); textColor.rgb.red = 255 textColor.rgb.green = 255 textColor.rgb.blue = 255 textItemRef.color = textColor textItemRef.font = "Myriad Pro" textItemRef.size = new UnitValue(24, "pt") // Set position of textItem, pre-estimate the width and // height of textItem of contents like '2017/03/30' for // a specified font size. var tHalfWidth = new UnitValue(0.75, "in") var tHeight = new UnitValue(0.3, "in") textItemRef.position = Array(app.activeDocument.width.as("in") * 0.5 - tHalfWidth.as("in"), app.activeDocument.height.as("in") * 0.98 - tHeight.as("in")) // creationDate example: 20170413 var Y = docRef.info.creationDate.substring(0,4) var M = docRef.info.creationDate.substring(4,6) var D = docRef.info.creationDate.substring(6) textItemRef.contents = Y + "/" + M + "/" + D jpgSaveOptions = new JPEGSaveOptions() jpgSaveOptions.embedColorProfile = true jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE jpgSaveOptions.matte = MatteType.NONE jpgSaveOptions.quality = 12 app.activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE) app.activeDocument.close(SaveOptions.DONOTSAVECHANGES) // Restore original ruler unit setting app.preferences.rulerUnits = originalUnit // Release references docRef = null artLayerRef = null textItemRef = null }