# @ginpei/exif-orientation 中文文档

规范地址：https://npmcn.com/package/%40ginpei/exif-orientation/

版本：1\.2\.0
npm 元数据更新时间：2022-10-22T07:36:26.045Z
中文译文更新时间：2026-11-16T09:12:13.564Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ginpei/exif-orientation
原文对照：https://npmcn.com/package/%40ginpei/exif-orientation/?lang=original
项目主页：https://github.com/ginpei/exif-orientation#readme
源码仓库：https://github.com/ginpei/exif-orientation

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：42.8 kB，7 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2019-01-03T08:23:18.787Z
- 最新版本发布：2022-10-22T07:36:25.982Z
- 近 30 天下载量：11656（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 0 个）

## 中文简介

从 JPEG 文件检测 Exif 方向数据

## 安装

```sh
npm install @ginpei/exif-orientation
```

也可以使用：`pnpm add @ginpei/exif-orientation`、`yarn add @ginpei/exif-orientation`、`bun add @ginpei/exif-orientation`

## README

# 流亡定向

[![Build Status](https://travis-ci.org/ginpei/exif-orientation.svg?branch=master)](https://travis-ci.org/ginpei/exif-orientation) [![Greenkeeper badge](https://badges.greenkeeper.io/ginpei/exif-orientation.svg)](https://greenkeeper.io/) [![Maintainability](https://api.codeclimate.com/v1/badges/022850f0f474ca642afe/maintainability)](https://codeclimate.com/github/ginpei/exif-orientation/maintainability)

从Exif-ed JPEG或更新取向代码获取取向(旋转和翻转)信息.

## 使用量

```
npm install @ginpei/exif-orientation
```

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

const orientation = await exif.getOrientation(fileOrBuffer);
console.log(
  `${orientation.rotation} degree,`,
  orientation.flipped ? 'flipped' : 'not flipped',
);
```

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

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

## 实例

见 [https://github.com/ginpei/exif-定向-实例](https://github.com/ginpei/exif-orientation-example)。 。 。 .

### 读取文件从 `<input type="file">`

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

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

### 读取文件从 `fs.readFile()`

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

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

## API 参考文献

### 导入

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

此软件包没有 `default`。 。 。 .

要导入类型脚本, 您需要设置 `moduleResolution` 选项。 详见下方的QQA部分.

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

-   `input: File | Buffer | ArrayBuffer` : JPEG 文件数据.

如果输入不是带有 Exif 方向信息的 JPEG 文件, 则返回 `undefined`。 。 。 .

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

-   `input: File | Buffer | ArrayBuffer` : JPEG 文件数据.
-   `orientation: OrientationCode` : 方向号.

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

-   `input: File | Buffer | ArrayBuffer` : JPEG 文件数据.

### `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`

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

## Q&A

## 埃西夫吗?

Exif是JPEG图像文件中的一种数据格式. 它可以包含旋转和翻转信息.

如果您看到一个图像的旋转异常,它可能是由于这个Exif取向信息的逻辑缺失而导致的.

-   [Exif - 维基百科](https://en.wikipedia.org/wiki/Exif)

遵循PDF文件(日文)确实有助于实施. 谢谢!

-   [— DC-008-2012 J.pdf (英语)](http://www.cipa.jp/std/documents/j/DC-008-2012_J.pdf)

### 找不到模块“ @ ginpei/ exif- 定向 ”

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

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


Found 1 error.
```

你必须设定 `moduleResolution` 无论是哪种方式:

-   单位 `tsconfig.json`数字 : `"moduleResolution": "node"`
-   从CLI: `--moduleResolution node`

见:

-   [编译器选项 · 类型脚本](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

## 历史

-   2021-10-22: v1.2.0 (中文(简体) )
    -   #20 支持包含非Exif的APP1图像( Marcello Bastéa-Forte@marcello3d)
    -   #22 支持包含 Exif 的图像而不导向
-   2020-07-13: v1.1.0 (中文(简体) )
    -   添加 `updateOrientationCode()` (托尼·布罗布斯顿) [@ 托尼·布罗布斯顿](https://github.com/TonyBrobston)(中文(简体) )
-   2019-01-06: v1.0.0 (中文(简体) )
    -   第一版发布

## 许可证

-   MIT 许可证

## 联系人

-   由银平公司制作
-   GitHub : (中文(简体) ) [国北](https://github.com/ginpei/)编号 :[前妻定向](https://github.com/ginpei/exif-orientation)
-   微博: [@ ginpei en (中文(简体) )](https://twitter.com/ginpei_en)

## 常见问题

### @ginpei/exif-orientation 是什么？

从 JPEG 文件检测 Exif 方向数据

### 如何安装 @ginpei/exif-orientation？

在项目目录运行 npm install @ginpei/exif-orientation，或使用 pnpm add / yarn add / bun add。

### @ginpei/exif-orientation 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @ginpei/exif-orientation 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @ginpei/exif-orientation 可以商用吗？

@ginpei/exif-orientation 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @ginpei/exif-orientation 的下载量有多少？

根据 npm 官方下载统计，@ginpei/exif-orientation 在 2026/10/17 – 2026/11/15 这 30 天内被下载 11,656 次，日均约 389 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @ginpei/exif-orientation 还在维护吗？

最新版本 1\.2\.0 发布于 2022/10/22（4 年前）；至今共发布 5 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/01/03。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

