Merge pull request #8224 from elisee/image-size

Add image-size.d.ts
This commit is contained in:
Masahiro Wakame
2016-02-26 20:28:46 +09:00
2 changed files with 52 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
/// <reference path="image-size.d.ts" />
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));
});
});
+24
View File
@@ -0,0 +1,24 @@
// Type definitions for image-size
// Project: https://github.com/image-size/image-size
// Definitions by: Elisée MAURER <https://github.com/elisee/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
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;
}