Merge pull request #31541 from Slessi/jpeg-autorotate

Types for jpeg-autorotate
This commit is contained in:
Nathan Shively-Sanders 2018-12-19 10:25:50 -08:00 committed by GitHub
commit aa91ccd564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 0 deletions

31
types/jpeg-autorotate/index.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
// Type definitions for jpeg-autorotate 4.0
// Project: https://github.com/johansatge/jpeg-autorotate#readme
// Definitions by: Slessi <https://github.com/Slessi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="node" />
export enum errors {
read_file = "read_file",
read_exif = "read_exif",
no_orientation = "no_orientation",
unknown_orientation = "unknown_orientation",
correct_orientation = "correct_orientation",
rotate_file = "rotate_file",
}
export interface CustomError extends Error {
code: errors;
}
export function rotate(
path_or_buffer: string | Buffer,
options?: { quality?: number },
module_callback?: (
error: CustomError | null,
buffer: Buffer | null,
orientation: number | null,
dimensions: { height: number; width: number } | null,
) => void,
): void;

View File

@ -0,0 +1,23 @@
import * as jo from "jpeg-autorotate";
jo.rotate("img.jpg");
jo.rotate(new Buffer(""));
jo.rotate(new Buffer(""), { quality: 50 });
jo.rotate("img.jpg", { quality: 100 }, (error, buffer, orientation, dimensions) => {
if (error && error.code === jo.errors.correct_orientation) {
console.log("The orientation of this image is already correct!");
}
if (orientation) {
console.log("Orientation was: " + orientation);
}
if (dimensions) {
console.log("Height after rotation: " + dimensions.height);
console.log("Width after rotation: " + dimensions.width);
}
if (buffer) {
buffer.readInt8(0);
}
});

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"jpeg-autorotate-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }