-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.php
More file actions
44 lines (37 loc) · 1.05 KB
/
Copy pathbasic.php
File metadata and controls
44 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Minimal ai_meta consumer.
*
* Build the extension first, then:
* php -d extension=./modules/ai_meta.so examples/basic.php path/to/image.png
*/
declare(strict_types=1);
if (!extension_loaded('ai_meta')) {
fwrite(STDERR, "ai_meta extension not loaded\n");
exit(1);
}
if ($argc < 2) {
fwrite(STDERR, "usage: php examples/basic.php <image>\n");
exit(2);
}
$path = $argv[1];
$data = file_get_contents($path);
if ($data === false) {
fwrite(STDERR, "failed to read {$path}\n");
exit(1);
}
try {
$scan = ai_meta_scan($data);
echo 'format=' . $scan['format']
. ' likely_ai=' . ($scan['likely_ai'] ? 'true' : 'false')
. ' schemes=' . implode(',', $scan['schemes'])
. PHP_EOL;
$fields = ai_meta_extract($data);
foreach ($fields as $key => $value) {
$preview = strlen($value) > 120 ? substr($value, 0, 117) . '...' : $value;
echo $key . ': ' . $preview . PHP_EOL;
}
} catch (AiMetaException $e) {
fwrite(STDERR, 'ai_meta error: ' . $e->getMessage() . PHP_EOL);
exit(1);
}