如何从 Drive 中的 jpeg 文件中提取 EXIF 数据 [英] How to extract EXIF data from jpeg files in Drive

查看:19
本文介绍了如何从 Drive 中的 jpeg 文件中提取 EXIF 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Google Script 从位于我的 Google Drive 文件夹之一的多个 jpeg 文件中提取 EXIF 数据.

I am trying to extract EXIF data from several jpeg files located in one of my Google Drive folders, using a Google Script.

更准确地说,我想提取照片的拍摄日期,以及之前使用 Adob​​e Lightroom 创建的图像的相关关键字/描述.

More accurately, I would like to extract the date at which the photo was taken, together with associated keywords / description of the image, previously created with Adobe Lightroom.

我知道互联网上存在多个允许从文件中提取 EXIF 数据的脚本,但我没有设法链接它们,或者将它们与我自己的 Google 脚本一起使用.

I know that several scripts allowing to extract EXIF data from a file exist on internet, but I didn't manage to link them, or to use them with my own Google script.

我怎样才能轻松做到这一点?(我是 Google Script 初学者,请尽量准确)

How can I do that easily ? (I am a beginner on Google Script, please be as precise as possible)

提前致谢

推荐答案

Google Apps Script 的 DriveApp 服务无法访问您要查找的详细信息,但 Advance Drive 服务可以.

The DriveApp service of Google Apps Script doesn't provide access to the details you're looking for, but the Advance Drive Service does.

您需要启用高级云端硬盘服务,按照此处的说明操作.

You will need to enable the Advanced Drive service, 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 中,文件的资源表示包括属性对于 EXIF 数据:

In the Google Drive API, the resource representation for a File includes properties for the EXIF data:

  "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
  },

这篇关于如何从 Drive 中的 jpeg 文件中提取 EXIF 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