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

@ginpei/exif-orientation

v1.2.0

Published

Detect Exif orientation data from JPEG file

Downloads

7,085

Readme

Exif orientation

Build Status Greenkeeper badge Maintainability

Get orientation (rotation and flipping) info from Exif-ed JPEG or Update orientation code.

Usage

npm install @ginpei/exif-orientation
import * as exif from '@ginpei/exif-orientation';

const orientation = await exif.getOrientation(fileOrBuffer);
console.log(
  `${orientation.rotation} degree,`,
  orientation.flipped ? 'flipped' : 'not flipped',
);
import * as exif from '@ginpei/exif-orientation';

await exif.updateOrientationCode(fileOrBuffer, exif.OrientationCode.deg90Flipped);

Examples

See https://github.com/ginpei/exif-orientation-example.

Read file from <input type="file">

// get file accessor
const elFile = document.querySelector<HTMLInputElement>('#file');
const file = elFile.files[0];

// get orientation
const orientation = await exif.getOrientation(file);

Read file from fs.readFile()

// read file as buffer
const buffer = fs.readFileSync(path);

// get orientation
const orientation = await exif.getOrientation(buffer);

API References

import

import * as exif from '@ginpei/exif-orientation';

This package does not have default.

To import in TypeScript, you need to set moduleResolution option. Find detail in Q&A section below.

function getOrientation(input: File | Buffer | ArrayBuffer): Promise<IOrientationInfo | undefined>

  • input: File | Buffer | ArrayBuffer : JPEG file data.

If the input is not JPEG file with Exif containing orientation information, it returns undefined.

function updateOrientationCode (input: File | Buffer | ArrayBuffer, orientation: OrientationCode): Promise<void>

  • input: File | Buffer | ArrayBuffer : JPEG file data.
  • orientation: OrientationCode : Orientation number.

function readOrientationCode(input: File | Buffer | ArrayBuffer): Promise<OrientationCode>

  • input: File | Buffer | ArrayBuffer : JPEG file data.

enum OrientationCode

  • OrientationCode.original
  • OrientationCode.deg90
  • OrientationCode.deg180
  • OrientationCode.deg270
  • OrientationCode.flipped
  • OrientationCode.deg90Flipped
  • OrientationCode.deg180Flipped
  • OrientationCode.deg270Flipped
  • OrientationCode.unknown

function getOrientationInfo(orientation: OrientationCode): IOrientationInfo | undefined

  • orientation: OrientationCode

interface IOrientationInfo

interface IOrientationInfo {
  rotation: number;
  flipped: boolean;
}

Q&A

Exif?

Exif is a kind of data format inside JPEG image file. It can contain rotation and flipping information.

If you see an image rotated weirdly, it might be caused by lacking logic for this Exif orientation information.

Following PDF file (Japanese) really helped to implement. Thanks!

Cannot find module '@ginpei/exif-orientation'

src/index.ts:1:23 - error TS2307: Cannot find module '@ginpei/exif-orientation'.

1 import * as exif from '@ginpei/exif-orientation';
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

You have to set moduleResolution in either way:

  • In tsconfig.json: "moduleResolution": "node"
  • From CLI: --moduleResolution node

See:

History

  • 2021-10-22: v1.2.0
    • #20 Support images containing APP1 that is not Exif (Marcello Bastéa-Forte @marcello3d)
    • #22 Support images containing Exif without orientation
  • 2020-07-13: v1.1.0
  • 2019-01-06: v1.0.0
    • First Release

License

  • MIT License

Contact