Skip to content

zigar.image.formats

Chung Leong edited this page Jul 28, 2026 · 2 revisions

JavaScript | PHP


Tuple contain the image formats supported by the current compilation target.

When the target is WebAssembly, GD support is excluded.

Use this tuple in conjunction with getField() to loop through the different formats.

Usage:

const std = @import("std");

const zigar = @import("zigar");

pub fn transform(img_in: zigar.image.Any(.ro), img_out: zigar.image.Any(.rw)) void {
    inline for (zigar.image.formats) |tag| {
        if (img_in == tag and img_out == tag) {
            const in = img_in.getField(tag);
            const out = img_out.getField(tag);
            const x_adv: f32 = in.getWidthAsFloat() / out.getWidthAsFloat();
            const y_adv: f32 = in.getHeightAsFloat() / out.getHeightAsFloat();
            var coord: @Vector(2, f32) = undefined;
            coord[1] = 0.5;
            for (0..out.getHeight()) |y| {
                coord[0] = 0.5;
                for (0..out.getWidth()) |x| {
                    const pixel = init: {
                        const color = in.sampleLinear(Pixel, coord);
                        // do something here...
                    };
                    out.setPixel(@Vector(4, f32), x, y, pixel);
                }
                coord[1] += y_adv;
            }
        }
    }
}

Clone this wiki locally