npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@toriyama/exif-ts

v0.0.6

Published

Exif tool

Downloads

2

Readme

This is pre-release!

@toriyama/exif-ts

JPEG 画像に含まれる Exif 情報を取り出したり編集したりするツールです。

Installation

npm install @toriyama/exif-ts

Usage

使い方の大まかな流れは次のようになります。

  • ローカル/Web 上から画像を読み込み
  • タグ情報を抽出
  • タグ情報を編集
  • 編集した画像を保存

Load image

画像を読み込みExifオブジェクトを作成しましょう。 ExifコンストラクタはUint8Arrayを引数に取ります。

fs

fs.readFileを用いて画像ファイルを読み込む際は、Bufferが返るので、new Uint8Array()によって 8 ビット符号なし整数値配列に変換してください。

import fs from "fs/promises";
import { Exif } from "@toriyama/exif-ts";

(async () => {
	const buffer = await fs.readFile("/home/torichan/Pictures/roadbike.jpg");
	const exif = new Exif(new Uint8Array(buffer));
	console.log(exif.tags);
})();

axios

axiosを用いる場合はArrayBufferが返るので同様にUint8Arrayに変換する必要があります。

import axios from "axios";
import { Exif } from "@toriyama/exif-ts";

(async () => {
	const url =
		"https://yuukitoriyama.github.io/yorimichi-images/20210711/IMG_20210711_1607115.jpg";
	const response = await axios.get(url, {
		responseType: "arraybuffer",
	});
	const buffer = new Uint8Array(response.data);
	const exif = new Exif(new Uint8Array(buffer));
	console.log(exif.tags);
})();

以下ではExifオブジェクト付属のメソッド/プロパティについて解説します。

Locate marker

JPEG 画像(もとい Exif 画像)ではメタデータを保存するために種々のマーカーが定義されています。 Exif.locateはバイナリ中のマーカーの位置を調べるためのメソッドです。

const position = exif.locate(0xffd8); // SOI(Start of Image)の位置を調べる
console.log(position); // 0

Show exif tags

Exif.tagsプロパティにはバイナリを解析して抽出された Exif 情報が保存されています。

console.log(exif.tags);
{
  IFD0: [
    { tag: 272, format: [Object], value: 'QCAM-AA\x00' },
    { tag: 305, format: [Object], value: 'imx378-1\x00' },
    { tag: 306, format: [Object], value: '2021:07:11 16:07:11\x00' },
    { tag: 531, format: [Object], value: [Array] },
    { tag: 34665, format: [Object], value: [Array] },
    { tag: 296, format: [Object], value: [Array] },
    { tag: 34853, format: [Object], value: [Array] },
    { tag: 282, format: [Object], value: [Array] },
    { tag: 283, format: [Object], value: [Array] },
    { tag: 271, format: [Object], value: 'QCOM-AA\x00' }
  ],
  IFD1: [
    { tag: 513, format: [Object], value: [Array] },
    { tag: 514, format: [Object], value: [Array] }
  ],
  ExifSubIFD: [
    { tag: 34855, format: [Object], value: [Array] },
    { tag: 34850, format: [Object], value: [Array] },
    { tag: 33437, format: [Object], value: [Array] },
    { tag: 33434, format: [Object], value: [Array] },
    { tag: 41495, format: [Object], value: [Array] },
    { tag: 37522, format: [Object], value: '271369\x00' },
    { tag: 37521, format: [Object], value: '271369\x00' },
    { tag: 37520, format: [Object], value: '271369\x00' },
    { tag: 37386, format: [Object], value: [Array] },
    { tag: 37385, format: [Object], value: [Array] },
    { tag: 37383, format: [Object], value: [Array] },
    { tag: 41990, format: [Object], value: [Array] },
    { tag: 37510, format: [Object], value: [Uint8Array] },
    { tag: 40965, format: [Object], value: [Array] },
    { tag: 41989, format: [Object], value: [Array] },
    { tag: 36868, format: [Object], value: '2021:07:11 16:07:11\x00' },
    { tag: 37380, format: [Object], value: [Array] },
    { tag: 40963, format: [Object], value: [Array] },
    { tag: 41987, format: [Object], value: [Array] },
    { tag: 36867, format: [Object], value: '2021:07:11 16:07:11\x00' },
    { tag: 37379, format: [Object], value: [Array] },
    { tag: 40962, format: [Object], value: [Array] },
    { tag: 41986, format: [Object], value: [Array] },
    { tag: 37378, format: [Object], value: [Array] },
    { tag: 37121, format: [Object], value: [Uint8Array] },
    { tag: 40961, format: [Object], value: [Array] },
    { tag: 41729, format: [Object], value: [Uint8Array] },
    { tag: 37377, format: [Object], value: [Array] },
    { tag: 41985, format: [Object], value: [Array] },
    { tag: 36864, format: [Object], value: [Uint8Array] },
    { tag: 40960, format: [Object], value: [Uint8Array] }
  ],
  GPSIFD: [
    { tag: 1, format: [Object], value: 'N\x00\x00\x00' },
    { tag: 2, format: [Object], value: [Array] },
    { tag: 3, format: [Object], value: 'E\x00\x00\x00' },
    { tag: 4, format: [Object], value: [Array] },
    { tag: 5, format: [Object], value: [Array] },
    { tag: 6, format: [Object], value: [Array] },
    { tag: 7, format: [Object], value: [Array] },
    { tag: 27, format: [Object], value: 'ASCII\x00\x00\x00FUSED\x00' },
    { tag: 29, format: [Object], value: '2021:07:11\x00' }
  ]
}