search
HomeWeb Front-endJS TutorialJS script to automatically add borders and EXIF ​​information to pictures in PhotoShop_javascript skills

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(); 

//-------------

Statement
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
JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript: Exploring the Versatility of a Web LanguageJavaScript: Exploring the Versatility of a Web LanguageApr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The Evolution of JavaScript: Current Trends and Future ProspectsThe Evolution of JavaScript: Current Trends and Future ProspectsApr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Demystifying JavaScript: What It Does and Why It MattersDemystifying JavaScript: What It Does and Why It MattersApr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Is Python or JavaScript better?Is Python or JavaScript better?Apr 06, 2025 am 12:14 AM

Python is more suitable for data science and machine learning, while JavaScript is more suitable for front-end and full-stack development. 1. Python is known for its concise syntax and rich library ecosystem, and is suitable for data analysis and web development. 2. JavaScript is the core of front-end development. Node.js supports server-side programming and is suitable for full-stack development.

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)