Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
ai-meta (Rust)
ai-meta-rs is a safe Rust crate for detecting, extracting, stripping, and writing AI-generation metadata declared in image files.
It wraps the ai_meta C library and links prebuilt release binaries of that library (pinned by LIBAI_META_VERSION).
- Repository: https://github.com/localtools/ai-meta-rs
- Crates.io: ai-meta-rs (
use ai_meta::…) - License: MIT — free and open source
- Rust: 1.74+
- Scope: declared metadata only — it does not analyze pixels to guess whether an undeclared image is AI-generated
Sibling projects: ai-meta (C), ai-meta-php, ai-meta-node, ai-meta-wasm (browser / WebAssembly).
Why
Generators and platforms increasingly embed provenance and generation parameters (Stable Diffusion parameters, EXIF/XMP, C2PA Content Credentials, IPTC). This crate gives Rust applications a small, dependency-light way to inspect and scrub that metadata while leaving pixel data and color profiles intact when requested.
Features
| Capability | Notes |
|---|---|
| Formats | PNG, JPEG, WebP |
| Schemes | PNG text (tEXt / iTXt / zTXt), EXIF, XMP, IPTC (JPEG), C2PA detect/strip/hints |
| Scan | Fast format + scheme list + likely_ai |
| Extract | BTreeMap<String, String> of fields (e.g. parameters, prompt, Seed, …) |
| Strip / write | Returns a new Vec<u8>; input is never mutated |
| Errors | Error with messages from ai_meta_strerror() |
| Safety | RAII frees ai_meta_info / strip-write buffers; no aliasing of freed C memory |
C2PA signatures are not cryptographically verified (same as the C library).
Quick start
Install
[]
= "0.1"
use ;
First build downloads the pinned ai_meta prebuilt into OUT_DIR when needed (requires network, curl or wget). Runtime needs zlib only — libai_meta.a is linked statically.
WebAssembly
For wasm32-unknown-unknown, build.rs compiles libai_meta and zlib from source with a wasm-capable clang (wasi-sdk). Set WASI_SDK_PATH or AI_META_WASM_CC. Optional AI_META_SRC points at an ai-meta checkout; otherwise the pinned tag is downloaded.
Browser / npm bindings live in the sibling crate ai-meta-wasm (wasm-pack → pkg/).
From source
Optional local cache of the C library (skips download when present):
Requirements
- Rust 1.74+
- A C linker (
cc,clang, orgcc) - zlib (
zlib1g-devon Debian/Ubuntu; usually present on macOS) - Network on first build or a prebuilt prefix
How libai_meta is found
build.rs resolves the library in this order:
AI_META_PREFIX(directory withinclude/+lib/libai_meta.a)./deps/ai_meta(fromscripts/fetch-libai-meta.sh)- pkg-config
ai_meta - Download the pinned GitHub Release into
OUT_DIR
API
| Function | Role |
|---|---|
scan(&[u8]) -> Result<ScanResult> |
Format, schemes, likely_ai |
extract(&[u8]) -> Result<BTreeMap<String, String>> |
Field map |
strip(&[u8], Flags) -> Result<Vec<u8>> |
New image bytes |
write(&[u8], key, value) -> Result<Vec<u8>> |
Inject/replace metadata |
detect_format(&[u8]) -> Format |
Format only |
version() -> String |
Linked libai_meta version |
Flags
| Flag | Role |
|---|---|
Flags::NONE |
No strip flags |
Flags::STRIP_PNG_TEXT / STRIP_EXIF / STRIP_XMP / STRIP_IPTC / STRIP_C2PA |
Per-scheme strip |
Flags::STRIP_ALL_AI |
All AI-related strip bits |
Flags::KEEP_COLOR_PROFILE |
Preserve ICC / color profile when possible |
Flags::KEEP_NON_AI_TEXT |
Keep benign PNG text when stripping |
Conventions
| Topic | Rule |
|---|---|
| Errors | Result<T, Error>; message from ai_meta_strerror() |
| Memory | Library buffers freed inside the crate before return |
| Strip / write | Always return a new Vec<u8> |
| Color profiles | Preserved when KEEP_COLOR_PROFILE is set (recommended) |
Full docs: docs.rs/ai-meta-rs. Example: examples/basic.rs.
Design
- Thin safe wrapper over the buffer-based C API (
src/ffi.rs+src/lib.rs) - Compiled dependency — links release artifacts of ai_meta, not a source copy
- Runtime deps — zlib (+ the Rust crate deps); static
libai_meta.apreferred at link time - Portability — Linux and macOS; CI covers both
Out of scope
- Pixel / ML-based “is this AI?” detection
- Full C2PA claim verification and signing
- Lossy re-encode of image payloads (metadata containers only)
- Bundling or re-implementing the C library inside this repo
Testing
Coverage includes scan, extract, write/strip round-trip, and error paths against small PNG fixtures under tests/fixtures/.
Project layout
Cargo.toml Package metadata (name: ai-meta-rs, lib: ai_meta)
build.rs Locate / download libai_meta + link + zlib
src/lib.rs Safe public API
src/ffi.rs Raw `ai_meta.h` bindings
examples/basic.rs Minimal CLI demo
scripts/fetch-libai-meta.sh
tests/fixtures/ PNG fixtures
LIBAI_META_VERSION Pinned ai_meta release
LICENSE NOTICE MIT + third-party notices
Releases
Tag a release to run tests, publish to crates.io, and create a GitHub Release:
Requires repository secret CARGO_REGISTRY_TOKEN (crates.io API token). Workflow: .github/workflows/release.yml.
Native library (dependency)
| Item | Location |
|---|---|
| Releases | https://github.com/localtools/ai-meta/releases |
| Pin file | LIBAI_META_VERSION |
| Fetch helper | scripts/fetch-libai-meta.sh |
Contributing
Contributions are welcome. See CONTRIBUTING.md and our Code of Conduct.
For security issues, see SECURITY.md — please do not open public issues for vulnerabilities.
Changelog
See CHANGELOG.md.
License
This project is licensed under the MIT License — see LICENSE and NOTICE.
Copyright (c) 2026 Local Tools and ai-meta-rs contributors
You may use, modify, and distribute this software under the terms of that license.
The native ai_meta library is also MIT-licensed; prebuilt binaries are obtained from its GitHub Releases.