• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

exif-js/exif-js: JavaScript library for reading EXIF image metadata

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

exif-js/exif-js

开源软件地址:

https://github.com/exif-js/exif-js

开源编程语言:

JavaScript 64.9%

开源软件介绍:

Exif.js

A JavaScript library for reading EXIF meta data from image files.

You can use it on images in the browser, either from an image or a file input element. Both EXIF and IPTC metadata are retrieved. This package can also be used in AMD or CommonJS environments.

Note: The EXIF standard applies only to .jpg and .tiff images. EXIF logic in this package is based on the EXIF standard v2.2 (JEITA CP-3451, included in this repo).

Install

Install exif-js through NPM:

npm install exif-js --save    

Or Bower:

bower install exif-js --save

Then add a script tag in your an HTML in the best position referencing your local file.

<script src="vendors/exif-js/exif-js"></script>

You can also use a minified version hosted on jsDelivr

<script src="https://cdn.jsdelivr.net/npm/exif-js"></script>

Usage

The package adds a global EXIF variable (or AMD or CommonJS equivalent).

Start with calling the EXIF.getData function. You pass it an image as a parameter:

  • either an image from a <img src="image.jpg">
  • OR a user selected image in a <input type="file"> element on your page.

As a second parameter you specify a callback function. In the callback function you should use this to access the image with the aforementioned metadata you can then use as you want. That image now has an extra exifdata property which is a Javascript object with the EXIF metadata. You can access it's properties to get data like the image caption, the date a photo was taken or it's orientation.

You can get all tages with EXIF.getTag. Or get a single tag with EXIF.getTag, where you specify the tag as the second parameter. The tag names to use are listed in EXIF.Tags in exif.js.

Important: Note that you have to wait for the image to be completely loaded, before calling getData or any other function. It will silently fail otherwise. You can implement this wait, by running your exif-extracting logic on the window.onLoad function. Or on an image's own onLoad function. For jQuery users please note that you can NOT (reliably) use jQuery's ready event for this. Because it fires before images are loaded. You could use $(window).load() instead of $(document.ready() (please note that `exif-js has NO dependency on jQuery or any other external library).

JavaScript:

window.onload=getExif;

function getExif() {
    var img1 = document.getElementById("img1");
    EXIF.getData(img1, function() {
        var make = EXIF.getTag(this, "Make");
        var model = EXIF.getTag(this, "Model");
        var makeAndModel = document.getElementById("makeAndModel");
        makeAndModel.innerHTML = `${make} ${model}`;
    });

    var img2 = document.getElementById("img2");
    EXIF.getData(img2, function() {
        var allMetaData = EXIF.getAllTags(this);
        var allMetaDataSpan = document.getElementById("allMetaDataSpan");
        allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, "\t");
    });
}

HTML:

<img src="image1.jpg" id="img1" />
<pre>Make and model: <span id="makeAndModel"></span></pre>
<br/>
<img src="image2.jpg" id="img2" />
<pre id="allMetaDataSpan"></pre>
<br/>

Note there are also alternate tags, such the EXIF.TiffTags. See the source code for the full definition and use. You can also get back a string with all the EXIF information in the image pretty printed by using EXIF.pretty. Check the included index.html.

XMP Since issue #53 was merged also extracting of XMP data is supported. To not slow down this is optional, and you need to call EXIF.enableXmp(); before using ..getDatat().

Please refer to the source code for more advanced usages such as getting image data from a File/Blob object (EXIF.readFromBinaryFile).

Contributions

This is an open source project. Please contribute by forking this repo and issueing a pull request. The project has had notable contributions already, like reading ITPC data.

You can also contribute by filing bugs or new features please issue. Or improve the documentation. Please update this README when you do a pull request of proposed changes in base functionality.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap