@ginpei/exif-orientation

中文文档
1.2.0发布于 2022/10/22MITTypeScriptCommonJS零依赖近 30 天下载 1.2万

从 JPEG 文件检测 Exif 方向数据

中文使用文档
文档目录18 节
  1. 使用量
  2. 实例
  3. 读取文件从 <input type="file">
  4. 读取文件从 fs.readFile()
  5. API 参考文献
  6. 导入
  7. function getOrientation(input: File | Buffer | ArrayBuffer)…
  8. function updateOrientationCode (input: File | Buffer | Arra…
  9. function readOrientationCode(input: File | Buffer | ArrayBu…
  10. enum OrientationCode
  11. function getOrientationInfo(orientation: OrientationCode): …
  12. interface IOrientationInfo
  13. Q&A
  14. 埃西夫吗?
  15. 找不到模块“ @ ginpei/ exif- 定向 ”
  16. 历史
  17. 许可证
  18. 联系人

流亡定向

Build Status Greenkeeper badge Maintainability

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

使用量

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

实例

见 https://github.com/ginpei/exif-定向-实例。 。 。 .

读取文件从 <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);

读取文件从 fs.readFile()

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

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

API 参考文献

导入

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

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

Q&A

埃西夫吗?

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

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

遵循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

见:

历史

  • 2021-10-22: v1.2.0 (中文(简体) )
    • #20 支持包含非Exif的APP1图像( Marcello Bastéa-Forte@marcello3d)
    • #22 支持包含 Exif 的图像而不导向
  • 2020-07-13: v1.1.0 (中文(简体) )
  • 2019-01-06: v1.0.0 (中文(简体) )
    • 第一版发布

许可证

  • MIT 许可证

联系人

版本与发布记录

@ginpei/exif-orientation 共发布 5 个版本,首次发布于 2019/01/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2022/10/224 年前
1.1.02020/07/146 年前
1.0.02019/01/067 年前
0.0.22019/01/037 年前
0.0.12019/01/037 年前

关于 @ginpei/exif-orientation 的常见问题

@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 和提交记录判断。