mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-02-04 07:52:51 +00:00
[blueimp-load-image] enhanced load image callback with metadata argument (#37848)
* extended loadimagecallback with metadata argument. * lint. * extended unit test. * cleanup test. * polishing.
This commit is contained in:
parent
982b76ff4a
commit
a67c19be85
@ -1,7 +1,9 @@
|
||||
import loadImage from 'blueimp-load-image';
|
||||
import loadImage, { MetaData } from 'blueimp-load-image';
|
||||
|
||||
// Test image taken from package tests: https://github.com/blueimp/JavaScript-Load-Image/blob/master/test/test.js
|
||||
|
||||
// 2x1px JPEG (color white, with the Exif orientation flag set to 6 and the
|
||||
// IPTC ObjectName (2:5) set to 'objectname'):
|
||||
const b64DataJPEG =
|
||||
'/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAASUkqAAgAAAABABIBAwABAAAA' +
|
||||
'BgASAAAAAAD/7QAsUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAA8cAgUACm9iamVj' +
|
||||
@ -20,7 +22,9 @@ const b64DataJPEG =
|
||||
'2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A/v4ooooA/9k=';
|
||||
const imageUrlJPEG = 'data:image/jpeg;base64,' + b64DataJPEG;
|
||||
|
||||
loadImage(imageUrlJPEG, (canvas: HTMLCanvasElement): void => {
|
||||
loadImage(imageUrlJPEG, (image: HTMLCanvasElement | HTMLImageElement, data?: MetaData): void => {
|
||||
const canvas = image as HTMLCanvasElement;
|
||||
console.log(data);
|
||||
canvas.toBlob((blob: Blob | null): void => {
|
||||
const url = canvas.toDataURL("image/png");
|
||||
console.log(url);
|
||||
|
||||
19
types/blueimp-load-image/index.d.ts
vendored
19
types/blueimp-load-image/index.d.ts
vendored
@ -1,11 +1,28 @@
|
||||
// Type definitions for blueimp-load-image 2.23
|
||||
// Project: https://github.com/blueimp/JavaScript-Load-Image
|
||||
// Definitions by: Evan Kesten <https://github.com/ebk46>
|
||||
// Konstantin Lukaschenko <https://github.com/KonstantinLukaschenko>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export type LoadImageCallback = (canvas: HTMLCanvasElement) => void;
|
||||
export type LoadImageCallback = (image: HTMLCanvasElement | HTMLImageElement, data?: MetaData) => void;
|
||||
|
||||
export interface Exif {
|
||||
[tag: number]: number | string | string[];
|
||||
}
|
||||
|
||||
export interface Iptc {
|
||||
[tag: number]: number | string | string[];
|
||||
}
|
||||
|
||||
export interface MetaData {
|
||||
originalWidth?: number;
|
||||
originalHeight?: number;
|
||||
imageHead?: ArrayBuffer | Uint8Array;
|
||||
exif?: Exif;
|
||||
iptc?: Iptc;
|
||||
}
|
||||
|
||||
export interface BasicOptions {
|
||||
maxWidth?: number; maxHeight?: number;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user