PHP code example of localtools / ai-meta-php

1. Go to this page and download the library: Download localtools/ai-meta-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

localtools / ai-meta-php example snippets


/** @return array{format: string, schemes: list<string>, likely_ai: bool} */
ai_meta_scan(string $data): array

/** @return array<string, string> */
ai_meta_extract(string $data): array

ai_meta_strip(string $data, int $flags = 0): string

ai_meta_write(string $data, string $key, string $value): string

$bytes = file_get_contents('in.png');

$scan = ai_meta_scan($bytes);
if ($scan['likely_ai']) {
    $fields = ai_meta_extract($bytes);
    // $fields['parameters'], $fields['prompt'], …

    $clean = ai_meta_strip(
        $bytes,
        AI_META_FLAG_STRIP_ALL_AI | AI_META_FLAG_KEEP_COLOR_PROFILE
    );
    file_put_contents('out.png', $clean);
}

$written = ai_meta_write($bytes, 'parameters', "Steps: 20, Seed: 1");
bash
php -m | grep ai_meta
php -r 'var_export(ai_meta_scan(file_get_contents("image.png")));'
bash
./scripts/fetch-libai-meta.sh
pie install localtools/ai-meta-php --with-ai-meta="$PWD/deps/ai_meta"
# or, if deps/ai_meta is already present in the build tree:
pie install localtools/ai-meta-php

composer.json             PIE / Packagist metadata (type: php-ext)
ai_meta.c                 Extension implementation
php_ai_meta.h             Version / module headers
config.m4                 phpize build (links prebuilt libai_meta)
stub.php                  IDE stub
examples/basic.php        Minimal consumer
scripts/fetch-libai-meta.sh
scripts/package-dist.sh
tests/*.phpt              PHP test suite
LIBAI_META_VERSION        Pinned ai_meta release
LICENSE NOTICE            MIT + third-party notices