Skip to main content
Module

x/imagemagick_deno/src/magick-image.ts

Deno port of the WASM library for ImageMagick
Latest
File
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759
// 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 { ByteArray } from "./byte-array.ts";import { Channels } from "./channels.ts";import { ChromaticityInfo } from "./chromaticity-info.ts";import { ClassType } from "./class-type.ts";import { ColorSpace } from "./color-space.ts";import { ColorType } from "./color-type.ts";import { CompositeOperator } from "./composite-operator.ts";import { CompressionMethod } from "./compression-method.ts";import { Density } from "./density.ts";import { Disposable } from "./internal/disposable.ts";import { DisposableArray } from "./internal/disposable-array.ts";import { DistortMethod } from "./distort-method.ts";import { DistortSettings } from "./settings/distort-settings.ts";import { DrawingWand } from "./drawables/drawing-wand.ts";import { Endian } from "./endian.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 { GifDisposeMethod } from "./gif-dispose-method.ts";import { Gravity } from "./gravity.ts";import { ImageMagick } from "./image-magick.ts";import { IDisposable } from "./disposable.ts";import { IDrawable } from "./drawables/drawable.ts";import { IImageProfile, ImageProfile } from "./profiles/image-profile.ts";import { Interlace } from "./interlace.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 { IMagickImageCollection, MagickImageCollection,} from "./magick-image-collection.ts";import { MagickReadSettings } from "./settings/magick-read-settings.ts";import { MagickRectangle } from "./internal/magick-rectangle.ts";import { MagickSettings } from "./settings/magick-settings.ts";import { MorphologySettings } from "./settings/morphology-settings.ts";import { NativeInstance } from "./native-instance.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 { PixelIntensityMethod } from "./pixel-intensity-method.ts";import { PixelInterpolateMethod } from "./pixel-interpolate-method.ts";import { Point } from "./point.ts";import { Pointer } from "./internal/pointer/pointer.ts";import { PrimaryInfo } from "./primary-info.ts";import { Quantum } from "./quantum.ts";import { IStatistics, Statistics } from "./statistics.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 { _withByteArray, _withDoubleArray } from "./internal/native/array.ts";
export interface IMagickImage extends IDisposable { /** @internal */ _instance: number; /** @internal */ _use<TReturnType>(func: (image: IMagickImage) => TReturnType): TReturnType; /** @internal */ _use<TReturnType>( func: (image: IMagickImage) => Promise<TReturnType>, ): Promise<TReturnType>; /** @internal */ _use<TReturnType>( func: (image: IMagickImage) => TReturnType | Promise<TReturnType>, ): TReturnType | Promise<TReturnType>;
animationDelay: number; animationIterations: number; animationTicksPerSecond: number; readonly artifactNames: ReadonlyArray<string>; readonly attributeNames: ReadonlyArray<string>; backgroundColor: MagickColor; readonly baseHeight: number; readonly baseWidth: number; blackPointCompensation: boolean; borderColor: MagickColor; boundingBox: MagickGeometry | null; readonly channelCount: number; readonly channels: ReadonlyArray<PixelChannel>; chromaticity: ChromaticityInfo; classType: ClassType; colorFuzz: Percentage; colormapSize: number; colorSpace: ColorSpace; colorType: ColorType; comment: string | null; compose: CompositeOperator; readonly compression: CompressionMethod; density: Density; depth: number; endian: Endian; readonly fileName: string | null; filterType: FilterType; format: MagickFormat; gamma: number; gifDisposeMethod: GifDisposeMethod; hasAlpha: boolean; readonly height: number; interpolate: PixelInterpolateMethod; readonly interlace: Interlace; label: string | null; orientation: OrientationType; page: MagickGeometry; quality: number; readonly settings: MagickSettings; 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; brightnessContrast(brightness: Percentage, contrast: Percentage): void; brightnessContrast( brightness: Percentage, contrast: Percentage, channels: Channels, ): 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<TReturnType>(func: (image: IMagickImage) => TReturnType): TReturnType; clone<TReturnType>( func: (image: IMagickImage) => Promise<TReturnType>, ): Promise<TReturnType>; 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; cropToTiles(geometry: MagickGeometry): IMagickImageCollection; 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; flip(): void; flop(): void; getArtifact(name: string): string | null; getAttribute(name: string): string | null; getProfile(name: string): IImageProfile | null; getWriteMask<TReturnType>( func: (mask: IMagickImage | null) => TReturnType, ): TReturnType; getWriteMask<TReturnType>( func: (mask: IMagickImage | null) => Promise<TReturnType>, ): Promise<TReturnType>; getPixels<TReturnType>( func: (pixels: IPixelCollection) => TReturnType, ): TReturnType; getPixels<TReturnType>( func: (pixels: IPixelCollection) => Promise<TReturnType>, ): Promise<TReturnType>; grayscale(): void; grayscale(method: PixelIntensityMethod): void; histogram(): Map<string, number>; inverseContrast(): void; inverseOpaque(target: MagickColor, fill: MagickColor): 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; inverseTransparent(color: MagickColor): 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; linearStretch(blackPoint: Percentage, whitePoint: Percentage): 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; motionBlur(radius: number, sigma: number, angle: number): void; morphology(settings: MorphologySettings): void; negate(): void; negate(channels: Channels): void; negateGrayScale(): void; negateGrayScale(channels: Channels): void; normalize(): void; oilPaint(): void; oilPaint(radius: number): void; opaque(target: MagickColor, fill: MagickColor): void; ping(fileName: string, settings?: MagickReadSettings): void; ping(array: ByteArray, settings?: MagickReadSettings): void; read(color: MagickColor, width: number, height: number): void; read(fileName: string, settings?: MagickReadSettings): void; read(array: ByteArray, settings?: MagickReadSettings): void; readFromCanvas(canvas: HTMLCanvasElement): void; removeArtifact(name: string): void; removeAttribute(name: string): void; removeProfile(name: string): void; removeWriteMask(): void; repage(): void; resize(geometry: MagickGeometry): void; resize(width: number, height: number): void; rotate(degrees: number): void; separate<TReturnType>( func: (images: IMagickImageCollection) => TReturnType, ): TReturnType; separate<TReturnType>( func: (images: IMagickImageCollection) => Promise<TReturnType>, ): Promise<TReturnType>; separate<TReturnType>( func: (images: IMagickImageCollection) => TReturnType, channels: Channels, ): TReturnType; separate<TReturnType>( func: (images: IMagickImageCollection) => Promise<TReturnType>, channels: Channels, ): Promise<TReturnType>; sepiaTone(): void; sepiaTone(threshold: number): void; sepiaTone(threshold: Percentage): void; setArtifact(name: string, value: string): void; setArtifact(name: string, value: boolean): void; setAttribute(name: string, value: string): void; setProfile(name: string, data: ByteArray): void; setWriteMask(image: IMagickImage): 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; splice(geometry: MagickGeometry): void; solarize(): void; solarize(factor: number): void; solarize(factor: Percentage): void; statistics(): IStatistics; statistics(channels: Channels): IStatistics; strip(): void; toString(): string; transparent(color: MagickColor): void; 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<TReturnType>(func: (data: Uint8Array) => TReturnType): TReturnType; write<TReturnType>( format: MagickFormat, func: (data: Uint8Array) => TReturnType, ): TReturnType; write<TReturnType>( func: (data: Uint8Array) => Promise<TReturnType>, ): Promise<TReturnType>; write<TReturnType>( format: MagickFormat, func: (data: Uint8Array) => Promise<TReturnType>, ): Promise<TReturnType>; 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 animationDelay(): number { return ImageMagick._api._MagickImage_AnimationDelay_Get(this._instance); } set animationDelay(value: number) { ImageMagick._api._MagickImage_AnimationDelay_Set(this._instance, value); }
get animationIterations(): number { return ImageMagick._api._MagickImage_AnimationIterations_Get( this._instance, ); } set animationIterations(value: number) { ImageMagick._api._MagickImage_AnimationIterations_Set( this._instance, value, ); }
get animationTicksPerSecond(): number { return ImageMagick._api._MagickImage_AnimationTicksPerSecond_Get( this._instance, ); } set animationTicksPerSecond(value: number) { ImageMagick._api._MagickImage_AnimationTicksPerSecond_Set( this._instance, value, ); }
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 attributeNames(): ReadonlyArray<string> { const artifactNames: string[] = []; ImageMagick._api._MagickImage_ResetAttributeIterator(this._instance); let name = ImageMagick._api._MagickImage_GetNextAttributeName( this._instance, ); while (name !== 0) { artifactNames.push(ImageMagick._api.UTF8ToString(name)); name = ImageMagick._api._MagickImage_GetNextAttributeName(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 baseHeight(): number { return ImageMagick._api._MagickImage_BaseHeight_Get(this._instance); }
get baseWidth(): number { return ImageMagick._api._MagickImage_BaseWidth_Get(this._instance); }
get blackPointCompensation(): boolean { return ImageMagick._api._MagickImage_BlackPointCompensation_Get( this._instance, ) === 1; }
set blackPointCompensation(value: boolean) { ImageMagick._api._MagickImage_BlackPointCompensation_Set( this._instance, value ? 1 : 0, ); }
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 boundingBox(): MagickGeometry | null { return Exception.usePointer((exception) => { const boundingBox = ImageMagick._api._MagickImage_BoundingBox_Get( this._instance, exception, ); const geometry = MagickGeometry._fromRectangle(boundingBox); if (geometry.width === 0 || geometry.height === 0) { return null; }
return geometry; }); }
get channelCount(): number { return ImageMagick._api._MagickImage_ChannelCount_Get(this._instance); }
get channels(): ReadonlyArray<PixelChannel> { const channels: PixelChannel[] = []; [ PixelChannel.Red, PixelChannel.Green, PixelChannel.Blue, PixelChannel.Black, PixelChannel.Alpha, ].forEach((channel) => { if (ImageMagick._api._MagickImage_HasChannel(this._instance, channel)) { channels.push(channel); } });
return channels; }
get chromaticity(): ChromaticityInfo { return new ChromaticityInfo( PrimaryInfo._create( ImageMagick._api._MagickImage_ChromaRedPrimary_Get(this._instance), ), PrimaryInfo._create( ImageMagick._api._MagickImage_ChromaGreenPrimary_Get(this._instance), ), PrimaryInfo._create( ImageMagick._api._MagickImage_ChromaBluePrimary_Get(this._instance), ), PrimaryInfo._create( ImageMagick._api._MagickImage_ChromaWhitePoint_Get(this._instance), ), ); } set chromaticity(value: ChromaticityInfo) { value.blue._use((primaryInfoPtr) => ImageMagick._api._MagickImage_ChromaBluePrimary_Set( this._instance, primaryInfoPtr, ) ); value.green._use((primaryInfoPtr) => ImageMagick._api._MagickImage_ChromaGreenPrimary_Set( this._instance, primaryInfoPtr, ) ); value.red._use((primaryInfoPtr) => ImageMagick._api._MagickImage_ChromaRedPrimary_Set( this._instance, primaryInfoPtr, ) ); value.white._use((primaryInfoPtr) => ImageMagick._api._MagickImage_ChromaWhitePoint_Set( this._instance, primaryInfoPtr, ) ); }
get classType(): ClassType { return Exception.usePointer((exception) => { return ImageMagick._api._MagickImage_ClassType_Get( this._instance, exception, ); }); } set classType(value: ClassType) { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_ClassType_Set( this._instance, value, exception, ); }); }
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 colormapSize(): number { return Exception.usePointer((exception) => { return ImageMagick._api._MagickImage_ColormapSize_Get( this._instance, exception, ); }); } set colormapSize(value: number) { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_ColormapSize_Set( this._instance, value, exception, ); }); }
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 colorType(): ColorType { if (this.settings.colorType !== undefined) { return this.settings.colorType; }
return Exception.usePointer((exception) => { return ImageMagick._api._MagickImage_ColorType_Get( this._instance, exception, ); }); } set colorType(value: ColorType) { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_ColorType_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 compose(): CompositeOperator { return ImageMagick._api._MagickImage_Compose_Get(this._instance); } set compose(value: CompositeOperator) { ImageMagick._api._MagickImage_Compose_Set(this._instance, value); }
get compression(): CompressionMethod { return ImageMagick._api._MagickImage_Compression_Get(this._instance); }
get density(): Density { return new Density( ImageMagick._api._MagickImage_ResolutionX_Get(this._instance), ImageMagick._api._MagickImage_ResolutionY_Get(this._instance), ImageMagick._api._MagickImage_ResolutionUnits_Get(this._instance), ); } set density(value: Density) { ImageMagick._api._MagickImage_ResolutionX_Set(this._instance, value.x); ImageMagick._api._MagickImage_ResolutionY_Set(this._instance, value.y); ImageMagick._api._MagickImage_ResolutionUnits_Set( this._instance, value.units, ); }
get depth(): number { return ImageMagick._api._MagickImage_Depth_Get(this._instance); } set depth(value: number) { ImageMagick._api._MagickImage_Depth_Set(this._instance, value); }
get endian(): number { return ImageMagick._api._MagickImage_Endian_Get(this._instance); } set endian(value: number) { ImageMagick._api._MagickImage_Endian_Set(this._instance, value); }
get fileName(): string | null { const fileName = ImageMagick._api._MagickImage_FileName_Get(this._instance); if (fileName === 0) { return null; } return ImageMagick._api.UTF8ToString(fileName); }
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 gamma(): number { return ImageMagick._api._MagickImage_Gamma_Get(this._instance); }
get gifDisposeMethod(): GifDisposeMethod { return ImageMagick._api._MagickImage_GifDisposeMethod_Get(this._instance); } set gifDisposeMethod(value: GifDisposeMethod) { ImageMagick._api._MagickImage_GifDisposeMethod_Set(this._instance, value); }
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 height(): number { return ImageMagick._api._MagickImage_Height_Get(this._instance); }
get interlace(): Interlace { return ImageMagick._api._MagickImage_Interlace_Get(this._instance); }
get interpolate(): PixelInterpolateMethod { return ImageMagick._api._MagickImage_Interpolate_Get(this._instance); } set interpolate(value: PixelInterpolateMethod) { ImageMagick._api._MagickImage_Interpolate_Set(this._instance, value); }
get label(): string | null { return this.getAttribute("label"); } set label(value: string | null) { if (value === null) { this.removeAttribute("label"); } else { this.setAttribute("label", value); } }
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 settings(): MagickSettings { return this._settings; }
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, sigmaOrUndefined?: number, channelsOrUndefined?: Channels, ): void { let radius = 0; const sigma = this.valueOrDefault(sigmaOrUndefined, 1); let channels = this.valueOrDefault(channelsOrUndefined, Channels.Undefined);
if (typeof radiusOrChannel === "number") { radius = radiusOrChannel; } else if (radiusOrChannel !== undefined) { channels = radiusOrChannel; }
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Blur( this._instance, radius, sigma, channels, exception.ptr, ); this._setInstance(instance, exception); }); }
border(size: number): void; border(width: number, height: number): void; border(sizeOrWidth: number, heightOrUndefined?: number): void { const width = sizeOrWidth; const height = this.valueOrDefault(heightOrUndefined, sizeOrWidth); const geometry = new MagickGeometry(0, 0, width, height);
Exception.use((exception) => { geometry._toRectangle((rectangle) => { const instance = ImageMagick._api._MagickImage_Border( this._instance, rectangle, exception.ptr, ); this._setInstance(instance, exception); }); }); }
brightnessContrast(brightness: Percentage, contrast: Percentage): void; brightnessContrast( brightness: Percentage, contrast: Percentage, channels: Channels, ): void; brightnessContrast( brightness: Percentage, contrast: Percentage, channelsOrUndefined?: Channels, ): void { const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, );
Exception.use((exception) => { ImageMagick._api._MagickImage_BrightnessContrast( this._instance, brightness.toDouble(), contrast.toDouble(), channels, exception.ptr, ); }); }
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<TReturnType>(func: (image: IMagickImage) => TReturnType): TReturnType; clone<TReturnType>( func: (image: IMagickImage) => Promise<TReturnType>, ): Promise<TReturnType>; clone<TReturnType>( func: (image: IMagickImage) => TReturnType | Promise<TReturnType>, ): TReturnType | Promise<TReturnType> { const image = MagickImage._clone(this); return image._use(func); }
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, channelsOrUndefined?: Channels, ): number { return Exception.usePointer((exception) => { const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, ); return ImageMagick._api._MagickImage_CompareDistortion( this._instance, image._instance, metric, channels, 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, channelsOrUndefined?: Channels, ): void { let x = 0; let y = 0; let compose = CompositeOperator.In; let channels = 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) { channels = pointOrArgsOrChannels; }
if (typeof channelsOrArgs === "string") { args = channelsOrArgs; } else if (channelsOrArgs !== undefined) { channels = channelsOrArgs; }
if (channelsOrUndefined !== undefined) { channels = channelsOrUndefined; }
if (args !== null) { this.setArtifact("compose:args", args); }
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Composite( this._instance, image._instance, x, y, compose, channels, 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, channelsOrUndefined?: Channels, ): void { let x = 0; let y = 0; let compose = CompositeOperator.In; let channels = 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) { channels = pointOrArgsOrChannels; }
if (typeof channelsOrArgs === "string") { args = channelsOrArgs; } else if (channelsOrArgs !== undefined) { channels = channelsOrArgs; }
if (channelsOrUndefined !== undefined) { channels = channelsOrUndefined; }
if (args !== null) { this.setArtifact("compose:args", args); }
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_CompositeGravity( this._instance, image._instance, gravity, x, y, compose, channels, exception, ); });
if (args !== null) { this.removeArtifact("compose:args"); } }
contrast = () => this._contrast(true);
contrastStretch(blackPoint: Percentage): void; contrastStretch(blackPoint: Percentage, whitePoint: Percentage): void; contrastStretch( blackPoint: Percentage, whitePointOrUndefined?: Percentage, channelsOrUndefined?: Channels, ): void { const pixels = this.width * this.height; const lower = blackPoint.multiply(pixels); const upper = pixels - (whitePointOrUndefined ?? blackPoint).multiply(pixels); const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, );
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_ContrastStretch( this._instance, lower, upper, channels, exception, ); }); }
static create(): IMagickImage; static create( color: MagickColor, width: number, height: number, ): IMagickImage; static create(fileName: string, settings?: MagickReadSettings): IMagickImage; static create(array: ByteArray, settings?: MagickReadSettings): IMagickImage; static create( fileNameOrArrayOrColorOrUndefined?: string | ByteArray | MagickColor, settingsOrWidthOrUndefined?: MagickReadSettings | number, heightOrUndefined?: number, ): IMagickImage { const image = new MagickImage( MagickImage.createInstance(), new MagickSettings(), ); if (fileNameOrArrayOrColorOrUndefined !== undefined) { image.readOrPing( false, fileNameOrArrayOrColorOrUndefined, settingsOrWidthOrUndefined, heightOrUndefined, ); } return image; }
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, gravityOrUndefined?: Gravity, ): void { let geometry: MagickGeometry; let gravity: Gravity;
if (geometryOrWidth instanceof MagickGeometry) { geometry = geometryOrWidth; gravity = this.valueOrDefault(heightOrGravity, Gravity.Undefined); } else if (heightOrGravity !== undefined) { geometry = new MagickGeometry(geometryOrWidth, heightOrGravity); gravity = this.valueOrDefault(gravityOrUndefined, Gravity.Undefined); }
Exception.use((exception) => { _withString(geometry.toString(), (geometryPtr) => { const instance = ImageMagick._api._MagickImage_Crop( this._instance, geometryPtr, gravity, exception.ptr, ); this._setInstance(instance, exception); }); }); }
cropToTiles(geometry: MagickGeometry): IMagickImageCollection { return Exception.use((exception) => { return _withString(geometry.toString(), (geometryPtr) => { const images = ImageMagick._api._MagickImage_CropToTiles( this._instance, geometryPtr, exception.ptr, ); const collection = MagickImageCollection._createFromImages( images, this._settings, ); return collection; }); }); }
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); }); }); }
flip(): void { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Flip( this._instance, exception.ptr, ); this._setInstance(instance, exception); }); }
flop(): void { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Flop( this._instance, 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<TReturnType>( func: (mask: IMagickImage | null) => TReturnType, ): TReturnType; getWriteMask<TReturnType>( func: (mask: IMagickImage | null) => Promise<TReturnType>, ): Promise<TReturnType>; getWriteMask<TReturnType>( func: (mask: IMagickImage | null) => TReturnType | Promise<TReturnType>, ): TReturnType | Promise<TReturnType> { const instance = Exception.usePointer((exception) => { return ImageMagick._api._MagickImage_GetWriteMask( this._instance, exception, ); }); const image = instance === 0 ? null : new MagickImage(instance, new MagickSettings()); if (image == null) { return func(image); } else { return image._use(func); } }
getPixels<TReturnType>( func: (pixels: IPixelCollection) => TReturnType, ): TReturnType; getPixels<TReturnType>( func: (pixels: IPixelCollection) => Promise<TReturnType>, ): Promise<TReturnType>; getPixels<TReturnType>( func: (pixels: IPixelCollection) => TReturnType | Promise<TReturnType>, ): TReturnType | Promise<TReturnType> { if (this._settings._ping) { throw new MagickError("image contains no pixel data"); }
return PixelCollection._use(this, func); }
grayscale( method: PixelIntensityMethod = PixelIntensityMethod.Undefined, ): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Grayscale( this._instance, method, exception, ); }); }
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 = () => this._contrast(false);
inverseOpaque = (target: MagickColor, fill: MagickColor) => this._opaque(target, fill, true);
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, channelsOrUndefined?: Channels, ): void { this._sigmoidalContrast( false, contrast, midpointOrPercentage, channelsOrUndefined, ); }
inverseTransparent = (color: MagickColor) => this._transparent(color, true);
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, gammaOrUndefined?: number, ): void { let channels = Channels.Composite; let blackPoint: Percentage; let whitePoint: Percentage; let gamma = this.valueOrDefault(gammaOrUndefined, 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") { gamma = whitePointPercentageOrGamma; } }
Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Level( this._instance, blackPoint.toDouble(), whitePoint.toQuantum(), gamma, channels, exception, ); }); }
linearStretch(blackPoint: Percentage, whitePoint: Percentage): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_LinearStretch( this._instance, blackPoint.toDouble(), whitePoint.toQuantum(), 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(channelsOrUndefined?: Channels): void { Exception.usePointer((exception) => { const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, ); ImageMagick._api._MagickImage_Negate( this._instance, 0, channels, exception, ); }); }
negateGrayScale(): void; negateGrayScale(channelsOrUndefined?: Channels): void { Exception.usePointer((exception) => { const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, ); ImageMagick._api._MagickImage_Negate( this._instance, 1, channels, 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, saturationOrUndefined?: Percentage, hueOrUndefined?: Percentage, ): void { const saturation = this.valueOrDefault( saturationOrUndefined, new Percentage(100), ); const hue = this.valueOrDefault(hueOrUndefined, new Percentage(100)); Exception.usePointer((exception) => { const modulate = `${brightness.toDouble()}/${saturation.toDouble()}/${hue.toDouble()}`; _withString(modulate, (modulatePtr) => { ImageMagick._api._MagickImage_Modulate( this._instance, modulatePtr, exception, ); }); }); }
motionBlur(radius: number, sigma: number, angle: number): void { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_MotionBlur( this._instance, radius, sigma, angle, exception.ptr, ); this._setInstance(instance, exception); }); }
morphology(settings: MorphologySettings): void { Exception.use((exception) => { _withString(settings.kernel, (kernelPtr) => { const instance = ImageMagick._api._MagickImage_Morphology( this._instance, settings.method, kernelPtr, settings.channels, settings.iterations, exception.ptr, ); this._setInstance(instance, exception); }); }); }
oilPaint(): void; oilPaint(radius: number): void; oilPaint(radiusOrUndefined?: number): void { const radius = this.valueOrDefault(radiusOrUndefined, 3); 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); }); }
opaque = (target: MagickColor, fill: MagickColor) => this._opaque(target, fill, false);
ping(fileName: string, settings?: MagickReadSettings): void; ping(array: ByteArray, settings?: MagickReadSettings): void; ping( fileNameOrArray: string | ByteArray, settingsOrUndefined?: MagickReadSettings, ): void { this.readOrPing(true, fileNameOrArray, settingsOrUndefined); }
read(color: MagickColor, width: number, height: number): void; read(fileName: string, settings?: MagickReadSettings): void; read(array: ByteArray, settings?: MagickReadSettings): void; read( fileNameOrArrayOrColor: string | ByteArray | MagickColor, settingsOrWidthOrUndefined?: MagickReadSettings | number, heightOrUndefined?: number, ): void { this.readOrPing( false, fileNameOrArrayOrColor, settingsOrWidthOrUndefined, heightOrUndefined, ); }
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); }); }
removeProfile(name: string): void { _withString(name, (namePtr) => { ImageMagick._api._MagickImage_RemoveProfile(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, heightOrUndefined?: number, ): void { const geometry = typeof widthOrGeometry === "number" ? new MagickGeometry(widthOrGeometry, heightOrUndefined 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); }); }
separate<TReturnType>( func: (images: IMagickImageCollection) => TReturnType, ): TReturnType; separate<TReturnType>( func: (images: IMagickImageCollection) => Promise<TReturnType>, ): Promise<TReturnType>; separate<TReturnType>( func: (images: IMagickImageCollection) => TReturnType, channels: Channels, ): TReturnType; separate<TReturnType>( func: (images: IMagickImageCollection) => Promise<TReturnType>, channels: Channels, ): Promise<TReturnType>; separate<TReturnType>( func: ( images: IMagickImageCollection, ) => TReturnType | Promise<TReturnType>, channelsOrUndefined?: Channels, ): TReturnType | Promise<TReturnType> { return Exception.use((exception) => { const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, ); const images = ImageMagick._api._MagickImage_Separate( this._instance, channels, exception.ptr, ); const collection = MagickImageCollection._createFromImages( images, this._settings, ); return collection._use(func); }); }
sepiaTone(): void; sepiaTone( numberOrPercentage: Percentage | number = new Percentage(80), ): void { Exception.use((exception) => { const threshold = typeof numberOrPercentage === "number" ? new Percentage(numberOrPercentage) : numberOrPercentage; const instance = ImageMagick._api._MagickImage_SepiaTone( this._instance, threshold.toQuantum(), exception.ptr, ); this._setInstance(instance, exception); }); }
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, ); }); }); }); }
setProfile(name: string, data: ByteArray): void { Exception.use((exception) => { _withString(name, (namePtr) => { _withByteArray(data, (dataPtr) => { ImageMagick._api._MagickImage_SetProfile( this._instance, namePtr, dataPtr, data.byteLength, exception.ptr, ); }); }); }); }
setWriteMask(image: IMagickImage): void { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_SetWriteMask( this._instance, image._instance, exception, ); }); }
sharpen(): void; sharpen(radius: number, sigma: number): void; sharpen(radius: number, sigma: number, channels: Channels): void; sharpen( radiusOrUndefined?: number, sigmaOrUndefined?: number, channelsOrUndefined?: Channels, ): void { const radius = this.valueOrDefault(radiusOrUndefined, 0.0); const sigma = this.valueOrDefault(sigmaOrUndefined, 1.0); const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, );
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Sharpen( this._instance, radius, sigma, channels, 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, channelsOrUndefined?: Channels, ): void { this._sigmoidalContrast( true, contrast, midpointOrPercentage, channelsOrUndefined, ); }
solarize(): void; solarize(numberOrPercentage: Percentage | number = new Percentage(50)): void { Exception.use((exception) => { const factor = typeof numberOrPercentage === "number" ? new Percentage(numberOrPercentage) : numberOrPercentage; ImageMagick._api._MagickImage_Solarize( this._instance, factor.toQuantum(), exception.ptr, ); }); }
splice(geometry: MagickGeometry): void { MagickRectangle.use(this, geometry, (geometryPtr) => { Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Splice( this._instance, geometryPtr, exception.ptr, ); this._setInstance(instance, exception); }); }); }
statistics(): IStatistics; statistics(channels: Channels): IStatistics; statistics(channelsOrUndefined?: Channels): IStatistics { const channels = this.valueOrDefault(channelsOrUndefined, Channels.Default); return Exception.usePointer((exception) => { const list = ImageMagick._api._MagickImage_Statistics( this._instance, channels, exception, ); const statistics = Statistics._create(this, list, channels); ImageMagick._api._Statistics_DisposeList(list); return statistics; }); }
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] }`;
transparent(color: MagickColor): void { color._use((valuePtr) => { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Transparent( this._instance, valuePtr, 0, exception, ); }); }); }
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 = this.valueOrDefault(methodOrUndefined, this.interpolate); const amplitude = this.valueOrDefault(amplitudeOrUndefined, 25); const length = this.valueOrDefault(lengthOrUndefined, 150);
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 = this.valueOrDefault(radiusOrUndefined, 0); const sigma = this.valueOrDefault(sigmaOrUndefined, 1.0); const x = this.valueOrDefault(xOrUndefined, 0); const y = this.valueOrDefault(yOrUndefined, 0);
Exception.use((exception) => { const instance = ImageMagick._api._MagickImage_Vignette( this._instance, radius, sigma, x, y, exception.ptr, ); this._setInstance(instance, exception); }); }
write<TReturnType>(func: (data: Uint8Array) => TReturnType): TReturnType; write<TReturnType>( format: MagickFormat, func: (data: Uint8Array) => TReturnType, ): TReturnType; write<TReturnType>( func: (data: Uint8Array) => Promise<TReturnType>, ): Promise<TReturnType>; write<TReturnType>( format: MagickFormat, func: (data: Uint8Array) => Promise<TReturnType>, ): Promise<TReturnType>; write<TReturnType>( funcOrFormat: | ((data: Uint8Array) => TReturnType | Promise<TReturnType>) | MagickFormat, func?: (data: Uint8Array) => TReturnType | Promise<TReturnType>, ): TReturnType | Promise<TReturnType> { let data = 0; let length = 0;
if (func !== undefined) { this._settings.format = funcOrFormat as MagickFormat; } else { func = funcOrFormat as ( data: Uint8Array, ) => TReturnType | Promise<TReturnType>; }
Exception.use((exception) => { Pointer.use((pointer) => { this._settings._use((settings) => { try { data = ImageMagick._api._MagickImage_WriteBlob( this._instance, settings._instance, pointer.ptr, exception.ptr, ); length = pointer.value; } catch { if (data !== 0) { data = ImageMagick._api._MagickMemory_Relinquish(data); } } }); }); });
const array = new DisposableArray(data, length, func); return Disposable._disposeAfterExecution(array, array.func); }
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 */ static _clone(image: MagickImage): MagickImage { return Exception.usePointer((exception) => { return new MagickImage( ImageMagick._api._MagickImage_Clone(image._instance, exception), image._settings._clone(), ); }); }
/** @internal */ _getSettings(): MagickSettings { return this._settings; }
/** @internal */ protected _instanceNotInitialized(): void { throw new MagickError("no image has been read"); }
/** @internal */ _use<TReturnType>(func: (image: IMagickImage) => TReturnType): TReturnType; /** @internal */ _use<TReturnType>( func: (image: IMagickImage) => Promise<TReturnType>, ): Promise<TReturnType>; _use<TReturnType>( func: (image: IMagickImage) => TReturnType | Promise<TReturnType>, ): TReturnType | Promise<TReturnType> { return Disposable._disposeAfterExecution(this, func); }
/** @internal */ static _use<TReturnType>( func: (image: IMagickImage) => TReturnType, ): TReturnType; /** @internal */ 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(); return image._use<TReturnType>(func); }
private _contrast(enhance: boolean) { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Contrast( this._instance, this.fromBool(enhance), exception, ); }); }
private _opaque(target: MagickColor, fill: MagickColor, invert: boolean) { Exception.usePointer((exception) => { target._use((targetPtr) => { fill._use((filltPtr) => { ImageMagick._api._MagickImage_Opaque( this._instance, targetPtr, filltPtr, this.fromBool(invert), exception, ); }); }); }); }
private _sigmoidalContrast( sharpen: boolean, contrast: number, midpointOrPercentage?: number | Percentage, channelsOrUndefined?: 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; } const channels = this.valueOrDefault( channelsOrUndefined, Channels.Undefined, ); Exception.usePointer((exception) => { ImageMagick._api._MagickImage_SigmoidalContrast( this._instance, this.fromBool(sharpen), contrast, midpoint, channels, exception, ); }); }
private _transparent(color: MagickColor, invert: boolean) { color._use((valuePtr) => { Exception.usePointer((exception) => { ImageMagick._api._MagickImage_Transparent( this._instance, valuePtr, this.fromBool(invert), 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 | ByteArray | MagickColor, settingsOrWidthOrUndefined?: MagickReadSettings | number, heightOrUndefined?: number, ): void { Exception.use((exception) => { const readSettings = settingsOrWidthOrUndefined instanceof MagickReadSettings ? settingsOrWidthOrUndefined : 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 settingsOrWidthOrUndefined === "number" ? settingsOrWidthOrUndefined : 0; readSettings.height = typeof heightOrUndefined === "number" ? heightOrUndefined : 0; } else { this.readFromArray(fileNameOrArrayOrColor, readSettings, exception); return; } readSettings._use((settings) => { const instance = ImageMagick._api._MagickImage_ReadFile( settings._instance, exception.ptr, ); this._setInstance(instance, exception); }); }); }
private readFromArray( array: ByteArray, readSettings: MagickReadSettings, exception: Exception, ): void { readSettings._use((settings) => { _withByteArray(array, (arrayPtr) => { const instance = ImageMagick._api._MagickImage_ReadBlob( settings._instance, arrayPtr, 0, array.byteLength, exception.ptr, ); this._setInstance(instance, exception); }); }); }
private toBool(value: number): boolean { return value === 1; }
private valueOrDefault<TType>( value: TType | undefined, defaultValue: TType, ): TType { if (value === undefined) { return defaultValue; }
return value; }}