Just a couple of functions in Zig that export image data, RGB/RGBA/grayscale/grayscale+alpha (but alpha channel is ignored), 8 or 16 bits per channel, as PPM/PGM files. Not enough code to be called a library.
PPM and PGM are very simple graphic file formats, but they are widespread enough for popular editors, like Gimp, Krita or Adobe Photoshop to be able to open them. Meaning you can quickly dump whatever you want from your Zig programs as a PPM/PGM file and open it in an editor.
See https://en.wikipedia.org/wiki/Netpbm?useskin=vector, https://netpbm.sourceforge.net/doc/ppm.html.
Check out the tests in export_ppm.zig
for examples of use.
test_data_src folder contains PNG images I used as test data, ignore them or use them however you want. I release them in public domain.
export_ppm.zig is licensed under the MIT License.
Just drop export_ppm.zig
into your project and add const eppm = @import("export_ppm.zig");
, or use the Zig package manager:
-
In your project's
build.zig.zon
, in.dependencies
, add.export_ppm = .{ .url = "https://github.com/Durobot/export_ppm/archive/<GIT COMMIT HASH, 40 HEX DIGITS>.tar.gz", .hash = "<ZIG PACKAGE HASH, 68 HEX DIGITS>" // Use arbitrary hash, get correct hash from the error }
-
In your project's
build.zig
, inpub fn build
, beforeb.installArtifact(exe);
, addconst eppm = b.dependency("export_ppm", .{ .target = target, .optimize = optimize, }); exe.root_module.addImport("export_ppm", eppm.module("export_ppm"));
-
Add
const eppm = @import("export_ppm");
in your source file(s). -
Build your project with
zig build
, as you normally do.