@11ways/exiv2 中文文档教程

发布于 3年前 浏览 28 项目主页 更新于 3年前

Exiv2

Exiv2 是 node.js 的原生 C++ 扩展,它提供 支持通过 Exiv2 库 读取和写入图像元数据。

Dependencies

要构建此插件,您需要 Exiv2 库和标头,因此如果您使用 一个包管理器,你可能需要安装一个额外的“-dev”包。

Debian

apt-get install libexiv2 libexiv2-dev

OS X

您还需要安装 pkg-config 以帮助找到库和标头。

MacPorts

port install pkgconfig exiv2

Homebrew

brew install pkg-config exiv2

Other systems

参见 Exiv2 下载页面 了解更多 信息。

Installation Instructions

一旦依赖关系到位,您就可以使用构建和安装模块 npm:

npm install exiv2

您可以通过运行来验证所有内容是否已正确安装和运行 测试:

npm test

Sample Usage

Read tags:

var ex = require('exiv2');

ex.getImageTags('./photo.jpg', function(err, tags) {
  console.log("DateTime: " + tags["Exif.Image.DateTime"]);
  console.log("DateTimeOriginal: " + tags["Exif.Photo.DateTimeOriginal"]);
});

Load preview images:

var ex = require('exiv2')
  , fs = require('fs');

ex.getImagePreviews('./photo.jpg', function(err, previews) {
  // Display information about the previews.
  console.log(previews);

  // Or you can save them--though you'll probably want to check the MIME
  // type before picking an extension.
  fs.writeFile('preview.jpg', previews[0].data);
});

Write tags:

var ex = require('exiv2')

var newTags = {
  "Exif.Photo.UserComment" : "Some Comment..",
  "Exif.Canon.OwnerName" : "My Camera"
};
ex.setImageTags('./photo.jpg', newTags, function(err){
  if (err) {
    console.log(err);
  } else {
    console.log("setImageTags complete..");
  }
});

查看 examples/test/ 目录了解更多信息。

电子邮件:gmail 的 dberesford 推特:@dberesford

Exiv2

Exiv2 is a native c++ extension for node.js that provides support for reading and writing image metadata via the Exiv2 library.

Dependencies

To build this addon you'll need the Exiv2 library and headers so if you're using a package manager you might need to install an additional "-dev" packages.

Debian

apt-get install libexiv2 libexiv2-dev

OS X

You'll also need to install pkg-config to help locate the library and headers.

MacPorts:

port install pkgconfig exiv2

Homebrew:

brew install pkg-config exiv2

Other systems

See the Exiv2 download page for more information.

Installation Instructions

Once the dependencies are in place, you can build and install the module using npm:

npm install exiv2

You can verify that everything is installed and operating correctly by running the tests:

npm test

Sample Usage

Read tags:

var ex = require('exiv2');

ex.getImageTags('./photo.jpg', function(err, tags) {
  console.log("DateTime: " + tags["Exif.Image.DateTime"]);
  console.log("DateTimeOriginal: " + tags["Exif.Photo.DateTimeOriginal"]);
});

Load preview images:

var ex = require('exiv2')
  , fs = require('fs');

ex.getImagePreviews('./photo.jpg', function(err, previews) {
  // Display information about the previews.
  console.log(previews);

  // Or you can save them--though you'll probably want to check the MIME
  // type before picking an extension.
  fs.writeFile('preview.jpg', previews[0].data);
});

Write tags:

var ex = require('exiv2')

var newTags = {
  "Exif.Photo.UserComment" : "Some Comment..",
  "Exif.Canon.OwnerName" : "My Camera"
};
ex.setImageTags('./photo.jpg', newTags, function(err){
  if (err) {
    console.log(err);
  } else {
    console.log("setImageTags complete..");
  }
});

Take a look at the examples/ and test/ directories for more.

email: dberesford at gmail twitter: @dberesford

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文