流亡定向
从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.originalOrientationCode.deg90OrientationCode.deg180OrientationCode.deg270OrientationCode.flippedOrientationCode.deg90FlippedOrientationCode.deg180FlippedOrientationCode.deg270FlippedOrientationCode.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 (中文(简体) )
- 添加
updateOrientationCode()(托尼·布罗布斯顿) @ 托尼·布罗布斯顿(中文(简体) )
- 添加
- 2019-01-06: v1.0.0 (中文(简体) )
- 第一版发布
许可证
- MIT 许可证
联系人
- 由银平公司制作
- GitHub : (中文(简体) ) 国北编号 :前妻定向
- 微博: @ ginpei en (中文(简体) )