我正在尝试使用Google脚本从位于我的Google云端硬盘文件夹中的几个jpeg文件中提取EXIF数据。
更准确地说,我想提取照片的拍摄日期以及以前使用Adobe Lightroom创建的相关关键字/图像描述。
我知道互联网上存在几种允许从文件中提取EXIF数据的脚本,但是我没有设法链接它们,也没有将它们与我自己的Google脚本一起使用。
我如何轻松做到这一点?
(我是Google Script的初学者,请尽可能精确)
先感谢您
最佳答案
Google Apps脚本的DriveApp服务不提供对所需详细信息的访问,但Advance Drive Service提供。
代码
您将需要启用Advanced Drive服务following instructions here。
// Demo use of getPhotoExif()
// Logs all files in a folder named "Photos".
function listPhotos() {
var files = DriveApp.getFoldersByName("Photos").next().getFiles();
var fileInfo = [];
while (files.hasNext()) {
var file = files.next();
Logger.log("File: %s, Date taken: %s",
file.getName(),
getPhotoExif(file.getId()).date || 'unknown');
}
}
/**
* Retrieve imageMediaMetadata for given file. See Files resource
* representation for details.
* (https://developers.google.com/drive/v2/reference/files)
*
* @param {String} fileId File ID to look up
*
* @returns {object} imageMediaMetadata object
*/
function getPhotoExif( fileId ) {
var file = Drive.Files.get(fileId);
var metaData = file.imageMediaMetadata;
// If metaData is 'undefined', return an empty object
return metaData ? metaData : {};
}
在Google Drive API中,文件的resource representation包含EXIF数据的属性:
"imageMediaMetadata": {
"width": integer,
"height": integer,
"rotation": integer,
"location": {
"latitude": double,
"longitude": double,
"altitude": double
},
"date": string,
"cameraMake": string,
"cameraModel": string,
"exposureTime": float,
"aperture": float,
"flashUsed": boolean,
"focalLength": float,
"isoSpeed": integer,
"meteringMode": string,
"sensor": string,
"exposureMode": string,
"colorSpace": string,
"whiteBalance": string,
"exposureBias": float,
"maxApertureValue": float,
"subjectDistance": integer,
"lens": string
},
关于google-apps-script - 如何从云端硬盘中的jpeg文件中提取EXIF数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30582284/