nodejs 第三方库 exiftool-vendored

exiftool-vendored 是一款可以帮助你快捷修改图片信息的第三方库。如果你想要批量修改图片信息的话,那么它是一个不错的选择。


1.导入第三方库

在控制台中执行下面代码即可。

npm install exiftool-vendored --save

2.获取信息

这里给出例子。

const { exiftool } = require('exiftool-vendored');

( async ()=>{
	const url=" The url of your image. ";
	const tags=await exiftool.read(url);
	exiftool.end();
	console.log(tags);
	return;
} )();

注意代码最后一定要有 exiftool.end() 这一语句,否则程序不会自己结束运行。


3.修改信息

这里以修改 FileName 属性为例。

const { exiftool } = require('exiftool-vendored');

( async ()=>{
	const url=" The url of your image. ";
	const config={"FileName":"NewFile.jpg"};
	await exiftool.write(url,config);
	exiftool.end();
	return;
} )();

如果需要修改其他的属性,可以根据查询数据得到的结果进行定向修改。

如果是要修改时间类型的数据的话,需要导入一个新类叫 ExifDateTime ,示例如下。

const { ExifDateTime } = require('exiftool-vendored');

const now=new Date();
const config=new ExifDateTime(
	now.getFullYear(), // year
	now.getMonth()+1, // month
	now.getDate(), // day
	now.getHours(), // hour
	now.getMinutes(), // minute
	now.getSeconds(), // second
	undefined, // millisecond
	undefined, // tzoffsetMinutes
	now.toLocaleString().replaceAll('/',':'), // rawValue 格式:YYYY:MM:DD HH:MM:SS
	undefined, // zoneName
	false, // inferredZone
);

在执行完 exiftool.write() 之后,如果使用的是默认选项,则会出现一个新文件,代表的是你的 修改前的文件。若不需要这个文件,就可以在执行时加入选项 -overwrite_original

示例:

await exiftool.write(url,{"DateTimeOriginal":config},['-overwrite_original']);
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值