File tree 4 files changed +49
-0
lines changed
4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ All notable changes to `:vips` will be documented in this file.
4
4
5
5
## master
6
6
7
+ - add getFields() to fetch an array of field names
8
+
7
9
## 2.2.0 - 2023-08-17
8
10
9
11
- improve FFI startup [ West14, jcupitt]
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env php
2
+ <?php
3
+
4
+ require dirname (__DIR__ ) . '/vendor/autoload.php ' ;
5
+
6
+ use Jcupitt \Vips ;
7
+
8
+ $ im = Vips \Image::newFromFile ($ argv [1 ]);
9
+
10
+ $ names = $ im ->getFields ();
11
+
12
+ echo "$ argv [1 ]\n" ;
13
+ foreach ($ names as &$ name ) {
14
+ $ value = $ im ->get ($ name );
15
+ echo "$ name: $ value \n" ;
16
+ }
17
+
18
+ /*
19
+ * Local variables:
20
+ * tab-width: 4
21
+ * c-basic-offset: 4
22
+ * End:
23
+ * vim600: expandtab sw=4 ts=4 fdm=marker
24
+ * vim<600: expandtab sw=4 ts=4
25
+ */
Original file line number Diff line number Diff line change @@ -348,6 +348,7 @@ private static function init(): void
348
348
$ glib_decls = $ typedefs . <<<EOS
349
349
void* g_malloc (size_t size);
350
350
void g_free (void* data);
351
+ void g_strfreev (char** str_array);
351
352
EOS ;
352
353
353
354
// GObject declarations
Original file line number Diff line number Diff line change 114
114
* conform to PHP naming conventions, you can use something like
115
115
* `$image->get('ipct-data')`.
116
116
*
117
+ * Use `$image->getFields()` to get an array of all the possible field names.
118
+ *
117
119
* Next we have:
118
120
*
119
121
* ```php
@@ -1217,6 +1219,25 @@ public function typeOf(string $name): int
1217
1219
return $ this ->getType ($ name );
1218
1220
}
1219
1221
1222
+ /**
1223
+ * Get the field names available for an image.
1224
+ *
1225
+ * @return Array
1226
+ */
1227
+ public function getFields (): array
1228
+ {
1229
+ $ str_array = FFI ::vips ()->vips_image_get_fields ($ this ->pointer );
1230
+
1231
+ $ fields = [];
1232
+ for ($ i = 0 ; $ str_array [$ i ] != null ; $ i ++) {
1233
+ array_push ($ fields , \FFI ::string ($ str_array [$ i ]));
1234
+ }
1235
+
1236
+ FFI ::glib ()->g_free ($ str_array );
1237
+
1238
+ return $ fields ;
1239
+ }
1240
+
1220
1241
/**
1221
1242
* Set any property on the underlying image.
1222
1243
*
You can’t perform that action at this time.
0 commit comments