Javascript scripting for automatically adding borders and EXIF information to Images Using PhotoShop

Source: Internet
Author: User
This article mainly introduces the Javascript script for PhotoShop to automatically add borders and EXIF information to images. This article provides and implements the Code. For more information, see

As a "photography enthusiast" (well, I admit that I am not qualified, so I only play photography for a few days -_-!!) There is always one thing that cannot be avoided, that is, to bring the EXIF parameter to the photo. Although I have installed a plug-in to display the EXIF information, I still feel that the plug-in is not very powerful, in addition, some comprehensive operations should be taken into account, such as batch resizing and adding copyright information.

Of course, we still need PS. We can also write PS scripts so that he can perform some operations according to our ideas. :) hey, I found a PS script from a post on the forum, according to your own ideas, add some modifications (mainly time, lens recognition, and focal length recognition. With the script, it is much more convenient. For example, if you want to add EXIF borders in batches, it is very easy to record an action and then run this action in batch :)

Finally, attach the script:

DisplayDialogs = DialogModes. NO; var defaultRulerUnits = preferences. rulerUnits; preferences. rulerUnits = Units. PIXELS; // Splits a long String into a single String function explodeArray (item) {var I = 0; var Count = 0; var tempString = new String (item ); tempArray = new Array (1); do {I = tempString. indexOf (":"); if (I> 0) tempString = tempString. substr (I + 1, tempString. length-i-1); I = tempString. indexOf (">"); if (I> 0) {tempArray [Count] = tempString. substr (0, I); tempString = tempString. substr (I + 1, tempString. length-i-1); Count ++;} I = tempString. indexOf ("<"); if (I> 0) {tempArray [Count] = tempString. substr (0, I); tempString = tempString. substr( I-1, tempString. length-I + 1); Count ++ ;}} while (tempString. indexOf ("")> 0); tempArray [Count] = tempString; return tempArray;} var I = 0; var j = 0; var k = 0; var pResulotion = 72; var AD = ""; var resRatio = ""; var imageRatio = ""; var dateArray1 = ""; var dateArray2 = ""; var monthsArray = ""; var exposureProgramArray = ""; var phoDate = ""; var phoTime = ""; var photoWidth = ""; var photoHight = ""; var exifData = ""; var black = ""; var white = ""; var gray = ""; var fWidth = ""; var fHight = ""; var tSize = ""; var tLeft = ""; Var tHight = ""; var infoLayer = ""; var TI = ""; nameLayer = ""; var TN = ""; var stringTemp = ""; // temporary string var make = ""; // camera company var model = ""; // camera model var camera = ""; // camera var lens = ""; // lens type var lensUsed = ""; // lens var focalLength = ""; // focal length var exposureTime = ""; // shutter var fNumber = ""; // aperture var ISOSpeedRatings = ""; // ISO sets var dateTimeOriginal = ""; // The shooting time var exposureBiasValue = ""; // The Exposure Compensation var exposureProgram = ""; // exposure program mode var fired = ""; // flash mode // change What you want to write, such as copyright ownership and your own network name. // if it is empty, the camera name var creator = "Photo By Kaisir" will be used "; // The photographer AD = activeDocument; // Aglin compiled the code for automatically changing the image size to the online communication size. // slightly modified. If the width of either side is greater than 1000, automatically crop the image. // the longest side here is 750, the shortest side is 500 // set the aspect ratio based on the image ratio taken by the camera. // if not, remove it. // -------------------------------------------- var resizeMax = 1024; var resizeMin = 678; if (AD. width. value> 1500 | AD. height. value> 1500) {imageRatio = AD. width. value/AD. height. value; if (imageRatio> 1) AD. ResizeImage (resizeMax, resizeMin, pResulotion, ResampleMethod. BICUBICSHARPER); if (imageRatio = 1) AD. resizeImage (resizeMax, resizeMax, pResulotion, ResampleMethod. BICUBICSHARPER); if (imageRatio <1) AD. resizeImage (resizeMin, resizeMax, pResulotion, ResampleMethod. BICUBICSHARPER);} // ------------------------------------------------ resRatio = AD. resolution/pResulotion; if (resRatio! = 1) {AD. resizeImage (AD. width. value, AD. height. value, pResulotion);} photoWidth = AD. width. value; photoHight = AD. height. value; // obtain the RAW stored information exifData = AD. xmpMetadata. rawData. toString (); // divides EXIF information into explodeArray (exifData); // Photoshop CS to obtain EXIF information // shutter speed for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("ExposureTime ")! =-1) {exposureTime = tempArray [n + 1]; break ;}/// aperture size for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("FNumber ")! =-1) {fNumber = tempArray [n + 1]; break ;}/// exposure program mode for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("ExposureProgram ")! =-1) {exposureProgram = tempArray [n + 1]; break ;}// exposure compensation for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("ExposureBiasValue ")! =-1) {exposureBiasValue = tempArray [n + 1]; break ;}// flash mode for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("Fired ")! =-1) {fired = tempArray [n + 1]; break ;}// shooting Date and Time for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("DateTimeOriginal ")! =-1) {dateTimeOriginal = tempArray [n + 1]; break ;}// use focal length for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (tempArray [n] = "FocalLength") {focalLength = tempArray [n + 1]; break ;}} // ISO settings for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("ISOSpeedRatings ")! =-1) {ISOSpeedRatings = ", ISO" + tempArray [n + 5]; break ;}// use the lens type for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (tempArray [n] = "Lens") {lens = tempArray [n + 1]; break ;}} // camera vendor for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("Make ")! =-1) {make = tempArray [n + 1]; break ;}// camera model for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("Model ")! =-1) {var model = tempArray [n + 1]; break ;}/// for some camera models that do not include the manufacturer, // camera = make + model; // for some camera models, including the manufacturer's camera = model; // The camera owner for (n = 0; n <tempArray. length; n ++) {stringTemp = tempArray [n]; if (stringTemp. indexOf ("creator ")! =-1 & creator = "") {creator = tempArray [n + 5]; break ;}// check the shutter speed dateArray1 = exposureTime. split ("/"); j = dateArray1 [0]; I = dateArray1 [1]; if (j/I> = 1) exposureTime = parseInt (j/I) + ". "+ (j-parseInt (j/I) * I); else {I = parseInt (I/j); j = 1; exposureTime = j + "/" + I;} // calculate the aperture size dateArray1 = fNumber. split ("/"); I = dateArray1 [0]; j = dateArray1 [1]; if (j> 1) fNumber = I/j; elsefNumber = I; // convert exposure compensation to decimal dateArray1 = exposureBiasValue. split ("/"); I = dateArray1 [0]; j = dateArray1 [1]; exposureBiasValue = I/j; // keep two digits after the decimal point, * 100/100, if you keep one digit, the value * 10/10 // is retained by two digits. for 20D, you can ignore the two rows if (exposureBiasValue! = 0) exposureBiasValue = parseInt (exposureBiasValue * 100)/100; if (exposureBiasValue> 0) exposureBiasValue = "+" + exposureBiasValue; // determine the exposure Program mode exposureProgramArray = ["undefined", "Manual", "Normal Program", "Aperture Priority", "Shutter Priority", "Creative Program ", "Action Program", "Portrait Mode", "Landscape Mode"]; exposureProgram = exposureProgramArray [exposureProgram]; // check the flash Mode dateArray1 = fired; if (dateArray1.indexO F ("True ")! =-1) fired = "FlashOn"; elsefired = "FlashOff"; // check the focal length dateArray1 = focalLength. split ("/"); I = dateArray1 [0]; j = dateArray1 [1]; focalLength = parseInt (I/j); // change the date format dateArray1 = dateTimeOriginal. split ("T"); phoDate = dateArray1 [0]; phoTime = dateArray1 [1]; dateArray2 = phoDate. split ("-"); monthsArray = ["1", "2", "3", "4", "5", "6", "7 ", "8", "9", "10", "11", "12"]; phoDate = dateArray2 [0] + "-" + monthsArray [dateArra Y2 [1]-1] + "-" + dateArray2 [2]; dateArray2 = phoTime. split ("+"); phoTime = dateArray2 [0]; // if (lens! = "") {If (lens. indexOf ("17.0-40.0 ")! =-1) lensUsed = "Canon 17-40mm F4L USM";} // if there is no camera information, compare else {var focLength = parseInt (focalLength) with the original method ); lensUsed = "18-55mm: 3. 5-5.6G "; // if (focLength> = 17 & focLength <= 40) // lensUsed =" Nikon "; // if (focLength> = 70 & focLength <= 200) // lensUsed = "Nikon"; // if (focLength = "85 ") // lensUsed = "Nikon"; // if (focLength = "100") // lensUsed = "Nikon";} // draw lines and frames // define black, you can also define other colors. rgb. red = black. rgb. green = black. rgb. blue = 0; // defines white. You can also define other colors. rgb. red = white. rgb. green = white. rgb. blue = 255; // defines gray. You can also define other colors. rgb. red = gray. rgb. green = gray. rgb. blue = 50; // Add a white line backgroundColor = white; // if it is changed to black line, // backgroundColor = black; // set the white line width to 2 or 4, on both sides, the actual width is divided by 2AD. resizeCanvas (AD. width. value + 2, AD. height. value + 2, AnchorPosition. MIDDLECENTER); // Add a gray box // backgroundColor = gray; // Add a black Box backgroundColor = black; // if it is changed to a white box // backgroundColor = white; // Border width and height, here, we set the width of the black box to 1/40 of the image width, and divide the width by 2 fWidth = parseInt (photoWidth/40); fHight = parseInt (photoWidth/40 ); // Add AD. resizeCanvas (AD. width. value + fWidth, AD. height. value + fHight, AnchorPosition. MIDDLECENTER); // Add width points at the bottom to facilitate the writing of AD. resizeCanvas (AD. width. value, AD. height. value + fHight, AnchorPosition. TOPCENTER); // scalar and parameter nameLayer = AD. artLayers. add (); nameLayer. kind = LayerKind. TEXT; TN = nameLayer. textItem; TN. contents = creator; // copyright font, font size, color, bold, etc. TN. font = "STXingkai"; // right-aligned TN. justification = Justification. RIGHT; // font size tSize = parseInt (fWidth + 10)/2); // The left margin and bottom margin of the font tLeft = photoWidth; tHight = photoHight-fHight + tSize; // mark position TN. position = [tLeft, tHight]; TN. size = tSize + 4; TN. color = white; // if it is a white box, the font is black // TN. color = black; TN. fauxBold = true; infoLayer = AD. artLayers. add (); infoLayer. kind = LayerKind. TEXT; TI = infoLayer. textItem; // right-aligned. If left-aligned, the following line of TI can be omitted. justification = Justification. RIGHT; tHight = photoHight + fHight + tSize; // The Position of the logo word TI. position = [tLeft, tHight]; // display: the camera model, lens, focal length, exposure time, aperture, ISO settings, shooting date, and other TI. contents = camera + "," + lensUsed + "@" + focalLength + "mm," + exposureTime + "Sec, F/"; TI. contents = TI. contents + fNumber + ", EV" + exposureBiasValue + ISOSpeedRatings; // if you are not interested in the exposure program, remove the following line TI. contents = TI. contents + "," + exposureProgram + "," + fired; TI. contents = TI. contents + "\ u000D" + phoDate + "" + phoTime; // TI for fonts, font sizes, and colors. font = ""; // TI. font = "Arial"; TI. size = tSize; TI. color = white; // if it is a white box, the font is black // TI. color = black; TI. fauxBold = true; AD. flatten ();//-------------
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.