google-apps-script - 如何从云端硬盘中的jpeg文件中提取EXIF数据

标签 google-apps-script google-drive-api

我正在尝试使用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/

相关文章:

google-apps-script - 返回基于单元格的命名范围的名称?

javascript - 如何使用正则表达式从字符串地址获取特定文本?

javascript - 如何将 UNIX 时间戳转换为 Google 表格日期值?

google-apps-script - Google 电子表格(在脚本中使用命名范围)

ios - 适用于 iOS 的 Google 云端硬盘 SDK : issue with queries

google-drive-api - 在 Google 云端硬盘文件共享上禁用自动生成的电子邮件

google-drive-api - 是否可以在不访问整个驱动器或使用驱动器应用程序的情况下访问单个谷歌驱动器文件?

google-apps-script - 谷歌应用程序脚本编辑器中的自动完成并不总是知道类型/上下文

android - 如何使用 REST API 从 Google Drive 下载公开共享的文件

javascript - 是否可以拥有一个单一的 Google Drive 帐户,许多用户可以从一个应用程序上传文件?