mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-30 11:14:27 +08:00
@@ -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));
|
||||
});
|
||||
});
|
||||
Vendored
+24
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user