mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add image quality options to blob-util (#20014)
* Add image quality options to blob-util * Remove unapplicable doc comment note from blob-util
This commit is contained in:
parent
2da08c2f7a
commit
189ef9638f
@ -5,6 +5,8 @@ const testBlob = new Blob(['abcd']);
|
||||
blobUtil.base64StringToBlob('abcd'); // $ExpectType Promise<Blob>
|
||||
blobUtil.createObjectURL(testBlob); // $ExpectType string
|
||||
blobUtil.imgSrcToBlob('test.jpg'); // $ExpectType Promise<Blob>
|
||||
blobUtil.imgSrcToBlob('http://some-other-site.com/img.jpg', 'image/jpeg', 'Anonymous', 1.0); // $ExpectType Promise<Blob>
|
||||
blobUtil.imgSrcToBlob('test.jpg', 'image/jpeg', undefined, 0.7); // $ExpectType Promise<Blob>
|
||||
blobUtil.createBlob(['abcd']); // $ExpectType Blob
|
||||
blobUtil.arrayBufferToBlob(new ArrayBuffer(0)); // $ExpectType Promise<Blob>
|
||||
blobUtil.binaryStringToBlob('0101'); // $ExpectType Promise<Blob>
|
||||
@ -12,7 +14,10 @@ blobUtil.blobToArrayBuffer(testBlob); // $ExpectType Promise<ArrayBuffer>
|
||||
blobUtil.blobToBase64String(testBlob); // $ExpectType Promise<string>
|
||||
blobUtil.blobToBinaryString(testBlob); // $ExpectType Promise<string>
|
||||
blobUtil.canvasToBlob(new HTMLCanvasElement()); // $ExpectType Promise<Blob>
|
||||
blobUtil.canvasToBlob(new HTMLCanvasElement(), 'image/webp'); // $ExpectType Promise<Blob>
|
||||
blobUtil.canvasToBlob(new HTMLCanvasElement(), 'image/webp', 0.8); // $ExpectType Promise<Blob>
|
||||
blobUtil.dataURLToBlob('data:abcd'); // $ExpectType Promise<Blob>
|
||||
blobUtil.blobToDataURL(testBlob); // $ExpectType Promise<string>
|
||||
blobUtil.imgSrcToDataURL('test.jpg'); // $ExpectType Promise<string>
|
||||
blobUtil.imgSrcToDataURL('http://some-other-site.com/img.jpg', 'image/jpeg', 'Anonymous', 1.0); // $ExpectType Promise<string>
|
||||
blobUtil.revokeObjectURL('blob:example'); // $ExpectType void
|
||||
|
||||
37
types/blob-util/index.d.ts
vendored
37
types/blob-util/index.d.ts
vendored
@ -13,8 +13,39 @@ export function blobToBase64String(blob: Blob): Promise<string>;
|
||||
export function base64StringToBlob(base64: string, type?: string): Promise<Blob>;
|
||||
export function dataURLToBlob(dataURL: string): Promise<Blob>;
|
||||
export function blobToDataURL(blob: Blob): Promise<string>;
|
||||
export function imgSrcToDataURL(src: string, type?: string, crossOrigin?: string): Promise<string>;
|
||||
export function canvasToBlob(canvas: HTMLCanvasElement, type?: string): Promise<Blob>;
|
||||
export function imgSrcToBlob(src: string, type?: string, crossOrigin?: string): Promise<Blob>;
|
||||
|
||||
/**
|
||||
* Convert an image's src URL to a data URL by loading the image and painting it to a canvas.
|
||||
*
|
||||
* Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.
|
||||
*
|
||||
* @param src
|
||||
* @param type the content type (optional, defaults to 'image/png')
|
||||
* @param crossOrigin for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors
|
||||
* @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
|
||||
*/
|
||||
export function imgSrcToDataURL(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<string>;
|
||||
|
||||
/**
|
||||
* Convert a canvas to a Blob.
|
||||
*
|
||||
* @param src
|
||||
* @param type the content type (optional, defaults to 'image/png')
|
||||
* @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
|
||||
*/
|
||||
export function canvasToBlob(canvas: HTMLCanvasElement, type?: string, quality?: number): Promise<Blob>;
|
||||
|
||||
/**
|
||||
* Convert an image's src URL to a Blob by loading the image and painting it to a canvas.
|
||||
*
|
||||
* Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.
|
||||
*
|
||||
* @param src
|
||||
* @param type the content type (optional, defaults to 'image/png')
|
||||
* @param crossOrigin for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors
|
||||
* @param quality a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'
|
||||
*/
|
||||
export function imgSrcToBlob(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<Blob>;
|
||||
|
||||
export function arrayBufferToBlob(arrayBuff: ArrayBuffer, type?: string): Promise<Blob>;
|
||||
export function blobToArrayBuffer(blob: Blob): Promise<ArrayBuffer>;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user