Download the PHP package localtools/ai-meta-php without Composer
On this page you can find all versions of the php package localtools/ai-meta-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download localtools/ai-meta-php
More information about localtools/ai-meta-php
Files in localtools/ai-meta-php
Package ai-meta-php
Short Description PHP extension for detecting, extracting, stripping, and writing AI-generation metadata in PNG/JPEG/WebP images (wraps prebuilt libai_meta).
License MIT
Homepage https://github.com/localtools/ai-meta-php
Informations about the package ai-meta-php
ai_meta (PHP)
ai-meta-php is a traditional C PHP extension (phpize / config.m4, not FFI) 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-php
- License: MIT — free and open source
- PHP: 8.1+ (NTS and ZTS)
- Scope: declared metadata only — it does not analyze pixels to guess whether an undeclared image is AI-generated
Why
Generators and platforms increasingly embed provenance and generation parameters (Stable Diffusion parameters, EXIF/XMP, C2PA Content Credentials, IPTC). This extension gives PHP 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 bitmask + likely_ai |
| Extract | Associative field map (e.g. parameters, prompt, Seed, …) |
| Strip / write | Returns a new binary buffer; input is never mutated |
| Errors | AiMetaException with messages from ai_meta_strerror() |
C2PA signatures are not cryptographically verified (same as the C library).
Quick start
Requirements
- PHP 8.1+ with development headers (
phpize,php-config) - A C11 compiler (
cc,clang, orgcc) - zlib development headers (
zlib1g-devon Debian/Ubuntu; usually present on macOS) - A prebuilt ai_meta prefix (
include/+lib/)
Build & test
The configure step prefers lib/libai_meta.a so the resulting ai_meta.so does not need libai_meta at runtime (only zlib).
Alternative discovery:
Load
See examples/basic.php.
Install with PIE
This extension supports PIE (PHP Installer for Extensions). Package metadata lives in composer.json (type: php-ext).
Source builds need a prebuilt ai_meta library:
composer.json declares download-url-method: ["pre-packaged-binary", "composer-default"], so PIE prefers a matching release binary and falls back to building from source.
Publish to Packagist (submit the GitHub repo) so pie install localtools/ai-meta-php resolves without a path repository.
Prebuilt packages
Extension (this repo)
GitHub Releases attach PIE-compatible binaries (via php/pie-ext-binary-builder):
Local packaging after a successful make:
Tag a release to build and attach PIE assets automatically:
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 |
This extension does not vendor or compile libai_meta sources.
PHP API
On any non-OK library status, an AiMetaException (extends RuntimeException) is thrown.
Constants
| Constant | Role |
|---|---|
AI_META_FLAG_NONE |
No strip flags |
AI_META_FLAG_STRIP_PNG_TEXT / STRIP_EXIF / STRIP_XMP / STRIP_IPTC / STRIP_C2PA |
Per-scheme strip |
AI_META_FLAG_STRIP_ALL_AI |
All AI-related strip bits |
AI_META_FLAG_KEEP_COLOR_PROFILE |
Preserve ICC / color profile when possible |
AI_META_FLAG_KEEP_NON_AI_TEXT |
Keep benign PNG text when stripping |
AI_META_SCHEME_* |
Scheme bitmask values (mirror the C API) |
IDE / static-analysis stubs: ai_meta.stub.php.
Conventions
| Topic | Rule |
|---|---|
| Errors | Throw AiMetaException; message from ai_meta_strerror() |
| Memory | Library buffers are freed inside the extension before return |
| Strip / write | Always return a new string buffer |
| Color profiles | Preserved when AI_META_FLAG_KEEP_COLOR_PROFILE is set (recommended) |
Design
- Thin PHP wrapper over the buffer-based C API
- Compiled dependency — links release artifacts of ai_meta, not a source copy
- Runtime deps — zlib (and the PHP runtime); static
libai_meta.ais preferred at link time - Portability — Linux and macOS; CI covers PHP 8.1–8.4
- Safety — malformed / truncated metadata should fail with an exception, not crash PHP
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
.phpt coverage includes scan, extract, write/strip round-trip, and exception paths against small PNG fixtures under tests/fixtures/.
CI: .github/workflows/ci.yml.
Project layout
Contributing
Contributions are welcome. See 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 NOTICE.
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.