Skip to main content
Go to Latest
File
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.// Licensed under the Apache License, Version 2.0.import { AlphaOption } from "./alpha-option.ts";import { AutoThresholdMethod } from "./auto-threshold-method.ts";import { Channels } from "./channels.ts";import { ColorSpace } from "./color-space.ts";import { CompositeOperator } from "./composite-operator.ts";import { DistortMethod } from "./distort-method.ts";import { DistortSettings } from "./settings/distort-settings.ts";import { DrawingWand } from "./drawables/drawing-wand.ts";import { ErrorMetric } from "./error-metric.ts";import { EvaluateOperator } from "./evaluate-operator.ts";import { Exception } from "./internal/exception/exception.ts";import { FilterType } from "./filter-type.ts";import { Gravity } from "./gravity.ts";import { ImageMagick } from "./image-magick.ts";import { IDrawable } from "./drawables/drawable.ts";import { IImageProfile, ImageProfile } from "./profiles/image-profile.ts";import { IMagickImageCollection, MagickImageCollection,} from "./magick-image-collection.ts";import { INativeInstance, NativeInstance } from "./internal/native-instance.ts";import { MagickColor } from "./magick-color.ts";import { MagickError } from "./magick-error.ts";import { MagickFormat } from "./magick-format.ts";import { MagickGeometry } from "./magick-geometry.ts";import { MagickReadSettings } from "./settings/magick-read-settings.ts";import { MagickRectangle } from "./internal/magick-rectangle.ts";import { MagickSettings } from "./settings/magick-settings.ts";import { OrientationType } from "./orientation-type.ts";import { Percentage } from "./percentage.ts";import { PixelChannel } from "./pixel-channel.ts";import { IPixelCollection, PixelCollection,} from "./pixels/pixel-collection.ts";import { PixelInterpolateMethod } from "./pixel-interpolate-method.ts";import { Point } from "./point.ts";import { Pointer } from "./internal/pointer/pointer.ts";import { Quantum } from "./quantum.ts";import { StringInfo } from "./internal/string-info.ts";import { VirtualPixelMethod } from "./virtual-pixel-method.ts";import { _createString, _withString } from "./internal/native/string.ts";import { _getEdges } from "./gravity.ts";import { _withDoubleArray } from "./internal/native/array.ts";
export interface IMagickImage extends INativeInstance { /** @internal */ _instance: number;
readonly artifactNames: ReadonlyArray<string>; backgroundColor: MagickColor; borderColor: MagickColor; readonly channelCount: number; colorFuzz: Percentage; colorSpace: ColorSpace; comment: string | null; depth: number; filterType: FilterType; format: MagickFormat; hasAlpha: boolean; interpolate: PixelInterpolateMethod; readonly height: number; orientation: OrientationType; page: MagickGeometry; quality: number; readonly signature: string | null; virtualPixelMethod: VirtualPixelMethod; width: number;
alpha(value: AlphaOption): void; autoOrient(): void; autoThreshold(method: AutoThresholdMethod): void; blur(): void; blur(channels: Channels): void; blur(radius: number, sigma: number): void; blur(radius: number, sigma: number, channels: Channels): void; border(size: number): void; border(width: number, height: number): void; channelOffset(pixelChannel: PixelChannel): number; charcoal(): void; charcoal(radius: number, sigma: number): void; clahe( xTiles: number, yTiles: number, numberBins: number, clipLimit: number, ): void; clahe( xTiles: Percentage, yTiles: Percentage, numberBins: number, clipLimit: number, ): void; clone(func: (image: IMagickImage) => void): void; clone(func: (image: IMagickImage) => Promise<void>): Promise<void>; colorAlpha(color: MagickColor): void; compare(image: IMagickImage, metric: ErrorMetric): number; compare(image: IMagickImage, metric: ErrorMetric, channels: Channels): number; composite(image: IMagickImage): void; composite(image: IMagickImage, compose: CompositeOperator): void; composite( image: IMagickImage, compose: CompositeOperator, channels: Channels, ): void; composite( image: IMagickImage, compose: CompositeOperator, args: string, ): void; composite( image: IMagickImage, compose: CompositeOperator, args: string, channels: Channels, ): void; composite(image: IMagickImage, point: Point): void; composite(image: IMagickImage, point: Point, channels: Channels): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, ): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, channels: Channels, ): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, args: string, ): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, args: string, channels: Channels, ): void; compositeGravity(image: IMagickImage, gravity: Gravity): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, channels: Channels, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, args: string, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, args: string, channels: Channels, ): void; compositeGravity(image: IMagickImage, gravity: Gravity, point: Point): void; compositeGravity( image: IMagickImage, gravity: Gravity, point: Point, channels: Channels, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, channels: Channels, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, args: string, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, args: string, channels: Channels, ): void; contrast(): void; contrastStretch(blackPoint: Percentage): void; contrastStretch(blackPoint: Percentage, whitePoint: Percentage): void; contrastStretch( blackPoint: Percentage, whitePoint?: Percentage, channels?: Channels, ): void; crop(geometry: MagickGeometry): void; crop(geometry: MagickGeometry, gravity: Gravity): void; crop(width: number, height: number): void; crop(width: number, height: number, gravity: Gravity): void; deskew(threshold: Percentage): number; distort(method: DistortMethod, params: number[]): void; distort( method: DistortMethod, settings: DistortSettings, params: number[], ): void; draw(drawables: IDrawable[]): void; draw(...drawables: IDrawable[]): void; evaluate(channels: Channels, operator: EvaluateOperator, value: number): void; evaluate( channels: Channels, operator: EvaluateOperator, value: Percentage, ): void; evaluate( channels: Channels, geometry: MagickGeometry, operator: EvaluateOperator, value: number, ): void; evaluate( channels: Channels, geometry: MagickGeometry, operator: EvaluateOperator, value: Percentage, ): void; extent(width: number, height: number): void; extent(width: number, height: number, gravity: Gravity): void; extent(width: number, height: number, backgroundColor: MagickColor): void; extent(geometry: MagickGeometry): void; extent(geometry: MagickGeometry, gravity: Gravity): void; extent( geometry: MagickGeometry, gravity: Gravity, backgroundColor: MagickColor, ): void; extent(geometry: MagickGeometry, backgroundColor: MagickColor): void; getArtifact(name: string): string | null; getAttribute(name: string): string | null; getProfile(name: string): IImageProfile | null; getWriteMask(func: (mask: IMagickImage | null) => void): void; getWriteMask( func: (mask: IMagickImage | null) => Promise<void>, ): Promise<void>; getPixels<TReturnType>( func: (pixels: IPixelCollection) => TReturnType, ): TReturnType; histogram(): Map<string, number>; inverseContrast(): void; inverseSigmoidalContrast(contrast: number): void; inverseSigmoidalContrast( contrast: number, midpointPercentage: Percentage, ): void; inverseSigmoidalContrast(contrast: number, midpoint: number): void; inverseSigmoidalContrast( contrast: number, midpoint: number, channels: Channels, ): void; level(blackPoint: Percentage, whitePoint: Percentage): void; level(blackPoint: Percentage, whitePoint: Percentage, gamma: number): void; level( channels: Channels, blackPoint: Percentage, whitePoint: Percentage, ): void; level( channels: Channels, blackPoint: Percentage, whitePoint: Percentage, gamma: number, ): void; liquidRescale(geometry: MagickGeometry): void; liquidRescale(width: number, height: number): void; modulate(brightness: Percentage): void; modulate(brightness: Percentage, saturation: Percentage): void; modulate( brightness: Percentage, saturation: Percentage, hue: Percentage, ): void; negate(): void; negate(channels: Channels): void; negateGrayScale(): void; negateGrayScale(channels: Channels): void; normalize(): void; oilPaint(): void; oilPaint(radius: number): void; ping(fileName: string, settings?: MagickReadSettings): void; ping(array: Uint8Array, settings?: MagickReadSettings): void; read(color: MagickColor, width: number, height: number): void; read(fileName: string, settings?: MagickReadSettings): void; read(array: Uint8Array, settings?: MagickReadSettings): void; readFromCanvas(canvas: HTMLCanvasElement): void; removeArtifact(name: string): void; removeAttribute(name: string): void; removeWriteMask(): void; repage(): void; resize(geometry: MagickGeometry): void; resize(width: number, height: number): void; rotate(degrees: number): void; sharpen(): void; sharpen(radius: number, sigma: number): void; sharpen(radius: number, sigma: number, channels: Channels): void; shave(leftRight: number, topBottom: number): void; sigmoidalContrast(contrast: number): void; sigmoidalContrast(contrast: number, midpointPercentage: Percentage): void; sigmoidalContrast(contrast: number, midpoint: number): void; sigmoidalContrast( contrast: number, midpoint: number, channels: Channels, ): void; separate(func: (images: IMagickImageCollection) => void): void; separate( func: (images: IMagickImageCollection) => Promise<void>, ): Promise<void>; separate( func: (images: IMagickImageCollection) => void, channels: Channels, ): void; separate( func: (images: IMagickImageCollection) => Promise<void>, channels: Channels, ): Promise<void>; setArtifact(name: string, value: string): void; setArtifact(name: string, value: boolean): void; setAttribute(name: string, value: string): void; setWriteMask(image: IMagickImage): void; strip(): void; toString(): string; trim(): void; trim(...edges: Gravity[]): void; trim(percentage: Percentage): void; vignette(): void; vignette(radius: number, sigma: number, x: number, y: number): void; wave(): void; wave(method: PixelInterpolateMethod, amplitude: number, length: number): void; write(func: (data: Uint8Array) => void, format?: MagickFormat): void; write( func: (data: Uint8Array) => Promise<void>, format?: MagickFormat, ): Promise<void>; writeToCanvas(canvas: HTMLCanvasElement): void;}
export class MagickImage extends NativeInstance implements IMagickImage { private readonly _settings: MagickSettings;
private constructor(instance: number, settings: MagickSettings) { super(instance, ImageMagick._api._MagickImage_Dispose); this._settings = settings; }
get artifactNames(): ReadonlyArray<string> { const artifactNames: string[] = []; ImageMagick._api._MagickImage_ResetArtifactIterator(this._instance); let name = ImageMagick._api._MagickImage_GetNextArtifactName( this._instance, ); while (name !== 0) { artifactNames.push(ImageMagick._api.UTF8ToString(name)); name = ImageMagick._api._MagickImage_GetNextArtifactName(this._instance); }
return artifactNames; }
get backgroundColor(): MagickColor { const colorPtr = ImageMagick._api._MagickImage_BackgroundColor_Get( this._instance, ); return MagickColor._create(colorPtr); } set backgroundColor(value: MagickColor) { value._use((valuePtr) => { ImageMagick._api._MagickImage_BackgroundColor_Set( this._instance, valuePtr, ); }); }
get borderColor(): MagickColor { const colorPtr = ImageMagick._api._MagickImage_BorderColor_Get( this._instance, ); return MagickColor._create(colorPtr); } set borderColor(value: MagickColor) { value._use((valuePtr) => { ImageMagick._api._MagickImage_BorderColor_Set(this._instance, valuePtr); }); }
get channelCount(): number { return ImageMagick._api._MagickImage_ChannelCount_Get(this._instance); }
get colorFuzz(): Percentage { return Percentage.fromQuantum( ImageMagick._api._MagickImage_ColorFuzz_Get(this._instance), ); } set colorFuzz(value: Percentage) { ImageMagick._api._MagickImage_ColorFuzz_Set( this._instance, value.toQuantum(), ); }
get colorSpace(): ColorSpace { return Exception.usePointer((exception) => { return ImageMagick._api._MagickImage_ColorSpace_Get( this._instance, exception, ); }); } set colorSpace(value: ColorSpace) { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_ColorSpace_Set( this._instance, value, exception, ); }); }
get comment(): string | null { return this.getAttribute("comment"); } set comment(value: string | null) { if (value === null) { this.removeAttribute("comment"); } else { this.setAttribute("comment", value); } }
get depth(): number { return ImageMagick._api._MagickImage_Depth_Get(this._instance); } set depth(value: number) { ImageMagick._api._MagickImage_Depth_Set(this._instance, value); }
get filterType(): number { return ImageMagick._api._MagickImage_FilterType_Get(this._instance); } set filterType(value: number) { ImageMagick._api._MagickImage_FilterType_Set(this._instance, value); }
get format(): MagickFormat { return _createString( ImageMagick._api._MagickImage_Format_Get(this._instance), "", ) as MagickFormat; } set format(value: MagickFormat) { _withString( value.toString(), (instance) => ImageMagick._api._MagickImage_Format_Set(this._instance, instance), ); }
get hasAlpha(): boolean { return Exception.usePointer((exception) => { return this.toBool( ImageMagick._api._MagickImage_HasAlpha_Get(this._instance, exception), ); }); } set hasAlpha(value: boolean) { Exception.usePointer((exception) => { if (value) { this.alpha(AlphaOption.Opaque); }
ImageMagick._api._MagickImage_HasAlpha_Set( this._instance, this.fromBool(value), exception, ); }); }
get interpolate(): PixelInterpolateMethod { return ImageMagick._api._MagickImage_Interpolate_Get(this._instance); } set interpolate(value: PixelInterpolateMethod) { ImageMagick._api._MagickImage_Interpolate_Set(this._instance, value); }
get height(): number { return ImageMagick._api._MagickImage_Height_Get(this._instance); }
get orientation(): OrientationType { return ImageMagick._api._MagickImage_Orientation_Get(this._instance); } set orientation(value: OrientationType) { ImageMagick._api._MagickImage_Orientation_Set(this._instance, value); }
get page(): MagickGeometry { const rectangle = ImageMagick._api._MagickImage_Page_Get(this._instance); return MagickGeometry.fromRectangle(rectangle); } set page(value: MagickGeometry) { value.toRectangle((rectangle) => { ImageMagick._api._MagickImage_Page_Set(this._instance, rectangle); }); }
get quality(): number { return ImageMagick._api._MagickImage_Quality_Get(this._instance); } set quality(value: number) { let quality = value < 1 ? 1 : value; quality = quality > 100 ? 100 : quality;
ImageMagick._api._MagickImage_Quality_Set(this._instance, quality); this._settings._quality = quality; }
get signature(): string | null { return Exception.usePointer((exception) => { return _createString( ImageMagick._api._MagickImage_Signature_Get(this._instance, exception), ); }); }
get virtualPixelMethod(): VirtualPixelMethod { return Exception.usePointer((exception) => { return ImageMagick._api._MagickImage_VirtualPixelMethod_Get( this._instance, exception, ); }); } set virtualPixelMethod(value: VirtualPixelMethod) { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_VirtualPixelMethod_Set( this._instance, value, exception, ); }); }
get width(): number { return ImageMagick._api._MagickImage_Width_Get(this._instance); }
alpha(value: AlphaOption): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_SetAlpha(this._instance, value, exception); }); }
autoOrient(): void { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_AutoOrient( this._instance, exception.ptr, ); this._setInstance(instance, exception); }); }
autoThreshold(method: AutoThresholdMethod): void { Exception.use((exception) => { ImageMagick._api._MagickImage_AutoThreshold( this._instance, method, exception.ptr, ); }); }
blur(): void; blur(channels: Channels): void; blur(radius: number, sigma: number): void; blur(radius: number, sigma: number, channels: Channels): void; blur( radiusOrChannel?: number | Channels, sigma?: number, channels?: Channels, ): void { let radius = 0; const sigmaValue = this.valueOrDefault(sigma, 1); let channelsValue = this.valueOrDefault(channels, Channels.Composite);
if (typeof radiusOrChannel === "number") { radius = radiusOrChannel; } else if (radiusOrChannel !== undefined) { channelsValue = radiusOrChannel; }
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Blur( this._instance, radius, sigmaValue, channelsValue, exception.ptr, ); this._setInstance(instance, exception); }); }
border(size: number): void; border(width: number, height: number): void; border(sizeOrWidth: number, height?: number): void { const widthValue = sizeOrWidth; const heightValue = this.valueOrDefault(height, sizeOrWidth);
const geometry = new MagickGeometry(0, 0, widthValue, heightValue);
Exception.use((exception) => { geometry.toRectangle((rectangle) => { const instance = ImageMagick._api._MagickImage_Border( this._instance, rectangle, exception.ptr, ); this._setInstance(instance, exception); }); }); }
channelOffset(pixelChannel: PixelChannel): number { if ( !ImageMagick._api._MagickImage_HasChannel(this._instance, pixelChannel) ) { return -1; }
return ImageMagick._api._MagickImage_ChannelOffset( this._instance, pixelChannel, ); }
charcoal(): void; charcoal(radius: number, sigma: number): void; charcoal(radiusOrUndefined?: number, sigmaOrUndefined?: number): void { const radius = radiusOrUndefined === undefined ? 0 : radiusOrUndefined; const sigma = sigmaOrUndefined === undefined ? 1 : sigmaOrUndefined; Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Charcoal( this._instance, radius, sigma, exception.ptr, ); this._setInstance(instance, exception); }); }
clahe( xTiles: number, yTiles: number, numberBins: number, clipLimit: number, ): void; clahe( xTiles: Percentage, yTiles: Percentage, numberBins: number, clipLimit: number, ): void; clahe( xTiles: number | Percentage, yTiles: number | Percentage, numberBins: number, clipLimit: number, ): void { Exception.usePointer((exception) => { const xTilesValue = xTiles instanceof Percentage ? xTiles.multiply(this.width) : xTiles; const yTilesValue = yTiles instanceof Percentage ? yTiles.multiply(this.height) : yTiles; ImageMagick._api._MagickImage_Clahe( this._instance, xTilesValue, yTilesValue, numberBins, clipLimit, exception, ); }); }
clone(func: (image: IMagickImage) => void): void; clone(func: (image: IMagickImage) => Promise<void>): Promise<void>; clone( func: (image: IMagickImage) => void | Promise<void>, ): void | Promise<void> { return Exception.usePointer((exception) => { const image = new MagickImage( ImageMagick._api._MagickImage_Clone(this._instance, exception), this._settings._clone(), ); try { return func(image); } finally { image.dispose(); } }); }
colorAlpha(color: MagickColor): void { if (!this.hasAlpha) { return; }
const canvas = MagickImage.create(); canvas.read(color, this.width, this.height); canvas.composite(this, CompositeOperator.SrcOver, new Point(0, 0)); this._instance = canvas._instance; }
compare(image: IMagickImage, metric: ErrorMetric): number; compare(image: IMagickImage, metric: ErrorMetric, channels: Channels): number; compare( image: IMagickImage, metric: ErrorMetric, channels?: Channels, ): number { return Exception.usePointer((exception) => { const compareChannels = channels !== undefined ? channels : Channels.Composite; return ImageMagick._api._MagickImage_CompareDistortion( this._instance, image._instance, metric, compareChannels, exception, ); }); }
composite(image: IMagickImage): void; composite(image: IMagickImage, compose: CompositeOperator): void; composite( image: IMagickImage, compose: CompositeOperator, channels: Channels, ): void; composite( image: IMagickImage, compose: CompositeOperator, args: string, ): void; composite( image: IMagickImage, compose: CompositeOperator, args: string, channels: Channels, ): void; composite(image: IMagickImage, point: Point): void; composite(image: IMagickImage, point: Point, channels: Channels): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, ): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, channels: Channels, ): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, args: string, ): void; composite( image: IMagickImage, compose: CompositeOperator, point: Point, args: string, channels: Channels, ): void; composite( image: IMagickImage, composeOrPoint?: CompositeOperator | Point, pointOrArgsOrChannels?: Point | string | Channels, channelsOrArgs?: Channels | string, channels?: Channels, ): void { let x = 0; let y = 0; let compose = CompositeOperator.In; let compositeChannels = Channels.Default; let args: string | null = null;
if (composeOrPoint instanceof Point) { x = composeOrPoint.x; y = composeOrPoint.y; } else if (composeOrPoint !== undefined) { compose = composeOrPoint; }
if (pointOrArgsOrChannels instanceof Point) { x = pointOrArgsOrChannels.x; y = pointOrArgsOrChannels.y; } else if (typeof pointOrArgsOrChannels === "string") { args = pointOrArgsOrChannels; } else if (pointOrArgsOrChannels !== undefined) { compositeChannels = pointOrArgsOrChannels; }
if (typeof channelsOrArgs === "string") { args = channelsOrArgs; } else if (channelsOrArgs !== undefined) { compositeChannels = channelsOrArgs; }
if (channels !== undefined) { compositeChannels = channels; }
if (args !== null) { this.setArtifact("compose:args", args); }
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Composite( this._instance, image._instance, x, y, compose, compositeChannels, exception, ); });
if (args !== null) { this.removeArtifact("compose:args"); } }
compositeGravity(image: IMagickImage, gravity: Gravity): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, channels: Channels, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, args: string, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, args: string, channels: Channels, ): void; compositeGravity(image: IMagickImage, gravity: Gravity, point: Point): void; compositeGravity( image: IMagickImage, gravity: Gravity, point: Point, channels: Channels, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, channels: Channels, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, args: string, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, compose: CompositeOperator, point: Point, args: string, channels: Channels, ): void; compositeGravity( image: IMagickImage, gravity: Gravity, composeOrPoint?: CompositeOperator | Point, pointOrArgsOrChannels?: Point | string | Channels, channelsOrArgs?: Channels | string, channels?: Channels, ): void { let x = 0; let y = 0; let compose = CompositeOperator.In; let compositeChannels = Channels.Default; let args: string | null = null;
if (composeOrPoint instanceof Point) { x = composeOrPoint.x; y = composeOrPoint.y; } else if (composeOrPoint !== undefined) { compose = composeOrPoint; }
if (pointOrArgsOrChannels instanceof Point) { x = pointOrArgsOrChannels.x; y = pointOrArgsOrChannels.y; } else if (typeof pointOrArgsOrChannels === "string") { args = pointOrArgsOrChannels; } else if (pointOrArgsOrChannels !== undefined) { compositeChannels = pointOrArgsOrChannels; }
if (typeof channelsOrArgs === "string") { args = channelsOrArgs; } else if (channelsOrArgs !== undefined) { compositeChannels = channelsOrArgs; }
if (channels !== undefined) { compositeChannels = channels; }
if (args !== null) { this.setArtifact("compose:args", args); }
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_CompositeGravity( this._instance, image._instance, gravity, x, y, compose, compositeChannels, exception, ); });
if (args !== null) { this.removeArtifact("compose:args"); } }
contrast(): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Contrast(this._instance, 1, exception); }); }
contrastStretch(blackPoint: Percentage): void; contrastStretch(blackPoint: Percentage, whitePoint: Percentage): void; contrastStretch( blackPoint: Percentage, whitePoint?: Percentage, channels?: Channels, ): void { const pixels = this.width * this.height; const lower = blackPoint.multiply(pixels); const upper = pixels - (whitePoint ?? blackPoint).multiply(pixels);
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_ContrastStretch( this._instance, lower, upper, channels ?? Channels.Default, exception, ); }); }
crop(geometry: MagickGeometry): void; crop(geometry: MagickGeometry, gravity: Gravity): void; crop(width: number, height: number): void; crop(width: number, height: number, gravity: Gravity): void; crop( geometryOrWidth: MagickGeometry | number, heightOrGravity?: number | Gravity, gravity?: Gravity, ): void { let geometry: MagickGeometry; let cropGravity: Gravity;
if (geometryOrWidth instanceof MagickGeometry) { geometry = geometryOrWidth; cropGravity = heightOrGravity !== undefined ? heightOrGravity : Gravity.Undefined; } else if (heightOrGravity !== undefined) { geometry = new MagickGeometry(geometryOrWidth, heightOrGravity); cropGravity = gravity !== undefined ? gravity : Gravity.Undefined; }
Exception.use((exception) => { _withString(geometry.toString(), (geometryPtr) => { const instance = ImageMagick._api._MagickImage_Crop( this._instance, geometryPtr, cropGravity, exception.ptr, ); this._setInstance(instance, exception); }); }); }
static create(): IMagickImage { return new MagickImage(MagickImage.createInstance(), new MagickSettings()); }
deskew(threshold: Percentage): number { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Deskew( this._instance, threshold.toQuantum(), exception.ptr, ); this._setInstance(instance, exception); });
const angle = Number(this.getArtifact("deskew:angle")); return isNaN(angle) ? 0.0 : angle; }
distort(method: DistortMethod, params: number[]): void; distort( method: DistortMethod, settings: DistortSettings, params: number[], ): void; distort( method: DistortMethod, settingsOrParams: number[] | DistortSettings, params?: number[], ): void { let distortArgs: number[]; let bestFit = 0; let settings: DistortSettings | null = null; if (settingsOrParams instanceof Array) { distortArgs = settingsOrParams; } else if (params instanceof Array) { distortArgs = params; settings = <DistortSettings> settingsOrParams; bestFit = settings.bestFit ? 1 : 0;
settings._setArtifacts(this); } else { distortArgs = []; }
Exception.use((exception) => { _withDoubleArray(distortArgs, (distortArgsPtr: number) => { const instance = ImageMagick._api._MagickImage_Distort( this._instance, method, bestFit, distortArgsPtr, distortArgs.length, exception.ptr, ); this._setInstance(instance, exception); }); });
if (settings !== null) { settings._removeArtifacts(this); } }
draw(drawables: IDrawable[]): void; draw(...drawables: IDrawable[]): void; draw(...drawables: IDrawable[][] | IDrawable[]): void { const wand = DrawingWand._create(this, this._settings); try { wand.draw(drawables.flat()); } finally { wand.dispose(); } }
evaluate(channels: Channels, operator: EvaluateOperator, value: number): void; evaluate( channels: Channels, operator: EvaluateOperator, value: Percentage, ): void; evaluate( channels: Channels, geometry: MagickGeometry, operator: EvaluateOperator, value: number, ): void; evaluate( channels: Channels, geometry: MagickGeometry, operator: EvaluateOperator, value: Percentage, ): void; evaluate( channels: Channels, operatorOrGeometry: EvaluateOperator | MagickGeometry, valueOrPercentageOrOperator: number | Percentage | EvaluateOperator, valueOrPercentage?: number | Percentage, ): void { if (typeof operatorOrGeometry === "number") { const operator = operatorOrGeometry; const value = typeof valueOrPercentageOrOperator === "number" ? valueOrPercentageOrOperator : valueOrPercentageOrOperator.toQuantum(); Exception.usePointer((exception) => { ImageMagick._api._MagickImage_EvaluateOperator( this._instance, channels, operator, value, exception, ); }); } else if (valueOrPercentage !== undefined) { if (typeof valueOrPercentageOrOperator !== "number") { throw new MagickError("this should not happen"); }
const geometry = operatorOrGeometry; const operator = valueOrPercentageOrOperator; const value = typeof valueOrPercentage === "number" ? valueOrPercentage : valueOrPercentage.toQuantum();
if (geometry.isPercentage) { throw new MagickError("percentage is not supported"); }
Exception.usePointer((exception) => { MagickRectangle.use(this, geometry, (rectangle) => { ImageMagick._api._MagickImage_EvaluateGeometry( this._instance, channels, rectangle, operator, value, exception, ); }); }); } }
extent(width: number, height: number): void; extent(width: number, height: number, gravity: Gravity): void; extent(width: number, height: number, backgroundColor: MagickColor): void; extent(geometry: MagickGeometry): void; extent(geometry: MagickGeometry, gravity: Gravity): void; extent( geometry: MagickGeometry, gravity: Gravity, backgroundColor: MagickColor, ): void; extent(geometry: MagickGeometry, backgroundColor: MagickColor): void; extent( geometryOrWidth: MagickGeometry | number, widthOrGravityOrBackgroundColor?: Gravity | MagickColor | number, backgroundColorOrGravity?: MagickColor | Gravity, ): void { let gravity = Gravity.Undefined; let geometry: MagickGeometry;
if (geometryOrWidth instanceof MagickGeometry) { geometry = geometryOrWidth; } else if (typeof widthOrGravityOrBackgroundColor === "number") { geometry = new MagickGeometry( geometryOrWidth, widthOrGravityOrBackgroundColor, ); }
if (widthOrGravityOrBackgroundColor instanceof MagickColor) { this.backgroundColor = widthOrGravityOrBackgroundColor; } else if (widthOrGravityOrBackgroundColor !== undefined) { gravity = widthOrGravityOrBackgroundColor; }
if (backgroundColorOrGravity instanceof MagickColor) { this.backgroundColor = backgroundColorOrGravity; } else if (backgroundColorOrGravity !== undefined) { gravity = backgroundColorOrGravity; }
Exception.use((exception) => { _withString(geometry.toString(), (geometryPtr) => { const instance = ImageMagick._api._MagickImage_Extent( this._instance, geometryPtr, gravity, exception.ptr, ); this._setInstance(instance, exception); }); }); }
getArtifact(name: string): string | null { return _withString(name, (namePtr) => { const value = ImageMagick._api._MagickImage_GetArtifact( this._instance, namePtr, ); return _createString(value); }); }
getAttribute(name: string): string | null { return Exception.use((exception) => { return _withString(name, (namePtr) => { const value = ImageMagick._api._MagickImage_GetAttribute( this._instance, namePtr, exception.ptr, ); return _createString(value); }); }); }
getProfile(name: string): IImageProfile | null { return _withString(name, (namePtr) => { const value = ImageMagick._api._MagickImage_GetProfile( this._instance, namePtr, ); const data = StringInfo.toArray(value); if (data === null) { return null; }
return new ImageProfile(name, data); }); }
getWriteMask(func: (mask: IMagickImage | null) => void): void; getWriteMask( func: (mask: IMagickImage | null) => Promise<void>, ): Promise<void>; getWriteMask( func: (mask: IMagickImage | null) => void | Promise<void>, ): void | Promise<void> { return Exception.usePointer((exception) => { const instance = ImageMagick._api._MagickImage_GetWriteMask( this._instance, exception, ); const image = instance === 0 ? null : new MagickImage(instance, new MagickSettings()); return func(image); }); }
getPixels<TReturnType>( func: (pixels: IPixelCollection) => TReturnType, ): TReturnType { if (this._settings._ping) { throw new MagickError("image contains no pixel data"); }
return PixelCollection._use(this, (pixels) => { return func(pixels); }); }
histogram(): Map<string, number> { const result = new Map<string, number>();
Exception.usePointer((exception) => { Pointer.use((lengthPointer) => { const histogram = ImageMagick._api._MagickImage_Histogram( this._instance, lengthPointer.ptr, exception, ); if (histogram !== 0) { const length = lengthPointer.value; for (let i = 0; i < length; i++) { const colorPtr = ImageMagick._api ._MagickColorCollection_GetInstance(histogram, i); const color = MagickColor._create(colorPtr); const count = ImageMagick._api._MagickColor_Count_Get(colorPtr); result.set(color.toString(), count); }
ImageMagick._api._MagickColorCollection_DisposeList(histogram); } }); });
return result; }
inverseContrast(): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Contrast(this._instance, 0, exception); }); }
inverseSigmoidalContrast(contrast: number): void; inverseSigmoidalContrast( contrast: number, midpointPercentage: Percentage, ): void; inverseSigmoidalContrast(contrast: number, midpoint: number): void; inverseSigmoidalContrast( contrast: number, midpoint: number, channels: Channels, ): void; inverseSigmoidalContrast( contrast: number, midpointOrPercentage?: number | Percentage, channels?: Channels, ): void { this.privateSigmoidalContrast( false, contrast, midpointOrPercentage, channels, ); }
level(blackPoint: Percentage, whitePoint: Percentage): void; level(blackPoint: Percentage, whitePoint: Percentage, gamma: number): void; level( channels: Channels, blackPoint: Percentage, whitePoint: Percentage, ): void; level( channels: Channels, blackPoint: Percentage, whitePoint: Percentage, gamma: number, ): void; level( channelsOrBlackPoint: Channels | Percentage, blackPointOrWhitePoint: Percentage, whitePointPercentageOrGamma?: Percentage | number, gamma?: number, ): void { let channels = Channels.Composite; let blackPoint: Percentage; let whitePoint: Percentage; let gammaValue = gamma !== undefined ? gamma : 1.0; if (typeof channelsOrBlackPoint === "number") { channels = channelsOrBlackPoint; blackPoint = blackPointOrWhitePoint; if (whitePointPercentageOrGamma instanceof Percentage) { whitePoint = whitePointPercentageOrGamma; } } else { blackPoint = channelsOrBlackPoint; whitePoint = blackPointOrWhitePoint; if (typeof whitePointPercentageOrGamma === "number") { gammaValue = whitePointPercentageOrGamma; } }
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Level( this._instance, blackPoint.toDouble(), whitePoint.toQuantum(), gammaValue, channels, exception, ); }); }
liquidRescale(geometry: MagickGeometry): void; liquidRescale(width: number, height: number): void; liquidRescale( widthOrGeometry: number | MagickGeometry, height?: number, ): void { const geometry = typeof widthOrGeometry === "number" ? new MagickGeometry(widthOrGeometry, height as number) : widthOrGeometry; Exception.use((exception) => { _withString(geometry.toString(), (geometryPtr) => { const instance = ImageMagick._api._MagickImage_LiquidRescale( this._instance, geometryPtr, geometry.x, geometry.y, exception.ptr, ); this._setInstance(instance, exception); }); }); }
negate(): void; negate(channels?: Channels): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Negate( this._instance, 0, channels ?? Channels.Composite, exception, ); }); }
negateGrayScale(): void; negateGrayScale(channels?: Channels): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Negate( this._instance, 1, channels ?? Channels.Composite, exception, ); }); }
normalize(): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Normalize(this._instance, exception); }); }
modulate(brightness: Percentage): void; modulate(brightness: Percentage, saturation: Percentage): void; modulate( brightness: Percentage, saturation: Percentage, hue: Percentage, ): void; modulate( brightness: Percentage, saturation?: Percentage, hue?: Percentage, ): void { const saturationPercentage = saturation === undefined ? new Percentage(100) : saturation; const huePercentage = hue === undefined ? new Percentage(100) : hue; Exception.usePointer((exception) => { const modulate = `${brightness.toDouble()}/${saturationPercentage.toDouble()}/${huePercentage.toDouble()}`; _withString(modulate, (modulatePtr) => { ImageMagick._api._MagickImage_Modulate( this._instance, modulatePtr, exception, ); }); }); }
oilPaint(): void; oilPaint(radius: number): void; oilPaint(radiusOrUndefined?: number): void { const radius = radiusOrUndefined === undefined ? 3 : radiusOrUndefined; const sigma = 0.0; // Not used due to precision issue in GetOptimalKernelWidth2D. Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_OilPaint( this._instance, radius, sigma, exception.ptr, ); this._setInstance(instance, exception); }); }
ping(fileName: string, settings?: MagickReadSettings): void; ping(array: Uint8Array, settings?: MagickReadSettings): void; ping( fileNameOrArray: string | Uint8Array, settings?: MagickReadSettings, ): void { this.readOrPing(true, fileNameOrArray, settings); }
read(color: MagickColor, width: number, height: number): void; read(fileName: string, settings?: MagickReadSettings): void; read(array: Uint8Array, settings?: MagickReadSettings): void; read( fileNameOrArrayOrColor: string | Uint8Array | MagickColor, settingsOrWidth?: MagickReadSettings | number, height?: number, ): void { this.readOrPing(false, fileNameOrArrayOrColor, settingsOrWidth, height); }
readFromCanvas(canvas: HTMLCanvasElement): void { const ctx = canvas.getContext("2d"); if (ctx === null) { return; }
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const settings = new MagickReadSettings(); settings.format = MagickFormat.Rgba; settings.width = canvas.width; settings.height = canvas.height;
Exception.use((exception) => { this.readFromArray(imageData.data, settings, exception); }); }
removeArtifact(name: string): void { _withString(name, (namePtr) => { ImageMagick._api._MagickImage_RemoveArtifact(this._instance, namePtr); }); }
removeAttribute(name: string): void { _withString(name, (namePtr) => { ImageMagick._api._MagickImage_RemoveAttribute(this._instance, namePtr); }); }
removeWriteMask(): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_SetWriteMask(this._instance, 0, exception); }); }
repage(): void { this.page = new MagickGeometry(0, 0, 0, 0); }
resize(geometry: MagickGeometry): void; resize(width: number, height: number): void; resize(widthOrGeometry: number | MagickGeometry, height?: number): void { const geometry = typeof widthOrGeometry === "number" ? new MagickGeometry(widthOrGeometry, height as number) : widthOrGeometry; Exception.use((exception) => { _withString(geometry.toString(), (geometryPtr) => { const instance = ImageMagick._api._MagickImage_Resize( this._instance, geometryPtr, exception.ptr, ); this._setInstance(instance, exception); }); }); }
rotate(degrees: number): void { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Rotate( this._instance, degrees, exception.ptr, ); this._setInstance(instance, exception); }); }
sharpen(): void; sharpen(radius: number, sigma: number): void; sharpen(radius: number, sigma: number, channels: Channels): void; sharpen(radius?: number, sigma?: number, channels?: Channels): void { const radiusValue = radius !== undefined ? radius : 0.0; const sigmaValue = sigma !== undefined ? sigma : 1.0; const channelsValue = channels !== undefined ? channels : Channels.Composite;
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Sharpen( this._instance, radiusValue, sigmaValue, channelsValue, exception.ptr, ); this._setInstance(instance, exception); }); }
shave(leftRight: number, topBottom: number) { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Shave( this._instance, leftRight, topBottom, exception.ptr, ); this._setInstance(instance, exception); }); }
sigmoidalContrast(contrast: number): void; sigmoidalContrast(contrast: number, midpointPercentage: Percentage): void; sigmoidalContrast(contrast: number, midpoint: number): void; sigmoidalContrast( contrast: number, midpoint: number, channels: Channels, ): void; sigmoidalContrast( contrast: number, midpointOrPercentage?: number | Percentage, channels?: Channels, ): void { this.privateSigmoidalContrast( true, contrast, midpointOrPercentage, channels, ); }
separate(func: (images: IMagickImageCollection) => void): void; separate( func: (images: IMagickImageCollection) => Promise<void>, ): Promise<void>; separate( func: (images: IMagickImageCollection) => void, channels: Channels, ): void; separate( func: (images: IMagickImageCollection) => Promise<void>, channels: Channels, ): Promise<void>; separate( func: (images: IMagickImageCollection) => void | Promise<void>, channels?: Channels, ): void | Promise<void> { return Exception.use((exception) => { const images = ImageMagick._api._MagickImage_Separate( this._instance, channels ?? Channels.All, exception.ptr, ); const collection = MagickImageCollection._createFromImages( images, this._settings._clone(), ); return collection._use(func); }); }
setArtifact(name: string, value: string): void; setArtifact(name: string, value: boolean): void; setArtifact(name: string, value: string | boolean): void { let strValue: string; if (typeof value === "string") { strValue = value; } else { strValue = this.fromBool(value).toString(); } _withString(name, (namePtr) => { _withString(strValue, (valuePtr) => { ImageMagick._api._MagickImage_SetArtifact( this._instance, namePtr, valuePtr, ); }); }); }
setAttribute(name: string, value: string): void { Exception.use((exception) => { _withString(name, (namePtr) => { _withString(value, (valuePtr) => { ImageMagick._api._MagickImage_SetAttribute( this._instance, namePtr, valuePtr, exception.ptr, ); }); }); }); }
setWriteMask(image: IMagickImage): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_SetWriteMask( this._instance, image._instance, exception, ); }); }
strip(): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Strip(this._instance, exception); }); }
toString = (): string => `${this.format} ${this.width}x${this.height} ${this.depth}-bit ${ ColorSpace[this.colorSpace] }`;
trim(): void; trim(...edges: Gravity[]): void; trim(percentage: Percentage): void; trim(...args: Gravity[] | Percentage[]): void { if (args.length > 0) { if (args.length == 1 && args[0] instanceof Percentage) { const percentage = args[0]; this.setArtifact( "trim:percent-background", percentage.toDouble().toString(), ); } else { const edges = args as Gravity[]; const value = [...new Set(_getEdges(edges))].join(","); this.setArtifact("trim:edges", value); } }
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Trim( this._instance, exception.ptr, ); this._setInstance(instance, exception);
this.removeArtifact("trim:edges"); this.removeArtifact("trim:percent-background"); }); }
wave(): void; wave(method: PixelInterpolateMethod, amplitude: number, length: number): void; wave( methodOrUndefined?: PixelInterpolateMethod, amplitudeOrUndefined?: number, lengthOrUndefined?: number, ): void { const method = methodOrUndefined == undefined ? this.interpolate : methodOrUndefined; const amplitude = amplitudeOrUndefined == undefined ? 25 : amplitudeOrUndefined; const length = lengthOrUndefined == undefined ? 150 : lengthOrUndefined;
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Wave( this._instance, method, amplitude, length, exception.ptr, ); this._setInstance(instance, exception); }); }
vignette(): void; vignette(radius: number, sigma: number, x: number, y: number): void; vignette( radiusOrUndefined?: number, sigmaOrUndefined?: number, xOrUndefined?: number, yOrUndefined?: number, ): void { const radius = radiusOrUndefined === undefined ? 0 : radiusOrUndefined; const sigma = sigmaOrUndefined === undefined ? 1.0 : sigmaOrUndefined; const x = xOrUndefined === undefined ? 0 : xOrUndefined; const y = yOrUndefined === undefined ? 0 : yOrUndefined;
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Vignette( this._instance, radius, sigma, x, y, exception.ptr, ); this._setInstance(instance, exception); }); }
write(func: (data: Uint8Array) => void, format?: MagickFormat): void; write( func: (data: Uint8Array) => Promise<void>, format?: MagickFormat, ): Promise<void>; write( func: (data: Uint8Array) => void | Promise<void>, format?: MagickFormat, ): void | Promise<void> { let data = 0; let bytes = new Uint8Array();
Exception.use((exception) => { Pointer.use((pointer) => { if (format !== undefined) { this._settings.format = format; }
this._settings._use((settings) => { try { data = ImageMagick._api._MagickImage_WriteBlob( this._instance, settings._instance, pointer.ptr, exception.ptr, ); if (data !== 0) { bytes = ImageMagick._api.HEAPU8.subarray( data, data + pointer.value, ); } } catch { if (data !== 0) { data = ImageMagick._api._MagickMemory_Relinquish(data); } } }); }); });
try { let result = func(bytes); if (!!result && typeof result.then === "function") { result = result.finally(() => { if (data !== 0) { data = ImageMagick._api._MagickMemory_Relinquish(data); } }); } return result; } finally { if (data !== 0) { data = ImageMagick._api._MagickMemory_Relinquish(data); } } }
writeToCanvas(canvas: HTMLCanvasElement): void { canvas.width = this.width; canvas.height = this.height;
const ctx = canvas.getContext("2d"); if (ctx === null) { return; }
PixelCollection._map(this, "RGBA", (q) => { const imageData = ctx.createImageData(this.width, this.height);
let p = 0; for (let y = 0; y < this.height; y++) { for (let x = 0; x < this.width; x++) { imageData.data[p++] = ImageMagick._api.HEAPU8[q++]; imageData.data[p++] = ImageMagick._api.HEAPU8[q++]; imageData.data[p++] = ImageMagick._api.HEAPU8[q++]; imageData.data[p++] = ImageMagick._api.HEAPU8[q++]; } }
ctx.putImageData(imageData, 0, 0); }); }
/** @internal */ static _createFromImage( instance: number, settings: MagickSettings, ): MagickImage { return new MagickImage(instance, settings); }
/** @internal */ _getSettings(): MagickSettings { return this._settings; }
/** @internal */ protected _instanceNotInitialized(): void { throw new MagickError("no image has been read"); }
/** @internal */ static _use<TReturnType>( func: (image: IMagickImage) => TReturnType, ): TReturnType; static _use<TReturnType>( func: (image: IMagickImage) => Promise<TReturnType>, ): Promise<TReturnType>; static _use<TReturnType>( func: (image: IMagickImage) => TReturnType | Promise<TReturnType>, ): TReturnType | Promise<TReturnType> { const image = MagickImage.create(); try { return func(image); } finally { image.dispose(); } }
private privateSigmoidalContrast( sharpen: boolean, contrast: number, midpointOrPercentage?: number | Percentage, channels?: Channels, ): void { let midpoint: number; if (midpointOrPercentage !== undefined) { if (typeof midpointOrPercentage === "number") { midpoint = midpointOrPercentage; } else { midpoint = midpointOrPercentage.multiply(Quantum.max); } } else { midpoint = Quantum.max * 0.5; } let usedChannels = Channels.Default; if (channels !== undefined) { usedChannels = channels; } Exception.usePointer((exception) => { ImageMagick._api._MagickImage_SigmoidalContrast( this._instance, this.fromBool(sharpen), contrast, midpoint, usedChannels, exception, ); }); }
private static createInstance(): number { return Exception.usePointer((exception) => { return ImageMagick._api._MagickImage_Create(0, exception); }); }
private fromBool(value: boolean): number { return value ? 1 : 0; }
private readOrPing( ping: boolean, fileNameOrArrayOrColor: string | Uint8Array | MagickColor, settingsOrWidth?: MagickReadSettings | number, height?: number, ): void { Exception.use((exception) => { if (fileNameOrArrayOrColor instanceof Uint8Array) { const readSettings = settingsOrWidth instanceof MagickReadSettings ? settingsOrWidth : new MagickReadSettings(this._settings); readSettings._ping = ping; this._settings._ping = ping; this.readFromArray(fileNameOrArrayOrColor, readSettings, exception); } else { const readSettings = settingsOrWidth instanceof MagickReadSettings ? settingsOrWidth : new MagickReadSettings(this._settings); readSettings._ping = ping; this._settings._ping = ping; if (typeof fileNameOrArrayOrColor === "string") { readSettings._fileName = fileNameOrArrayOrColor; } else if (fileNameOrArrayOrColor instanceof MagickColor) { readSettings._fileName = "xc:" + fileNameOrArrayOrColor.toShortString(); readSettings.width = typeof settingsOrWidth === "number" ? settingsOrWidth : 0; readSettings.height = typeof height === "number" ? height : 0; } readSettings._use((settings) => { const instance = ImageMagick._api._MagickImage_ReadFile( settings._instance, exception.ptr, ); this._setInstance(instance, exception); }); } }); }
private readFromArray( array: Uint8Array | Uint8ClampedArray, readSettings: MagickReadSettings, exception: Exception, ): void { readSettings._use((settings) => { const length = array.byteLength; let data = 0; try { data = ImageMagick._api._malloc(length); ImageMagick._api.HEAPU8.set(array, data); const instance = ImageMagick._api._MagickImage_ReadBlob( settings._instance, data, 0, length, exception.ptr, ); this._setInstance(instance, exception); } finally { if (data !== 0) { ImageMagick._api._free(data); } } }); }
private toBool(value: number): boolean { return value === 1; }
private valueOrDefault<TType>( value: TType | undefined, defaultValue: TType, ): TType { if (value === undefined) { return defaultValue; }
return value; }}