diff --git a/README.md b/README.md index 34cb3bd..0dae551 100644 --- a/README.md +++ b/README.md @@ -50,25 +50,25 @@ const options = { onProgress: Function, // optional, a function takes one progress argument (percentage from 0 to 100) useWebWorker: boolean, // optional, use multi-thread web worker, fallback to run in main-thread (default: true) - // following options are for advanced user + // following options are for advanced users maxIteration: number, // optional, max number of iteration to compress the image (default: 10) exifOrientation: number, // optional, see https://stackoverflow.com/a/32490603/10395024 fileType: string, // optional, fileType override initialQuality: number // optional, initial quality value between 0 and 1 (default: 1) } -imageCompression(file: File, options): Promise +imageCompression(file: File, options): Promise ``` ### Helper function ### -- for advanced user only, most user won't need to use the helper functions +- for advanced users only, most users won't need to use the helper functions ```javascript -imageCompression.getDataUrlFromFile(file: File | Blob): Promise +imageCompression.getDataUrlFromFile(file: File): Promise imageCompression.getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise imageCompression.loadImage(url: string): Promise imageCompression.drawImageInCanvas(img: HTMLImageElement): HTMLCanvasElement | OffscreenCanvas -imageCompression.drawFileInCanvas(file: File| Blob): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]> -imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise -imageCompression.getExifOrientation(file: File| Blob): Promise // based on https://stackoverflow.com/a/32490603/10395024 +imageCompression.drawFileInCanvas(file: File): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]> +imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise +imageCompression.getExifOrientation(file: File): Promise // based on https://stackoverflow.com/a/32490603/10395024 ``` ## Usage ## @@ -148,11 +148,7 @@ You can include the following script to load the Promise polyfill: ``` ## Typescript type definitions ## -``` -npm install --save-dev @types/browser-image-compression -or -yarn add --dev @types/browser-image-compression -``` +Typescript definitions are included in the package & referenced in the `types` section of the `package.json` ## Contribution ## 1. fork the repo and git clone it diff --git a/lib/index.d.ts b/lib/index.d.ts index 45b4d40..4885a2f 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for browser-image-compression 1.0 // Project: https://github.com/Donaldcwl/browser-image-compression -// Definitions by: Donald +// Definitions by: Donald & Jamie Haywood // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped interface Options { @@ -22,16 +22,16 @@ interface Options { initialQuality?: number; } -declare function imageCompression(image: File | Blob, options: Options): Promise; +declare function imageCompression(image: File, options: Options): Promise; declare namespace imageCompression { - function getDataUrlFromFile(file: File | Blob): Promise; - function getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise; + function getDataUrlFromFile(file: File): Promise; + function getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise; function loadImage(src: string): Promise; function drawImageInCanvas(img: HTMLImageElement): HTMLCanvasElement; - function drawFileInCanvas(file: File | Blob): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement]>; - function canvasToFile(canvas: HTMLCanvasElement, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise; - function getExifOrientation(file: File | Blob): Promise; + function drawFileInCanvas(file: File): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement]>; + function canvasToFile(canvas: HTMLCanvasElement, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise; + function getExifOrientation(file: File): Promise; } export as namespace imageCompression;