GithubHelp home page GithubHelp logo

kuboon / exif-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from exif-js/exif-js

0.0 0.0 0.0 2.04 MB

JavaScript library for reading EXIF image metadata

License: MIT License

HTML 1.52% TypeScript 66.51% JavaScript 31.97%

exif-js's Introduction

@kuboon/exif

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

This repo is forked from Exif.js but almost all codes are rewritten. There is no API compatibility with the original exif-js. (PullRequest of exif-js.compat.js is welcome.)

Overview

frontend module

  • getArrayBufferFrom: Get ArrayBuffer from various sources.

exif module

Extracts EXIF metadata from JPEG ArrayBuffer, including 4 TagGroups: 'tiff', 'exif', 'gps', 'thumbnail' and thumbnailBlob.

  • getEXIFrawTagsInJPEG: Get raw EXIF data from ArrayBuffer of JPEG image. Includes 4 RawTagsGroup and a thumbnailBlob.
  • getEXIFenrichedTagsInJPEG: Add human-readable values to getEXIFrawTagsInJPEG.
  • getEXIFminimalTagsInJPEG: Get minimal EXIF tags from ArrayBuffer of JPEG image.
  • buildKeyValue: Build key-value object from minimal EXIF tags.

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).

@example Basic exif access by key-value

import { exif } from "@kuboon/exif";
const buf = await Deno.readFile("image.jpg");

// `tags` contains 4 groups: 'tiff', 'exif', 'gps', 'thumbnail'
const { tags, thumbnailBlob } = exif.getEXIFenrichedTagsInJPEG(buf)!;

// By default, 'tiff', 'exif', 'gps' TagGroup are all included.
const kv = exif.buildKeyValue(tags);
console.log(kv["DateTimeOriginal"]!.data);

@example Get 'thumbnail' key-value Because some tags like XResolution conflicts with tiff TagGroup, You can get 'thumbnail' TagGroup separately.

const kv = exif.buildKeyValue(tags, "thumbnail");
console.log(kv["XResolution"]!.data);

@example Low-level row access

import { exif } from "@kuboon/exif";
const buf = await Deno.readFile("image.jpg");
const { tags, thumbnailBlob } = exif.getEXIFenrichedTagsInJPEG(buf)!;
console.log(exif.getRow(tags, "exif", "DateTimeOriginal")!.data);

getIPTCinJPEG

Find "IPTC header" in jpeg binary and extract key-value pairs.

https://en.wikipedia.org/wiki/International_Press_Telecommunications_Council

getXMPinJPEG

Scan <?xpacket begin="?" id="W5M0MpCehiHzreSzNTczkc9d"?> in jpeg binary and return XML string. (Not parsed)

https://en.wikipedia.org/wiki/Extensible_Metadata_Platform

Install and use on server

Totally different from the original exif-js. see https://jsr.io/@kuboon/exif for more details.

Install @kuboon/exif through jsr.io.

# deno
deno add @kuboon/exif

# node.js
npx jsr add @kuboon/exif

For browser

You can import frontend module from esm.sh/jsr (not documented on released version yet, but it works).

getArrayBufferFrom accepts one of HTMLImageElement, HTMLInputElement (with type="file"), URL, url string, Blob (or File) and returns ArrayBuffer. Then you can do same as server side.

<script type="module">
  import { getArrayBufferFrom } from "https://esm.sh/jsr/@kuboon/[email protected]/frontend";
  import { exif } from "https://esm.sh/jsr/@kuboon/[email protected]?exports=exif";

  const fileInput = document.getElementById("file-input");
  fileInput.addEventListener("change", async (e) => {
    const buf = await getArrayBufferFrom(fileInput);
    const ret = exif.getEXIFminimalTagsInJPEG(buf);
    if (ret === null) {
      /** @type {FileList} */
      const files = e.target.files;
      alert("No EXIF data found in image '" + files[0].name + "'.");
      return;
    }
    const kv = exif.buildKeyValue(ret.tags);
    alert(JSON.stringify(kv, null, "\t"));
  });
</script>
<input type="file" id="file-input" />

Contributions

Please feel free to open an issue or submit a pull request. I'm happy to review and merge them (until I lose interest for this repo).

You need deno test for local testing. https://deno.com

exif-js's People

Contributors

kuboon avatar bartvanderwal avatar jseidelin avatar atotic avatar pugwonk avatar townxelliot avatar bokub avatar chrisbolin avatar keathley avatar danielbarela avatar dmarkow avatar freidemokrat avatar hiroyky avatar xerc avatar pducks32 avatar tinymins avatar tian-zhihui avatar joeblynch avatar joeweiss avatar pankus avatar weepy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.