magick-wasm

repository·main·Indexed 21 days ago

https://github.com/dlemstra/magick-wasm

A WebAssembly port of ImageMagick (@imagemagick/magick-wasm) that enables high-performance image manipulation in web browsers, Node.js, and Deno without external dependencies. It supports over 100 major file formats and provides comprehensive enumerations for color spaces, composite operators, compression methods, convolution kernels, and image formats.

Tokens
7.4K
Snippets
16
Records
18
Agent score
75%

What's inside magick-wasm

  1. Overview of magick-wasm

    main
    magick-wasm is a WebAssembly-based library that brings the power of ImageMagick to web applications, Node.js, and Deno. It allows you to perform image manipulation supporting over 100 major file formats directly in your runtime without requiring a backend API callback or a system-level installation of ImageMagick.
  2. List of supported ColorSpace values

    main

    The following color spaces are supported by the ColorSpace enumeration:

    export const ColorSpace = {
        Undefined: 0,
        CMY: 1,
        CMYK: 2,
        Gray: 3,
        HCL: 4,
        HCLp: 5,
        HSB: 6,
        HSI: 7,
        HSL: 8,
        HSV: 9,
        HWB: 10,
        Lab: 11,
        LCH: 12,
        LCHab: 13,
        LCHuv: 14,
        Log: 15,
        LMS: 16,
        Luv: 17,
        OHTA: 18,
        Rec601YCbCr: 19,
        Rec709YCbCr: 20,
        RGB: 21,
        scRGB: 22,
        sRGB: 23,
        Transparent: 24,
        XyY: 25,
        XYZ: 26,
        YCbCr: 27,
        YCC: 28,
        YDbDr: 29,
        YIQ: 30,
        YPbPr: 31,
        YUV: 32,
        LinearGray: 33,
        Jzazbz: 34,
        DisplayP3: 35,
        Adobe98: 36,
        ProPhoto: 37,
        Oklab: 38,
        Oklch: 39,
        CAT02LMSC: 40,
    } as const;
  3. Available EvaluateOperator values

    main

    The EvaluateOperator enum specifies the mathematical or logical operators used during pixel evaluation in ImageMagick operations. Use these values when calling APIs that require an evaluation operator to determine how pixel values are transformed or compared.

    export const EvaluateOperator = {
        Undefined: 0,
        Abs: 1,
        Add: 2,
        AddModulus: 3,
        And: 4,
        Cosine: 5,
        Divide: 6,
        Exponential: 7,
        GaussianNoise: 8,
        ImpulseNoise: 9,
        LaplacianNoise: 10,
        LeftShift: 11,
        Log: 12,
        Max: 13,
        Mean: 14,
        Median: 15,
        Min: 16,
        MultiplicativeNoise: 17,
        Multiply: 18,
        Or: 19,
        PoissonNoise: 20,
        Pow: 21,
        RightShift: 22,
        RootMeanSquare: 23,
        Set: 24,
        Sine: 25,
        Subtract: 26,
        Sum: 27,
        ThresholdBlack: 28,
        Threshold: 29,
        ThresholdWhite: 30,
        UniformNoise: 31,
        Xor: 32,
        InverseLog: 33
    } as const;
    
    export type EvaluateOperator = typeof EvaluateOperator[keyof typeof EvaluateOperator];
  4. Identify MagickError severity levels

    main

    The MagickErrorSeverity object provides a set of numeric constants used to specify the severity of a MagickError. These levels are categorized into two main groups: Warnings (values in the 300s) and Errors (values in the 400s). Use these constants when handling or inspecting error reports from the ImageMagick WebAssembly module to determine if an issue is a non-fatal warning or a fatal error.

    // Example of how severity levels are structured
    import { MagickErrorSeverity } from '@imagemagick/magick-wasm';
    
    // Warnings (300-399)
    const warningLevel = MagickErrorSeverity.Warning; // 300
    const corruptImageWarning = MagickErrorSeverity.CorruptImageWarning; // 325
    
    // Errors (400-499)
    const errorLevel = MagickErrorSeverity.Error; // 400
    const policyError = MagickErrorSeverity.PolicyError; // 499
  5. Available CompositeOperator values

    main

    The CompositeOperator enum specifies the different operators used when composing images (e.g., blending, masking, or mathematical operations between a source and destination image). Use these values in image composition methods to define how pixels from the source image interact with the destination image.

    export const CompositeOperator = {
        Undefined: 0,
        Alpha: 1,
        Atop: 2,
        Blend: 3,
        Blur: 4,
        Bumpmap: 5,
        ChangeMask: 6,
        Clear: 7,
        ColorBurn: 8,
        ColorDodge: 9,
        Colorize: 10,
        CopyBlack: 11,
        CopyBlue: 12,
        Copy: 13,
        CopyCyan: 14,
        CopyGreen: 15,
        CopyMagenta: 16,
        CopyAlpha: 17,
        CopyRed: 18,
        CopyYellow: 19,
        Darken: 20,
        DarkenIntensity: 21,
        Difference: 22,
        Displace: 23,
        Dissolve: 24,
        Distort: 25,
        DivideDst: 26,
        DivideSrc: 27,
        DstAtop: 28,
        Dst: 29,
        DstIn: 30,
        DstOut: 31,
        DstOver: 32,
        Exclusion: 33,
        HardLight: 34,
        HardMix: 35,
        Hue: 36,
        In: 37,
        Intensity: 38,
        Lighten: 39,
        LightenIntensity: 40,
        LinearBurn: 41,
        LinearDodge: 42,
        LinearLight: 43,
        Luminize: 44,
        Mathematics: 45,
        MinusDst: 46,
        MinusSrc: 47,
        Modulate: 48,
        ModulusAdd: 49,
        ModulusSubtract: 50,
        Multiply: 51,
        No: 52,
        Out: 53,
        Over: 54,
        Overlay: 55,
        PegtopLight: 56,
        PinLight: 57,
        Plus: 58,
        Replace: 59,
        Saturate: 60,
        Screen: 61,
        SoftLight: 62,
        SrcAtop: 63,
        Src: 64,
        SrcIn: 65,
        SrcOut: 66,
        SrcOver: 67,
        Threshold: 68,
        VividLight: 69,
        Xor: 70,
        Stereo: 71,
        Freeze: 72,
        Interpolate: 73,
        Negate: 74,
        Reflect: 75,
        SoftBurn: 76,
        SoftDodge: 77,
        Stamp: 78,
        RMSE: 79,
        SaliencyBlend: 80,
        SeamlessBlend: 81
    } as const;
    
    export type CompositeOperator = typeof CompositeOperator[keyof typeof CompositeOperator];
  6. Reference the LogEventTypes enumeration

    main

    The LogEventTypes object provides bitmask values used to specify or filter ImageMagick log event types. You can use these values to categorize or select specific types of logging events, such as Exception, Image, or Resource. The All property is a convenience getter that combines Detailed and Trace events.

    export const LogEventTypes = {
        None: 0x000000,
        Accelerate: 0x00001,
        Annotate: 0x00002,
        Blob: 0x00004,
        Cache: 0x00008,
        Coder: 0x00010,
        Configure: 0x00020,
        Deprecate: 0x00040,
        Draw: 0x00080,
        Exception: 0x00100,
        Image: 0x00200,
        Locale: 0x00400,
        Module: 0x00800,
        Pixel: 0x01000,
        Policy: 0x02000,
        Resource: 0x04000,
        Trace: 0x08000,
        Transform: 0x10000,
        User: 0x20000,
        Wand: 0x40000,
        Detailed: 0x7fff7fff,
        get All() { return this.Detailed | this.Trace; }
    } as const;
    
    export type LogEventTypes = typeof LogEventTypes[keyof typeof LogEventTypes];
  7. Available built-in convolution kernels in Kernel

    main

    The Kernel object provides a set of predefined convolution kernel types used for image processing operations. You can use these constants to specify which built-in kernel to apply during convolution tasks.

    Available kernels include:

    • Standard/Mathematical: Gaussian, Blur, Binomial, Laplacian, Chebyshev, Euclidean
    • Edge Detection/Gradient: Sobel, FreiChen, Roberts, Prewitt, Kirsch, Edges, Corners, Diagonals, LineEnds, LineJunctions, Ridges
    • Geometric/Shape: Diamond, Square, Rectangle, Octagon, Octagonal, Disk, Plus, Cross, Ring, ConvexHull, Manhattan
    • Specialty: DoG (Difference of Gaussians), LoG (Laplacian of Gaussian), Comet, Compass, Peaks, ThinSE, Skeleton
    • Other: Unity, Undefined, UserDefined
    import { Kernel } from '@imagemagick/magick-wasm';
    
    // Example usage of a kernel constant
    const myKernel: Kernel = Kernel.Gaussian;
  8. Available image compression methods in CompressionMethod

    main

    The CompressionMethod object provides a set of constants used to specify different image compression algorithms within magick-wasm. Use these values when configuring compression settings for image operations.

    export const CompressionMethod = {
        Undefined: 0,
        B44A: 1,
        B44: 2,
        BZip: 3,
        DXT1: 4,
        DXT3: 5,
        DXT5: 6,
        Fax: 7,
        Group4: 8,
        JBIG1: 9,
        JBIG2: 10,
        JPEG2000: 11,
        JPEG: 12,
        LosslessJPEG: 13,
        LZMA: 14,
        LZW: 15,
        NoCompression: 16,
        Piz: 17,
        Pxr24: 18,
        RLE: 19,
        Zip: 20,
        ZipS: 21,
        Zstd: 22,
        WebP: 23,
        DWAA: 24,
        DWAB: 25,
        BC7: 26,
        BC5: 27
    } as const;
    
    export type CompressionMethod = typeof CompressionMethod[keyof typeof CompressionMethod];
  9. Available convolution filter types in FilterType

    main

    The FilterType object provides a set of constants used to specify different convolution filter types for image processing operations. These values are used when configuring filters for operations like resizing or blurring.

    export const FilterType = {
        Undefined: 0,
        Point: 1,
        Box: 2,
        Triangle: 3,
        Hermite: 4,
        Hann: 5,
        Hamming: 6,
        Blackman: 7,
        Gaussian: 8,
        Quadratic: 9,
        Cubic: 10,
        Catrom: 11,
        Mitchell: 12,
        Jinc: 13,
        Sinc: 14,
        SincFast: 15,
        Kaiser: 16,
        Welch: 17,
        Parzen: 18,
        Bohman: 19,
        Bartlett: 20,
        Lagrange: 21,
        Lanczos: 22,
        LanczosSharp: 23,
        Lanczos2: 24,
        Lanczos2Sharp: 25,
        Robidoux: 26,
        RobidouxSharp: 27,
        Cosine: 28,
        Spline: 29,
        LanczosRadius: 30,
        CubicSpline: 31,
        MagicKernelSharp2013: 32,
        MagicKernelSharp2021: 33,
    } as const;
    
    export type FilterType = typeof FilterType[keyof typeof FilterType];
  10. Reference the MagickFormat enumeration

    main

    The following is the complete list of supported image formats and their corresponding string values available in the MagickFormat object.

    export const MagickFormat = {
        Unknown: 'UNKNOWN',
        ThreeFr: '3FR',
        ThreeG2: '3G2',
        ThreeGp: '3GP',
        A: 'A',
        Aai: 'AAI',
        Ai: 'AI',
        APng: 'APNG',
        Art: 'ART',
        Arw: 'ARW',
        Ashlar: 'ASHLAR',
        Avci: 'AVCI',
        Avi: 'AVI',
        Avif: 'AVIF',
        Avs: 'AVS',
        B: 'B',
        Bayer: 'BAYER',
        Bayera: 'BAYERA',
        Bgr: 'BGR',
        Bgra: 'BGRA',
        Bgro: 'BGRO',
        Bmp: 'BMP',
        Bmp2: 'BMP2',
        Bmp3: 'BMP3',
        Brf: 'BRF',
        C: 'C',
        Cal: 'CAL',
        Cals: 'CALS',
        Canvas: 'CANVAS',
        Caption: 'CAPTION',
        Cin: 'CIN',
        Cip: 'CIP',
        Clip: 'CLIP',
        Cmyk: 'CMYK',
        Cmyka: 'CMYKA',
        Cr2: 'CR2',
        Cr3: 'CR3',
        Crw: 'CRW',
        Cube: 'CUBE',
        Cur: 'CUR',
        Cut: 'CUT',
        Data: 'DATA',
        Dcm: 'DCM',
        Dcr: 'DCR',
        Dcraw: 'DCRAW',
        Dcx: 'DCX',
        Dds: 'DDS',
        Dfont: 'DFONT',
        Dng: 'DNG',
        Dpx: 'DPX',
        Dxt1: 'DXT1',
        Dxt5: 'DXT5',
        Epdf: 'EPDF',
        Epi: 'EPI',
        Eps: 'EPS',
        Eps2: 'EPS2',
        Eps3: 'EPS3',
        Epsf: 'EPSF',
        Epsi: 'EPSI',
        Ept: 'EPT',
        Ept2: 'EPT2',
        Ept3: 'EPT3',
        Erf: 'ERF',
        Exr: 'EXR',
        Farbfeld: 'FARBFELD',
        Fax: 'FAX',
        Ff: 'FF',
        Fff: 'FFF',
        File: 'FILE',
        Fits: 'FITS',
        Fl32: 'FL32',
        Flv: 'FLV',
        Fractal: 'FRACTAL',
        Ftp: 'FTP',
        Fts: 'FTS',
        Ftxt: 'FTXT',
        G: 'G',
        G3: 'G3',
        G4: 'G4',
        Gif: 'GIF',
        Gif87: 'GIF87',
        Gradient: 'GRADIENT',
        Gray: 'GRAY',
        Graya: 'GRAYA',
        Group4: 'GROUP4',
        Hald: 'HALD',
        Hdr: 'HDR',
        Heic: 'HEIC',
        Heif: 'HEIF',
        Histogram: 'HISTOGRAM',
        Hrz: 'HRZ',
        Htm: 'HTM',
        Html: 'HTML',
        Http: 'HTTP',
        Https: 'HTTPS',
        Icb: 'ICB',
        Ico: 'ICO',
        Icon: 'ICON',
        Icn: 'ICN',
        Iiq: 'IIQ',
        Info: 'INFO',
        Inline: 'INLINE',
        Ipl: 'IPL',
        Isobrl: 'ISOBRL',
        Isobrl6: 'ISOBRL6',
        J2c: 'J2C',
        J2k: 'J2K',
        Jng: 'JNG',
        Jnx: 'JNX',
        Jp2: 'JP2',
        Jpc: 'JPC',
        Jpe: 'JPE',
        Jpeg: 'JPEG',
        Jpg: 'JPG',
        Jpm: 'JPM',
        Jps: 'JPS',
        Jpt: 'JPT',
        Json: 'JSON',
        Jxl: 'JXL',
        K: 'K',
        K25: 'K25',
        Kdc: 'KDC',
        Label: 'LABEL',
        M: 'M',
        M2v: 'M2V',
        M4v: 'M4V',
        Mac: 'MAC',
        Map: 'MAP',
        Mask: 'MASK',
        Mat: 'MAT',
        Matte: 'MATTE',
        Mdc: 'MDC',
        Mef: 'MEF',
        Miff: 'MIFF',
        Mkv: 'MKV',
        Mng: 'MNG',
        Mono: 'MONO',
        Mov: 'MOV',
        Mos: 'MOS',
        Mp4: 'MP4',
        Mpc: 'MPC',
        Mpeg: 'MPEG',
        Mpg: 'MPG',
        Mpo: 'MPO',
        Mrw: 'MRW',
        Msl: 'MSL',
        Msvg: 'MSVG',
        Mtv: 'MTV',
        Mvg: 'MVG',
        Nef: 'NEF',
        Nrw: 'NRW',
        Null: 'NULL',
        O: 'O',
        Ora: 'ORA',
        Orf: 'ORF',
        Otb: 'OTB',
        Otf: 'OTF',
        Pal: 'PAL',
        Palm: 'PALM',
        Pam: 'PAM',
        Pango: 'PANGO',
        Pattern: 'PATTERN',
        Pbm: 'PBM',
        Pcd: 'PCD',
        Pcds: 'PCDS',
        Pcl: 'PCL',
        Pct: 'PCT',
        Pcx: 'PCX',
        Pdb: 'PDB',
        Pbm: 'PBM',
        Pgm: 'PGM',
        Pgx: 'PGX',
        Phm: 'PHM',
        Picon: 'PICON',
        Pict: 'PICT',
        Pix: 'PIX',
        Pjpeg: 'PJPEG',
        Plasma: 'PLASMA',
        Pnm: 'PNM',
        Pocketmod: 'POCKETMOD',
        Ppm: 'PPM',
        Ps: 'PS',
        Ps2: 'PS2',
        Ps3: 'PS3',
        Psb: 'PSB',
        Psd: 'PSD',
        Ptif: 'PTIF',
        Pwp: 'PWP',
        Qoi: 'QOI',
        R: 'R',
        RadialGradient: 'RADIAL-GRADIENT',
        Raf: 'RAF',
        Ras: 'RAS',
        Raw: 'RAW',
        Rgb: 'RGB',
        Rgb565: 'RGB565',
        Rgba: 'RGBA',
        Rgbo: 'RGBO',
        Rgf: 'RGF',
        Rla: 'RLA',
        Rle: 'RLE',
        Rmf: 'RMF',
        Rw2: 'RW2',
        Rwl: 'RWL',
        Scr: 'SCR',
        Screenshot: 'SCREENSHOT',
        Sct: 'SCT',
        Sf3: 'SF3',
        Sfw: 'SFW',
        Sgi: 'SGI',
        Shtml: 'SHTML',
        Six: 'SIX',
        Sixel: 'SIXEL',
        SparseColor: 'SPARSE-COLOR',
        Sr2: 'SR2',
        Srf: 'SRF',
        Srw: 'SRW',
        Sti: 'STI',
        StrImg: 'STRIMG',
        Sun: 'SUN',
        Svg: 'SVG',
        Svgz: 'SVGZ',
        Text: 'TEXT',
        Tga: 'TGA',
        Thumbnail: 'THUMBNAIL',
        Tif: 'TIF',
        Tiff: 'TIFF',
        Tiff64: 'TIFF64',
        Tile: 'TILE',
        Tim: 'TIM',
        Tm2: 'TM2',
        Ttc: 'TTC',
        Ttf: 'TTF',
        Txt: 'TXT',
        Ubrl: 'UBRL',
        Ubrl6: 'UBRL6',
        Uil: 'UIL',
        Uyvy: 'UYVY',
        Vda: 'VDA',
        Vicar: 'VICAR',
        Vid: 'VID',
        Viff: 'VIFF',
        Vips: 'VIPS',
        Vst: 'VST',
        WebM: 'WEBM',
        WebP: 'WEBP',
        Wbmp: 'WBMP',
        Wmv: 'WMV',
        Wpg: 'WPG',
        X3f: 'X3F',
        Xbm: 'XBM',
        Xc: 'XC',
        Xcf: 'XCF',
        Xpm: 'XPM',
        Xps: 'XPS',
        Xv: 'XV',
        Y: 'Y',
        Yaml: 'YAML',
        Ycbcr: 'YCBCR',
        Ycbcra: 'YCBCRA',
        Yuv: 'YUV',
    } as const;