![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
exif-js
Advanced tools
Package description
The exif-js npm package is a JavaScript library that allows you to extract EXIF (Exchangeable Image File Format) metadata from image files. This metadata can include information such as the camera model, exposure time, GPS location, and more.
Extract EXIF Data
This feature allows you to extract all EXIF metadata from an image file. The code reads an image file and uses the `getData` method to extract the metadata, which is then logged to the console.
const EXIF = require('exif-js');
const fs = require('fs');
fs.readFile('path/to/image.jpg', (err, data) => {
if (err) throw err;
EXIF.getData(data, function() {
const allMetaData = EXIF.getAllTags(this);
console.log(allMetaData);
});
});
Get Specific EXIF Tag
This feature allows you to extract a specific EXIF tag from an image file. The code reads an image file and uses the `getTag` method to extract the 'Make' tag, which is then logged to the console.
const EXIF = require('exif-js');
const fs = require('fs');
fs.readFile('path/to/image.jpg', (err, data) => {
if (err) throw err;
EXIF.getData(data, function() {
const make = EXIF.getTag(this, 'Make');
console.log('Camera Make: ' + make);
});
});
Get GPS Data
This feature allows you to extract GPS data from an image file. The code reads an image file and uses the `getTag` method to extract the 'GPSLatitude' and 'GPSLongitude' tags, which are then logged to the console.
const EXIF = require('exif-js');
const fs = require('fs');
fs.readFile('path/to/image.jpg', (err, data) => {
if (err) throw err;
EXIF.getData(data, function() {
const gpsData = {
latitude: EXIF.getTag(this, 'GPSLatitude'),
longitude: EXIF.getTag(this, 'GPSLongitude')
};
console.log('GPS Data: ', gpsData);
});
});
piexifjs is a JavaScript library for reading and writing EXIF metadata in JPEG images. Unlike exif-js, which focuses on reading EXIF data, piexifjs also allows you to modify and write EXIF data back to the image.
exifr is a modern JavaScript library for reading EXIF, IPTC, and XMP metadata from image files. It supports a wider range of metadata formats compared to exif-js and is optimized for performance.
jpeg-js is a pure JavaScript library for decoding and encoding JPEG images. While it does not focus specifically on EXIF metadata, it can be used in conjunction with other libraries to handle image data and metadata.
Readme
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 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>
Note: This repo has no .min.js
. Do your own minification if you want that.
If you prefer another package manager you will probably manage :D. Or you can clone this GIT repository or download it's ZIP file and extract exif.js
to your project.
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:
<img src="image.jpg">
<file type="input">
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></div>
<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.
Please refer to the source code for more advanced usages such as getting image data from a File/Blob object (EXIF.readFromBinaryFile
).
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.
FAQs
JavaScript library for reading EXIF image metadata
The npm package exif-js receives a total of 116,616 weekly downloads. As such, exif-js popularity was classified as popular.
We found that exif-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.