image

    Image codec primitives for MoonBit with PNG/BMP/JPEG decode+encode, GIF/WebP/ICO/AVIF encode, and resize.

    moonbit
    image
    bmp
    jpeg
    gif
    png
    webp
    ico
    tiff
    apng
    avif
    encoder
    decoder
    Download zip
    Author
    Version
    0.5.0
    License
    Apache-2.0
    Last updated
    7 days ago
    Downloads
    28K

    #mizchi/image

    Image codec primitives for MoonBit: decode PNG / APNG / JPEG / GIF / BMP / ICO / TIFF / WebP, encode PNG / APNG / JPEG / GIF / BMP / TIFF / WebP (lossy / lossless, still and animated) / ICO / AVIF, resize, and EXIF orientation. Codecs have no external dependencies except mizchi/zlib.

    All decoded images are normalized to ImageData (RGBA8 buffer).

    #Install

    moon add mizchi/image

    #Usage

    // Auto-detect PNG / JPEG / GIF / BMP / ICO / TIFF / WebP
    let img = @image.decode_image(image_bytes)

    // Photos: apply the EXIF orientation so they display upright
    let photo = @image.decode_image_upright(jpeg_bytes)

    // Resize and re-encode
    let resized = @image.resize(img, 128, 128, Bilinear)
    let png = @image.encode_png(resized)
    // Smallest exact PNG color type, best compression
    let small_png = @image.encode_png(resized, color=Auto, compression=Best)

    // JPEG encode (quality defaults to 85, subsampling to Yuv444)
    let jpg = @image.encode_jpeg(resized)
    let small = @image.encode_jpeg(resized, quality=75, subsampling=Yuv420)

    // Other encoders
    let gif = @image.encode_gif(resized) // <= 256 colors, alpha 0/255 only
    let webp = @image.encode_webp(resized) // lossless
    let ico = @image.encode_ico(resized) // single PNG-backed icon, <= 256x256
    let avif = @image.encode_avif(resized, quality=75) // lossy AV1

    // Animations: every frame is the composited canvas, with its delay
    let apng = @image.decode_png_frames(png_bytes)
    for frame in apng.frames {
    ignore((frame.image, frame.delay_ms))
    }
    let gif_anim = @image.decode_gif_frames(gif_bytes)

    // Encode animations (every frame is a full canvas)
    let apng_out = @image.encode_apng(apng)
    let gif_out = @image.encode_gif_animation(apng)

    // Detect the format, or decode row by row (PNG / BMP are streamed)
    let format = @image.detect_image_format(image_bytes)
    let rows : Array[Bytes] = []
    let info = @image.decode_image_stream(
    image_bytes,
    on_row=fn(_y, row) { rows.push(row) },
    )
    inspect((info.format, info.width, info.height))

    #Support

    FormatDecodeEncodeAnimationStream decode
    PNGyesyes (RGBA / RGB / gray / gray+alpha / palette)APNG decode / encodeyes (streamed)
    JPEGyesyesn/ayes
    GIFyesyesdecode / encodeyes
    BMPyesyes (32-bit)n/ayes (streamed)
    ICO / CURyesyes (ICO, PNG payload)n/ayes
    TIFFyes (all pages)yes (RGB / RGBA)n/ayes
    WebPyes (lossy / lossless / alpha)yes (lossy / lossless)decode / encodeyes
    AVIFnoyes (lossy, alpha)nono

    All codecs run on every target: js, native, wasm and wasm-gc. decode_image_stream reads rows as they are decoded for PNG and BMP; other formats are decoded first, then emitted row by row.

    #Details

    • PNG decode: grayscale / RGB / palette / gray+alpha / RGBA at 1, 2, 4, 8 and 16 bits (16-bit uses the high byte), tRNS transparency, Adam7 interlace. APNG (decode_png_frames): fcTL / fdAT, dispose none / background / previous, blend source / over; decode_png returns the default image. Encode: RGBA8 by default, or RGB / gray / gray+alpha / palette (1-8 bit, tRNS) / Auto, with adaptive row filtering and four compression levels. encode_apng writes APNG from an Animation, cropping each frame to the changed region.
    • JPEG decode: baseline, extended sequential and progressive (8-bit, Huffman), any sampling factors, multiple scans, restart markers; grayscale, YCbCr, RGB, CMYK and YCCK (the color space is inferred from the JFIF / Adobe markers and component IDs like libjpeg-turbo; CMYK uses the Adobe inverted convention and is converted to RGB like Pillow, without ICC). Output is identical to libjpeg / libjpeg-turbo (islow IDCT, fancy upsampling, fixed-point color conversion). Encode: baseline with 4:4:4 / 4:2:2 / 4:2:0, standard or optimize=true (per-image) Huffman tables; the tables and entropy-coded data are identical to libjpeg's for the same quality, subsampling and optimize setting.
    • GIF decode: GIF87a / 89a, global and local color tables, interlace, transparency, animation with disposal 1-3, delays and the NETSCAPE loop count (frames are composited onto a transparent canvas, like browsers). Encode: LZW-compressed; encode_gif for one image and encode_gif_animation for an Animation (global or local palettes, changed-region cropping). At most 256 colors per frame, alpha 0 or 255.
    • BMP decode: 1 / 2 / 4 / 8-bit palette, RLE4 / RLE8, 16 / 24 / 32-bit, BI_BITFIELDS / BI_ALPHABITFIELDS, V2-V5 and OS/2 headers. Encode: 32-bit BGRA.
    • ICO / CUR decode: PNG or BMP (DIB) payloads with the AND mask; decode_ico returns the largest image, decode_ico_all every image. Encode: one image up to 256x256 with a PNG payload.
    • TIFF decode (decode_tiff for the first image, decode_tiff_pages for every page): little / big endian, strips and tiles, chunky and planar samples, None / LZW / Deflate / PackBits with the horizontal predictor, JPEG (compression 7, with JPEGTables; raw components like libtiff, YCbCr converted to RGB), WhiteIsZero / BlackIsZero / RGB / palette / CMYK, 1-16 bits per sample, extra alpha (associated alpha is un-premultiplied).
    • WebP decode: lossy (VP8), lossless (VP8L, all transforms, color cache, meta prefix codes), alpha (ALPH, raw or lossless, with spatial filters), and animation (decode_webp_frames: ANMF frames composited like libwebp's WebPAnimDecoder, with blending, disposal and the loop count). Output is identical to libwebp (RGBA, fancy upsampling). Encode: lossless (VP8L) with length-limited Huffman codes, a cost-based LZ77 parse, color cache, meta prefix codes and the subtract-green / predictor / cross-color / palette transforms (the smallest of several configurations is kept; on our test set about 6% smaller than libwebp's default lossless mode and on par with its slowest, -m 6); encode_webp_lossy(quality~) writes VP8 (rate-distortion optimized 4x4 / 16x16 / chroma intra modes, adaptive token probabilities, loop filter; alpha as a lossless, spatially filtered ALPH chunk) with libwebp's quality scale; on our test set files are about 3% smaller than libwebp's at the same PSNR. encode_webp_animation writes an animated WebP from an Animation (lossless frames cropped to the changed region, no blending).
    • AVIF encode: encode_avif(quality~) writes an AV1 still picture (8-bit 4:2:0, BT.601 full range) in pure MoonBit: rate-distortion optimized partitions (64x64 down to 8x8), all 13 intra modes, the DCT / ADST / identity transform types and the deblocking filter. Non-opaque alpha is stored as a monochrome auxiliary image. The quality scale follows libavif's; on our test set files are about 5% larger than libavif's (libaom, speed 6) at the same luma PSNR, except screen content (palette mode is not used). Up to 4096 pixels wide and 4096x2304 pixels (one tile). The reconstruction is checked to be identical to dav1d's decode.
    • Resize: Nearest, and fixed-point separable Bilinear / Bicubic.
    • EXIF orientation: read_exif_orientation reads the tag from JPEG, PNG (eXIf), TIFF and WebP (EXIF); apply_orientation applies it with the same mapping as Pillow's exif_transpose; decode_image_upright does both.

    #Not supported

    • JPEG: arithmetic coding, lossless and hierarchical modes, 12-bit samples. Decoders return stored pixels; use decode_image_upright / apply_orientation for EXIF orientation.
    • TIFF: old-style JPEG (compression 6), CCITT and other compressions, BigTIFF, floating-point samples, uncompressed YCbCr.
    • AVIF decode; lossy frames in animated WebP.
    • Color management (ICC profiles, gamma) is not applied.

    Unsupported inputs raise DecodeError::UnsupportedFeature.

    #Robustness and compatibility

    • Decoders raise DecodeError on malformed input instead of panicking. This is covered by a mutation fuzz test over every format.
    • Images larger than 2^27 pixels (134M) are rejected with UnsupportedFeature("image too large"), and PNG / TIFF zlib data is never inflated beyond the size the header implies.
    • Decoders are tested against Pillow (libjpeg-turbo, libtiff, libpng, libwebp) fixtures. JPEG decode and encode, and WebP decode, are checked for exact equality with libjpeg / libwebp.
    • On the wasm (linear memory) target, hot loops use 128-bit SIMD through inline WAT: PNG filters and color expansion, JPEG IDCT / FDCT, the WebP (VP8) loop filter, and resize. Other targets run scalar code that gives identical output. A wasm runtime with SIMD support is required.

    #API

    // Auto-detect pub fn decode_image(Bytes) -> ImageData raise DecodeError pub fn decode_image_stream(Bytes, on_row~ : (Int, Bytes) -> Unit) -> StreamImageInfo raise DecodeError pub fn detect_image_format(Bytes) -> ImageFormat? // PNG / APNG pub fn decode_png(Bytes) -> ImageData raise DecodeError pub fn decode_png_frames(Bytes) -> Animation raise DecodeError pub fn decode_png_stream(Bytes, on_row~ : (Int, Bytes) -> Unit) -> IhdrData raise DecodeError pub fn encode_png(ImageData, color? : PngColorMode = Rgba, compression? : PngCompression = Default) -> Bytes raise EncodeError pub fn encode_apng(Animation) -> Bytes raise EncodeError // JPEG pub fn decode_jpeg(Bytes) -> ImageData raise DecodeError pub fn encode_jpeg(ImageData, quality? : Int = 85, subsampling? : JpegSubsampling = Yuv444, optimize? : Bool = false) -> Bytes raise EncodeError // GIF pub fn decode_gif(Bytes) -> ImageData raise DecodeError pub fn decode_gif_frames(Bytes) -> Animation raise DecodeError pub fn encode_gif(ImageData) -> Bytes raise EncodeError pub fn encode_gif_animation(Animation) -> Bytes raise EncodeError // BMP pub fn decode_bmp(Bytes) -> ImageData raise DecodeError pub fn decode_bmp_stream(Bytes, on_row~ : (Int, Bytes) -> Unit) -> (Int, Int) raise DecodeError pub fn encode_bmp(ImageData) -> Bytes raise EncodeError // ICO / CUR pub fn decode_ico(Bytes) -> ImageData raise DecodeError pub fn decode_ico_all(Bytes) -> Array[ImageData] raise DecodeError pub fn encode_ico(ImageData) -> Bytes raise EncodeError // TIFF pub fn decode_tiff(Bytes) -> ImageData raise DecodeError pub fn decode_tiff_pages(Bytes) -> Array[ImageData] raise DecodeError pub fn encode_tiff(ImageData, compression? : TiffCompression = Lzw) -> Bytes raise EncodeError // WebP / AVIF pub fn decode_webp(Bytes) -> ImageData raise DecodeError pub fn decode_webp_frames(Bytes) -> Animation raise DecodeError pub fn encode_webp(ImageData) -> Bytes raise EncodeError // lossless pub fn encode_webp_lossy(ImageData, quality? : Int = 75) -> Bytes raise EncodeError pub fn encode_webp_animation(Animation) -> Bytes raise EncodeError pub fn encode_avif(ImageData, quality? : Int) -> Bytes raise EncodeError // Resize / orientation pub fn resize(ImageData, Int, Int, ResizeMethod) -> ImageData raise EncodeError pub fn read_exif_orientation(Bytes) -> Int? pub fn apply_orientation(ImageData, Int) -> ImageData pub fn decode_image_upright(Bytes) -> ImageData raise DecodeError

    #Types

    pub(all) struct ImageData { width : Int; height : Int; data : Bytes } // RGBA8 pub(all) enum ResizeMethod { Nearest; Bilinear; Bicubic } pub(all) enum JpegSubsampling { Yuv444; Yuv422; Yuv420 } pub(all) enum PngColorMode { Rgba; Rgb; Gray; GrayAlpha; Palette; Auto } pub(all) enum PngCompression { Stored; Fast; Default; Best } pub(all) enum TiffCompression { NoCompression; Lzw; Deflate; PackBits } pub(all) struct Animation { width : Int; height : Int; frames : Array[AnimationFrame]; plays : Int } // plays: 0 = forever pub(all) struct AnimationFrame { image : ImageData; delay_ms : Int } pub(all) enum ImageFormat { Png; Bmp; Jpeg; Gif; Ico; Tiff; WebP } pub(all) suberror DecodeError { InvalidSignature(String); InvalidChunkCrc(String); MissingChunk(String); UnsupportedFeature(String); CorruptData(String) } pub(all) suberror EncodeError { InvalidDimensions(String); InvalidData(String) }

    #License

    Apache-2.0

    DecodeError

    pub(all) suberror DecodeError {
    InvalidSignature(String)
    InvalidChunkCrc(String)
    MissingChunk(String)
    UnsupportedFeature(String)
    CorruptData(String)
    }

    impl Show for DecodeError

    DecodeError::output

    fn DecodeError::output(self : DecodeError, logger : &Logger) -> Unit

    DecodeError::to_string

    fn DecodeError::to_string(self : DecodeError) -> String

    EncodeError

    pub(all) suberror EncodeError {
    InvalidDimensions(String)
    InvalidData(String)
    }

    impl Show for EncodeError

    EncodeError::output

    fn EncodeError::output(self : EncodeError, logger : &Logger) -> Unit

    EncodeError::to_string

    fn EncodeError::to_string(self : EncodeError) -> String

    Animation

    pub(all) struct Animation {
    width : Int
    height : Int
    frames : Array[AnimationFrame]
    plays : Int
    }

    A decoded animation.

    AnimationFrame

    pub(all) struct AnimationFrame {
    image : ImageData
    delay_ms : Int
    }

    One fully composited animation frame.

    ColorType

    pub enum ColorType {
    Grayscale
    Rgb
    Indexed
    GrayscaleAlpha
    Rgba
    } derive(Eq,
    Debug
    )

    impl Show for ColorType

    ColorType::equal

    fn ColorType::equal(ColorType, ColorType) -> Bool

    ColorType::output

    fn ColorType::output(self : ColorType, logger : &Logger) -> Unit

    ColorType::to_string

    fn ColorType::to_string(self : ColorType) -> String

    IhdrData

    pub(all) struct IhdrData {
    width : Int
    height : Int
    bit_depth : Int
    color_type : ColorType
    compression : Int
    filter : Int
    interlace : Int
    } derive(Eq)

    impl Show for IhdrData

    IhdrData::equal

    fn IhdrData::equal(IhdrData, IhdrData) -> Bool

    IhdrData::output

    fn IhdrData::output(self : IhdrData, logger : &Logger) -> Unit

    IhdrData::to_string

    fn IhdrData::to_string(self : IhdrData) -> String

    ImageData

    pub(all) struct ImageData {
    width : Int
    height : Int
    data : Bytes
    } derive(Eq,
    Debug
    )

    impl Show for ImageData

    ImageData::equal

    fn ImageData::equal(ImageData, ImageData) -> Bool

    ImageData::output

    fn ImageData::output(self : ImageData, logger : &Logger) -> Unit

    ImageData::to_string

    fn ImageData::to_string(self : ImageData) -> String

    ImageFormat

    pub(all) enum ImageFormat {
    Png
    Bmp
    Jpeg
    Gif
    Ico
    Tiff
    WebP
    } derive(Eq,
    Debug
    )

    impl Show for ImageFormat

    ImageFormat::equal

    fn ImageFormat::equal(ImageFormat, ImageFormat) -> Bool

    ImageFormat::output

    fn ImageFormat::output(self : ImageFormat, logger : &Logger) -> Unit

    ImageFormat::to_string

    fn ImageFormat::to_string(self : ImageFormat) -> String

    JpegSubsampling

    pub(all) enum JpegSubsampling {
    Yuv444
    Yuv422
    Yuv420
    }

    Chroma subsampling for encode_jpeg.

    PngColorMode

    pub(all) enum PngColorMode {
    Rgba
    Rgb
    Gray
    GrayAlpha
    Palette
    Auto
    }

    Color type written by encode_png.

    PngCompression

    pub(all) enum PngCompression {
    Stored
    Fast
    Default
    Best
    }

    zlib compression effort for encode_png.

    ResizeMethod

    pub(all) enum ResizeMethod {
    Nearest
    Bilinear
    Bicubic
    } derive(Eq)

    ResizeMethod::equal

    ResizeMethod::output

    fn ResizeMethod::output(self : ResizeMethod, logger : &Logger) -> Unit

    ResizeMethod::to_string

    fn ResizeMethod::to_string(self : ResizeMethod) -> String

    StreamImageInfo

    pub(all) struct StreamImageInfo {
    format : ImageFormat
    width : Int
    height : Int
    } derive(Eq)

    StreamImageInfo::equal

    StreamImageInfo::output

    fn StreamImageInfo::output(self : StreamImageInfo, logger : &Logger) -> Unit

    StreamImageInfo::to_string

    fn StreamImageInfo::to_string(self : StreamImageInfo) -> String

    TiffCompression

    pub(all) enum TiffCompression {
    NoCompression
    Lzw
    Deflate
    PackBits
    }

    Compression for encode_tiff.

    apply_orientation

    fn apply_orientation(img : ImageData, orientation : Int) -> ImageData

    Transform img so that it displays upright for EXIF orientation (same mapping as Pillow's ImageOps.exif_transpose): 1 as is, 2 mirror horizontally, 3 rotate 180, 4 mirror vertically, 5 transpose, 6 rotate 90 clockwise, 7 transverse, 8 rotate 90 counter-clockwise. Other values return the image unchanged.

    decode_bmp

    fn decode_bmp(raw : Bytes) -> ImageData raise DecodeError

    decode_bmp_stream

    fn decode_bmp_stream(raw : Bytes, on_row~ : (Int, Bytes) -> Unit) -> (Int, Int) raise DecodeError

    decode_gif

    fn decode_gif(data : Bytes) -> ImageData raise DecodeError

    Decode the first frame of a GIF (composited on the logical screen).

    decode_gif_frames

    fn decode_gif_frames(data : Bytes) -> Animation raise DecodeError

    Decode every frame of a (possibly animated) GIF. Each frame is the full logical screen after compositing, with its delay.

    decode_ico

    fn decode_ico(raw : Bytes) -> ImageData raise DecodeError

    Decode the best image of an ICO / CUR file: the largest one, preferring higher bit depth among equal sizes.

    decode_ico_all

    fn decode_ico_all(raw : Bytes) -> Array[ImageData] raise DecodeError

    Decode every image of an ICO / CUR file, in directory order.

    decode_image

    fn decode_image(raw : Bytes) -> ImageData raise DecodeError

    Decode a PNG, JPEG, GIF (first frame), BMP, ICO/CUR, TIFF (first page) or WebP (first frame) image, detected from its signature.

    decode_image_stream

    fn decode_image_stream(raw : Bytes, on_row~ : (Int, Bytes) -> Unit) -> StreamImageInfo raise DecodeError

    Decode any supported image row by row (on_row(y, rgba_row)). PNG and BMP are streamed; other formats are decoded fully, then emitted by row.

    decode_image_upright

    fn decode_image_upright(raw : Bytes) -> ImageData raise DecodeError

    decode_image followed by apply_orientation with the file's EXIF orientation, so photos display upright.

    decode_jpeg

    fn decode_jpeg(data : Bytes) -> ImageData raise DecodeError

    decode_png

    fn decode_png(raw : Bytes) -> ImageData raise DecodeError

    decode_png_frames

    fn decode_png_frames(raw : Bytes) -> Animation raise DecodeError

    Decode every frame of an APNG. Each frame is the whole canvas after compositing (dispose_op: 0 none, 1 clear to transparent, 2 restore the previous canvas; blend_op: 0 source, 1 over), with its delay.

    A PNG without an acTL chunk is returned as a single frame. If the default image (IDAT) is not part of the animation (no fcTL before it), it is not included.

    decode_png_stream

    fn decode_png_stream(raw : Bytes, on_row~ : (Int, Bytes) -> Unit) -> IhdrData raise DecodeError

    decode_tiff

    fn decode_tiff(raw : Bytes) -> ImageData raise DecodeError

    Decode the first image of a TIFF file.

    decode_tiff_pages

    fn decode_tiff_pages(raw : Bytes) -> Array[ImageData] raise DecodeError

    Decode every image (page) of a TIFF file, following the IFD chain.

    decode_webp

    fn decode_webp(data : Bytes) -> ImageData raise DecodeError

    Decode a WebP image (lossy, lossless, with alpha; the first frame of an animation, composited on the canvas).

    decode_webp_frames

    fn decode_webp_frames(data : Bytes) -> Animation raise DecodeError

    Decode every frame of a (possibly animated) WebP. Each frame is the full canvas after compositing; plays is the loop count (0 = forever).

    detect_image_format

    fn detect_image_format(raw : Bytes) -> ImageFormat?

    The format of an image, detected from its signature.

    encode_apng

    fn encode_apng(anim : Animation) -> Bytes raise EncodeError

    Encode an APNG (RGBA8). Frame 0 is the default image; later frames are cropped to the region that changed from the previous frame and drawn with blend_op SOURCE / dispose_op NONE, which reproduces each full canvas. plays is written to acTL (0 = forever).

    encode_avif

    fn encode_avif(img : ImageData, quality? : Int) -> Bytes raise EncodeError

    Encode img as AVIF (lossy AV1, 4:2:0). quality is 0..100 (higher is better); images with non-opaque pixels get an alpha auxiliary image.

    encode_bmp

    fn encode_bmp(img : ImageData) -> Bytes raise EncodeError

    encode_gif

    fn encode_gif(img : ImageData) -> Bytes raise EncodeError

    encode_gif_animation

    fn encode_gif_animation(anim : Animation) -> Bytes raise EncodeError

    Encode an animated GIF. Every frame must have at most 256 colors (counting full transparency) and alpha 0 or 255. A global color table is used when all frames fit in one; otherwise each frame gets a local table. Delays are rounded to 1/100 s. plays: 0 = loop forever, n = play n times (NETSCAPE loop count n - 1; no loop extension for 1).

    Without transparency, frames after the first are cropped to the changed region (dispose: none). With transparency, every frame is written whole and disposed to background, so transparent pixels stay transparent.

    encode_ico

    fn encode_ico(img : ImageData) -> Bytes raise EncodeError

    encode_jpeg

    fn encode_jpeg(img : ImageData, quality? : Int, subsampling? : JpegSubsampling, optimize? : Bool) -> Bytes raise EncodeError

    Encode a baseline JPEG (RGB from RGBA8; alpha is ignored).

    The pipeline follows libjpeg (fixed-point color conversion, libjpeg's downsampling, islow integer FDCT and quantization, standard Huffman tables), so for the same quality and subsampling the entropy-coded data is identical to libjpeg's (e.g. Pillow with optimize=False).

    optimize=true builds Huffman tables from the image's own symbol statistics (two passes), like libjpeg's optimize_coding / Pillow's optimize=True; tables and entropy-coded data then match those too.

    encode_png

    fn encode_png(img : ImageData, color? : PngColorMode, compression? : PngCompression) -> Bytes raise EncodeError

    Encode a PNG. color selects the color type (default RGBA8; Auto picks the smallest exact one) and compression the zlib effort. Explicit modes that cannot represent the image raise InvalidData.

    encode_tiff

    fn encode_tiff(img : ImageData, compression? : TiffCompression) -> Bytes raise EncodeError

    Encode a TIFF: RGB when every pixel is opaque, otherwise RGBA with unassociated alpha (ExtraSamples = 2).

    encode_webp

    fn encode_webp(img : ImageData) -> Bytes raise EncodeError

    encode_webp_animation

    fn encode_webp_animation(anim : Animation) -> Bytes raise EncodeError

    Encode an animated WebP. Every frame is lossless; frames after the first store only the region that changed. Delays are in milliseconds (up to 2^24 - 1); plays is the loop count (0 = forever, at most 65535).

    encode_webp_lossy

    fn encode_webp_lossy(img : ImageData, quality? : Int) -> Bytes raise EncodeError

    Encode a lossy WebP (VP8). quality is 0-100 (higher = better and larger). Alpha, when present, is stored losslessly in an ALPH chunk.

    package_name

    fn package_name() -> String

    Project marker.

    read_exif_orientation

    fn read_exif_orientation(raw : Bytes) -> Int?

    The EXIF orientation (1-8) of a JPEG, PNG, TIFF or WebP file, if it has one. Malformed metadata is treated as absent.

    resize

    fn resize(img : ImageData, new_width : Int, new_height : Int, resize_method : ResizeMethod) -> ImageData raise EncodeError