diff --git a/types/jpeg-autorotate/index.d.ts b/types/jpeg-autorotate/index.d.ts new file mode 100644 index 0000000000..d0b50c43ec --- /dev/null +++ b/types/jpeg-autorotate/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for jpeg-autorotate 4.0 +// Project: https://github.com/johansatge/jpeg-autorotate#readme +// Definitions by: Slessi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/// + +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; diff --git a/types/jpeg-autorotate/jpeg-autorotate-tests.ts b/types/jpeg-autorotate/jpeg-autorotate-tests.ts new file mode 100644 index 0000000000..cdebb1a022 --- /dev/null +++ b/types/jpeg-autorotate/jpeg-autorotate-tests.ts @@ -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); + } +}); diff --git a/types/jpeg-autorotate/tsconfig.json b/types/jpeg-autorotate/tsconfig.json new file mode 100644 index 0000000000..da799d04ba --- /dev/null +++ b/types/jpeg-autorotate/tsconfig.json @@ -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" + ] +} diff --git a/types/jpeg-autorotate/tslint.json b/types/jpeg-autorotate/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/jpeg-autorotate/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }