Home Web Front-end JS Tutorial JS script to automatically add borders and EXIF ​​information to pictures in PhotoShop_javascript skills

JS script to automatically add borders and EXIF ​​information to pictures in PhotoShop_javascript skills

May 16, 2016 pm 04:13 PM
exif information js script photoshop picture

As a "photography enthusiast" (ok, I admit that I am not very qualified, I have only been doing photography for a few days -_-!!) there is always one thing that cannot be avoided, which is to have EXIF ​​parameters in the photos. Although my blog has installed a plug-in that can display EXIF ​​information, I feel that the plug-in is still not very powerful. In addition, some comprehensive operations must be considered, such as batch resizing, adding copyright information, etc.

Of course, fortunately, we still need PS, and we can also write PS scripts to let it perform certain operations according to our ideas:) Hey, I found a PS script from a post on the Wuji forum, and followed it myself The idea is slightly modified (mainly time, lens identification, and focal length identification) and the renderings are shown in the title picture. It is much more convenient to have a script. For example, if you want to add EXIF ​​borders in batches, it is very simple. Just record an action and then run the action in batches:)

Finally, attach this script:

displayDialogs = DialogModes.NO; 
var defaultRulerUnits = preferences.rulerUnits; 
preferences.rulerUnits = Units.PIXELS; 

//将一个长字串分解成单个字符串
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("</x:xmpmeta>")>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 grey="";
var fWidth="";
var fHight="";
var tSize="";
var tLeft="";
var tHight="";
var infoLayer="";
var TI="";
nameLayer=""; 
var TN=""; 
var stringTemp="";		//临时字串
var make="";			//相机公司
var model="";			//相机型号
var camera="";			//相机
var lens="";			//镜头类型
var lensUsed="";		//使用的镜头
var focalLength=""; 		//焦距
var exposureTime=""; 		//快门
var fNumber="";			//光圈
var ISOSpeedRatings="";		//ISO设置
var dateTimeOriginal="";	//拍摄时间
var exposureBiasValue="";	//曝光补偿
var exposureProgram="";		//曝光程序模式
var fired=""; 			//闪光模式
//改成你自己想写的,比如版权所有和你自己的网名等
//如果为空,将采用相机设置的名字

var creator="Photo By Kaisir";	//拍摄者


AD = activeDocument; 

//Aglin 编制了自动改变图象大小为网上交流大小的代码,
//稍加修改,如果宽窄任一边大于1000,就自动剪裁
//这里最长边为750,最短边为500
//请根据自己相机拍出来的图像比例设置长宽比
//如果不用可以去掉
//--------------------------------------------
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; 

//获取RAW保存的信息
exifData = AD.xmpMetadata.rawData.toString();

//将EXIF信息分成单个的相关信息
explodeArray(exifData); 

//Photoshop CS获取EXIF信息

//快门速度
for(n = 0; n < tempArray.length; n ++) 
{ 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("ExposureTime")!=-1)
	{ 
		exposureTime = tempArray[n+1]; 
		break;
	} 
}

//光圈大小
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("FNumber")!=-1){ 
		fNumber = tempArray[n+1];
		break;
	} 
}

//曝光程序模式
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("ExposureProgram")!=-1){ 
		exposureProgram = tempArray[n+1]; 
		break;
	} 
}

//曝光补偿
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("ExposureBiasValue")!=-1){ 
		exposureBiasValue = tempArray[n+1]; 
		break;
	} 
}

//闪光模式
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("Fired")!=-1){ 
		fired = tempArray[n+1]; 
		break;
	} 
}

//拍摄日期、时间
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("DateTimeOriginal")!=-1){ 
		dateTimeOriginal = tempArray[n+1]; 
		break;
	} 
}

//使用焦距
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(tempArray[n]=="FocalLength"){ 
		focalLength = tempArray[n+1];
		break;
	} 
}

//ISO设置
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("ISOSpeedRatings")!=-1){ 
		ISOSpeedRatings = ", ISO "+tempArray[n+5]; 
		break;
	} 
}

//使用镜头类型
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(tempArray[n]=="Lens"){ 
		lens=tempArray[n+1]; 
		break;
	} 
}


//相机厂商
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("Make")!=-1){ 
		make = tempArray[n+1]; 
		break;
	} 
}

//相机型号
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("Model")!=-1){ 
		var model = tempArray[n+1]; 
		break;
	} 
}
//对于有的相机型号不包括制造商部分
//camera = make+model; 
//对于有的相机型号包括制造商部分
camera = model; 

//相机所有者
for(n = 0; n < tempArray.length; n ++) { 
	stringTemp=tempArray[n];
	if(stringTemp.indexOf("creator")!=-1 && creator==""){ 
		creator = tempArray[n+5]; 
		break;
	} 
}

//检查快门速度
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;
}

