From 1cc48fb3ae3e4cfe07ea19525e74ca61b52b9b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e=20Maurer?= Date: Tue, 23 Feb 2016 17:53:31 +0100 Subject: [PATCH] Add image-size.d.ts --- image-size/image-size-tests.ts | 28 ++++++++++++++++++++++++++++ image-size/image-size.d.ts | 24 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 image-size/image-size-tests.ts create mode 100644 image-size/image-size.d.ts diff --git a/image-size/image-size-tests.ts b/image-size/image-size-tests.ts new file mode 100644 index 000000000..0f9b29618 --- /dev/null +++ b/image-size/image-size-tests.ts @@ -0,0 +1,28 @@ +/// + +import * as url from "url"; +import * as http from "http"; +import * as sizeOf from "image-size"; + +// Synchronous +const dimensions = sizeOf("images/funny-cats.png"); +console.log(dimensions.width, dimensions.height); + +// Asynchronous +sizeOf("images/funny-cats.png", (err, dimensions) => { + console.log(dimensions.width, dimensions.height); +}); + +// From URL +const imgUrl = "http://my-amazing-website.com/image.jpeg"; +const options = url.parse(imgUrl); + +http.get(options, (response) => { + const chunks: Buffer[] = []; + response.on("data", (chunk: Buffer) => { + chunks.push(chunk); + }).on("end", () => { + const buffer = Buffer.concat(chunks); + console.log(sizeOf(buffer)); + }); +}); diff --git a/image-size/image-size.d.ts b/image-size/image-size.d.ts new file mode 100644 index 000000000..6b553630c --- /dev/null +++ b/image-size/image-size.d.ts @@ -0,0 +1,24 @@ +// Type definitions for image-size +// Project: https://github.com/image-size/image-size +// Definitions by: Elisée MAURER +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "image-size" { + + interface ImageInfo { + width: number; + height: number; + type: string; + } + + function sizeOf(path: string): ImageInfo; + function sizeOf(path: string, callback: (err: Error, dimensions: ImageInfo) => void): void; + + function sizeOf(buffer: Buffer): ImageInfo; + + namespace sizeOf {} + + export = sizeOf; +}