magica
Version:
ImageMagick for browser and Node.js, easy setup, high level API and Command Line Interface, including WASM binary for an easy setup.
125 lines (124 loc) • 5 kB
TypeScript
import { ExtractInfoResultImage } from '../image/imageInfo';
import { IFile, Rgba, Size } from '../types';
/**
* Default File implementation with utilities for creating from file system or urls.
*
* Also instances have utilities to cache and get image information like size, mimeType, image comparison,
* interacting with HTML DOM, etc.
*/
export declare class File implements IFile {
readonly name: string;
readonly content: IFile['content'];
readonly url?: string;
/**
* Stores size for those image formats that don't store size information such as RGBA
*/
width?: number;
/**
* Stores size for those image formats that don't store size information such as RGBA
*/
height?: number;
protected _info: ExtractInfoResultImage[] | undefined;
protected _pixels?: Rgba[];
constructor(name: string, content: IFile['content'], isProtected?: boolean, url?: string, width?: number, height?: number);
/**
* Same as [info] but returning only the first image's data.
*/
infoOne(): Promise<ExtractInfoResultImage>;
/**
* Get image information, like geometry, important numbers, mimeType, etc.
* The first time it calls `identify` command, but then it will cache ths value.
*/
info(): Promise<ExtractInfoResultImage[]>;
size(): Promise<Size>;
widthXHeight(): Promise<string>;
mimeType(): Promise<string>;
pixel(x: number, y: number): Promise<string | undefined>;
rgba(x: number, y: number): Promise<Rgba | undefined>;
/**
* it will compute all pixel colors so following [pixel] and [rgba] calls will be fast
*/
pixelCalculate(): Promise<void>;
/**
* Creates a DataUrl like `data:image/png;name=f.png;base64,` using given base64 content, mimeType and fileName.
*/
asDataUrl(mime?: string): Promise<string>;
/**
* Returns base64 representation of this image in an encoded format like PNG
*/
asBase64(file: File): string;
/**
* Returns base64 representation of this image in an encoded format like PNG
*/
equals(file?: File): Promise<boolean>;
/**
* Returns base64 representation of this image in an encoded format like PNG
*/
asArrayBuffer(): Promise<ArrayBuffer | SharedArrayBuffer>;
static equals: ((a: string | IFile, b: string | IFile) => boolean);
asHTMLImageData(): Promise<ImageData>;
asRGBAImageData(): Promise<RGBAImageData>;
sizeDepthArgs(onlyIfRGBA?: boolean): Promise<string>;
static getSizeDepthArgs(f: File, onlyIfRGBA?: boolean): Promise<string>;
/**
* Creates a DataUrl like `data:image/png;name=f.png;base64,` using given base64 content, mimeType and fileName.
*/
static toDataUrl(file: File, mime?: string): Promise<string>;
/**
* Creates a File from given url. In Node.js urls must be absolute!.
*/
static fromUrl(url: string, o?: RequestInit & ResolveOptions): Promise<File | undefined>;
/**
* Creates a File from given ArrayBuffer.
*/
static fromArrayBuffer(b: ArrayBuffer, o?: ResolveOptions): Promise<File>;
/**
* Creates a File from given file system path. Only Node.js.
*/
static fromFile(f: string, o?: ResolveOptions): File | undefined;
/**
* Returns the file content as plain string. This is useful to read the content of a .json or .txt file
* but not for images or other binary file content.
*/
static asString(f: IFile): string;
/**
* Returns base64 representation of this image in an encoded format like PNG
*/
static toBase64(file: File): string;
/**
* Loads file from given base64 string.
*/
static fromBase64(base64: string, name: string): File;
/**
* Loads file from given data url string.
*/
static fromDataUrl(dataUrl: string, name: string): File;
/**
* Loads files from files in html input element of type "file".
*/
static fromHtmlFileInputElement(el: HTMLInputElement): Promise<Array<File>>;
/**
* Shortcut for [resolve] that returns the first result.
*/
static resolveOne(files: string | IFile | undefined | (string | IFile | undefined)[], options?: ResolveOptions): Promise<File | undefined>;
/**
* Given paths, urls or files it will try to load them all and return a list of File for those succeed.
*/
static resolve(files: string | IFile | undefined | (string | IFile | undefined)[], options?: ResolveOptions): Promise<File[]>;
static isFile(f: any): f is File;
static asFile(f: string | IFile): File;
static asPath(f: string | IFile): string;
static fromRGBAImageData(d: RGBAImageData, name?: string): File;
static fromHTMLImageData(d: ImageData, name?: string): File;
static fileExists(f: string | IFile): Promise<boolean>;
}
export interface ResolveOptions {
protected?: boolean;
name?: string;
}
interface RGBAImageData {
width: number;
height: number;
data: Uint8ClampedArray;
}
export {};