//计算光圈大小
dateArray1 = fNumber.split("/");
i = dateArray1[0];
j = dateArray1[1];
if(j>1)
	fNumber=i/j;
else
	fNumber=i;

//曝光补偿换算成小数
dateArray1 = exposureBiasValue.split("/");
i = dateArray1[0];
j = dateArray1[1];
exposureBiasValue=i/j;

//小数点后面保留2位,就*100/100,保留一位,就*10/10
//这里保留了2位,20D可以不要这两行
if(exposureBiasValue!=0)
	exposureBiasValue=parseInt(exposureBiasValue*100)/100;

if (exposureBiasValue > 0)
	exposureBiasValue="+"+exposureBiasValue;

//确定曝光程序模式
exposureProgramArray = ["未定义",
	"Manual",
	"Normal Program",
	"Aperture Priority",
	"Shutter Priority",
	"Creative Program",
	"Action Program",
	"Portrait Mode",
	"Landscape Mode"];
exposureProgram = exposureProgramArray[exposureProgram];

//检查闪光模式
dateArray1 = fired;
if(dateArray1.indexOf("True")!=-1)
	fired="FlashOn";
else
	fired="FlashOff";


//检查焦距
dateArray1 = focalLength.split("/");
i = dateArray1[0];
j = dateArray1[1];

focalLength=parseInt(i/j);




//改变日期格式
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[dateArray2[1]-1]+"-"+dateArray2[2];
dateArray2 = phoTime.split("+");
phoTime = dateArray2[0];

//你有什么镜头,就根据镜头和最大焦距改吧

if(lens != "") {
	if(lens.indexOf("17.0-40.0 mm")!=-1)
		lensUsed = "Canon 17-40mm F4L USM"; 
}
//如果没有镜头信息,就使用原来的办法比较
else {
	var focLength=parseInt(focalLength);
	lensUsed="18-55mm 1: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"; 
}

//画线和框
//定义黑色,你也可以定义其他颜色哟
black = new SolidColor(); 
black.rgb.red = black.rgb.green = black.rgb.blue = 0; 

//定义白色,你也可以定义其他颜色哟
white = new SolidColor(); 
white.rgb.red = white.rgb.green = white.rgb.blue = 255; 

//定义灰色,你也可以定义其他颜色哟
grey = new SolidColor(); 
grey.rgb.red = grey.rgb.green = grey.rgb.blue = 50; 

//加入一条白线
backgroundColor = white; 

//如果改为黑线
//backgroundColor = black; 

//白线宽窄设为2或4,两边,实际宽度除以2
AD.resizeCanvas(AD.width.value+2,AD.height.value+2,AnchorPosition.MIDDLECENTER); 

//加入灰框
//backgroundColor = grey; 

//加入黑框
backgroundColor = black; 

//如果改为白框
//backgroundColor = white; 

//边框宽度和高度,这里将黑框宽窄设为图片宽度的1/40,两边,实际宽度再除以2
fWidth = parseInt(photoWidth/40);
fHight = parseInt(photoWidth/40);

//加框
AD.resizeCanvas(AD.width.value+fWidth,AD.height.value+fHight, AnchorPosition.MIDDLECENTER); 

//底部再加宽点,便于写字
AD.resizeCanvas(AD.width.value,AD.height.value+fHight+fHight+fHight,AnchorPosition.TOPCENTER); 


//标字和参数 
nameLayer = AD.artLayers.add(); 
nameLayer.kind = LayerKind.TEXT; 
TN = nameLayer.textItem; 

TN.contents = creator;

//版权字体、字号、颜色和加粗等 
TN.font = "STXingkai"; 

//右对齐
TN.justification = Justification.RIGHT;

//字号
tSize = parseInt((fWidth+10)/2);

//字体左边距和下边距
tLeft = photoWidth;
tHight = photoHight-fHight+tSize;

//标字的位置
TN.position = [tLeft,tHight];

TN.size = tSize+4; 
TN.color = white; 

//如果为白框,字体为黑色
//TN.color = black; 

TN.fauxBold = true; 

infoLayer = AD.artLayers.add(); 
infoLayer.kind = LayerKind.TEXT; 
TI = infoLayer.textItem; 

//右对齐,如果左对齐可以省略下面这行
TI.justification = Justification.RIGHT;

tHight = photoHight+fHight+tSize;

//标字的位置
TI.position = [tLeft,tHight];

//显示:相机型号,镜头,焦距,曝光时间,光圈,ISO设置,拍摄日期等

TI.contents = camera+", "+lensUsed+" @"+focalLength+"mm,"+exposureTime+"Sec,F/";
TI.contents = TI.contents+fNumber+", EV "+exposureBiasValue+ISOSpeedRatings;
//如果对曝光程式不感兴趣,请去掉下面行
TI.contents = TI.contents+", "+exposureProgram+", "+fired;
TI.contents = TI.contents+"\u000D"+phoDate+" "+phoTime;

//字体、字号、颜色等 
TI.font = "黑体"; 
//TI.font = "Arial"; 

TI.size = tSize; 
TI.color = white; 

//如果为白框,字体为黑色
//TI.color = black; 

TI.fauxBold = true;

AD.flatten(); 

//-------------
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? Mar 22, 2024 am 08:06 AM

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the &quot;My&quot; button in the lower right corner; (2) On the personal center page, find &quot;Settings&quot; and click it; (3) Scroll down and find the &quot;Clear Cache&quot; option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

How to post pictures in TikTok comments? Where is the entrance to the pictures in the comment area? How to post pictures in TikTok comments? Where is the entrance to the pictures in the comment area? Mar 21, 2024 pm 09:12 PM

With the popularity of Douyin short videos, user interactions in the comment area have become more colorful. Some users wish to share images in comments to better express their opinions or emotions. So, how to post pictures in TikTok comments? This article will answer this question in detail and provide you with some related tips and precautions. 1. How to post pictures in Douyin comments? 1. Open Douyin: First, you need to open Douyin APP and log in to your account. 2. Find the comment area: When browsing or posting a short video, find the place where you want to comment and click the &quot;Comment&quot; button. 3. Enter your comment content: Enter your comment content in the comment area. 4. Choose to send a picture: In the interface for entering comment content, you will see a &quot;picture&quot; button or a &quot;+&quot; button, click

6 Ways to Make Pictures Sharper on iPhone 6 Ways to Make Pictures Sharper on iPhone Mar 04, 2024 pm 06:25 PM

Apple's recent iPhones capture memories with crisp detail, saturation and brightness. But sometimes, you may encounter some issues that may cause the image to look less clear. While autofocus on iPhone cameras has come a long way, allowing you to take photos quickly, the camera can mistakenly focus on the wrong subject in certain situations, making the photo blurry in unwanted areas. If your photos on your iPhone look out of focus or lack sharpness overall, the following post should help you make them sharper. How to Make Pictures Clearer on iPhone [6 Methods] You can try using the native Photos app to clean up your photos. If you want more features and options

How to make ppt pictures appear one by one How to make ppt pictures appear one by one Mar 25, 2024 pm 04:00 PM

In PowerPoint, it is a common technique to display pictures one by one, which can be achieved by setting animation effects. This guide details the steps to implement this technique, including basic setup, image insertion, adding animation, and adjusting animation order and timing. Additionally, advanced settings and adjustments are provided, such as using triggers, adjusting animation speed and order, and previewing animation effects. By following these steps and tips, users can easily set up pictures to appear one after another in PowerPoint, thereby enhancing the visual impact of the presentation and grabbing the attention of the audience.

How to convert pdf documents into jpg images with Foxit PDF Reader - How to convert pdf documents into jpg images with Foxit PDF Reader How to convert pdf documents into jpg images with Foxit PDF Reader - How to convert pdf documents into jpg images with Foxit PDF Reader Mar 04, 2024 pm 05:49 PM

Are you also using Foxit PDF Reader software? So do you know how Foxit PDF Reader converts pdf documents into jpg images? The following article brings you how Foxit PDF Reader converts pdf documents into jpg images. For those who are interested in the method of converting jpg images, please come and take a look below. First start Foxit PDF Reader, then find "Features" on the top toolbar, and then select the "PDF to Others" function. Next, open a web page called "Foxit PDF Online Conversion". Click the "Login" button on the upper right side of the page to log in, and then turn on the "PDF to Image" function. Then click the upload button and add the pdf file you want to convert into an image. After adding it, click "Start Conversion"

How to use HTML, CSS and jQuery to implement advanced functions of image merging and display How to use HTML, CSS and jQuery to implement advanced functions of image merging and display Oct 27, 2023 pm 04:36 PM

Overview of advanced functions of how to use HTML, CSS and jQuery to implement image merge display: In web design, image display is an important link, and image merge display is one of the common techniques to improve page loading speed and enhance user experience. This article will introduce how to use HTML, CSS and jQuery to implement advanced functions of image merging and display, and provide specific code examples. 1. HTML layout: First, we need to create a container in HTML to display the merged images. You can use di

How to use JavaScript to implement the drag and zoom function of images? How to use JavaScript to implement the drag and zoom function of images? Oct 27, 2023 am 09:39 AM

How to use JavaScript to implement the drag and zoom function of images? In modern web development, dragging and zooming images is a common requirement. By using JavaScript, we can easily add dragging and zooming functions to images to provide a better user experience. In this article, we will introduce how to use JavaScript to implement this function, with specific code examples. HTML structure First, we need a basic HTML structure to display pictures and add

What should I do if the images on the webpage cannot be loaded? 6 solutions What should I do if the images on the webpage cannot be loaded? 6 solutions Mar 15, 2024 am 10:30 AM

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

See all articles