diff --git a/tests/043.phpt b/tests/043.phpt new file mode 100644 index 0000000..5e8c461 --- /dev/null +++ b/tests/043.phpt @@ -0,0 +1,86 @@ +--TEST-- +can get fields +--SKIPIF-- + +--FILE-- + +--EXPECT-- +pass width +pass height +pass bands +pass format +pass coding +pass interpretation +pass xoffset +pass yoffset +pass xres +pass yres +pass filename +pass vips-loader +pass jpeg-multiscan +pass jpeg-chroma-subsample +pass exif-data +pass resolution-unit +pass exif-ifd0-Make +pass exif-ifd0-Model +pass exif-ifd0-Orientation +pass exif-ifd0-XResolution +pass exif-ifd0-YResolution +pass exif-ifd0-ResolutionUnit +pass exif-ifd0-DateTime +pass exif-ifd0-YCbCrPositioning +pass exif-ifd1-Compression +pass exif-ifd1-XResolution +pass exif-ifd1-YResolution +pass exif-ifd1-ResolutionUnit +pass exif-ifd2-ExposureTime +pass exif-ifd2-FNumber +pass exif-ifd2-ExifVersion +pass exif-ifd2-DateTimeOriginal +pass exif-ifd2-DateTimeDigitized +pass exif-ifd2-ComponentsConfiguration +pass exif-ifd2-CompressedBitsPerPixel +pass exif-ifd2-ShutterSpeedValue +pass exif-ifd2-ApertureValue +pass exif-ifd2-ExposureBiasValue +pass exif-ifd2-MaxApertureValue +pass exif-ifd2-SubjectDistance +pass exif-ifd2-MeteringMode +pass exif-ifd2-Flash +pass exif-ifd2-FocalLength +pass exif-ifd2-MakerNote +pass exif-ifd2-UserComment +pass exif-ifd2-FlashPixVersion +pass exif-ifd2-ColorSpace +pass exif-ifd2-PixelXDimension +pass exif-ifd2-PixelYDimension +pass exif-ifd2-FocalPlaneXResolution +pass exif-ifd2-FocalPlaneYResolution +pass exif-ifd2-FocalPlaneResolutionUnit +pass exif-ifd2-SensingMethod +pass exif-ifd2-FileSource +pass exif-ifd4-InteroperabilityIndex +pass exif-ifd4-InteroperabilityVersion +pass exif-ifd4-RelatedImageWidth +pass exif-ifd4-RelatedImageLength +pass jpeg-thumbnail-data +pass orientation +pass get_fields + diff --git a/vips-1.0.12.tgz b/vips-1.0.12.tgz index e915394..6b2a01a 100644 Binary files a/vips-1.0.12.tgz and b/vips-1.0.12.tgz differ diff --git a/vips.c b/vips.c index dfd3724..6e93c03 100644 --- a/vips.c +++ b/vips.c @@ -1898,6 +1898,52 @@ PHP_FUNCTION(vips_image_remove) } /* }}} */ +/* {{{ proto array|long vips_image_get_fields(resource image) + Get fields from image metadata */ +PHP_FUNCTION(vips_image_get_fields) +{ + zval *im; + VipsImage *image; + gchar **gvalue; + gchar* tmp = NULL; + int i = 0; + zval fields; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &im) == FAILURE) { + RETURN_LONG(-1); + } + + if ((image = (VipsImage *)zend_fetch_resource(Z_RES_P(im), + "GObject", le_gobject)) == NULL) { + RETURN_LONG(-1); + } + + gvalue = vips_image_get_fields(image); + + array_init(&fields); + + while((tmp = gvalue[i]) != NULL){ + VIPS_DEBUG_MSG("%s\n", tmp); + VIPS_DEBUG_MSG("%llu\n", strlen(tmp)); + + zend_string *str = zend_string_init(tmp, strlen(tmp), 0); + + VIPS_DEBUG_MSG("This is my string: %s\n", ZSTR_VAL(str)); + VIPS_DEBUG_MSG("It is %zd char long\n", ZSTR_LEN(str)); // %zd is the printf format for size_t + + add_next_index_str(&fields, str); + i++; + } + +// g_object_unref(gvalue); + + /* Return as an array for all OK, -1 for error. + */ + array_init(return_value); + add_assoc_zval(return_value, "out", &fields); +} +/* }}} */ + /* {{{ proto string vips_error_buffer() Fetch and clear the vips error buffer */ PHP_FUNCTION(vips_error_buffer) diff --git a/vips.stub.php b/vips.stub.php index 2638f0f..e766b46 100644 --- a/vips.stub.php +++ b/vips.stub.php @@ -94,6 +94,12 @@ function vips_image_set_type($image, string|int $type, string $field, mixed $val */ function vips_image_remove($image, string $field): int {} +/** + * @param resource $image + * @return array|int + */ +function vips_image_get_fields($image): array|int {} + function vips_error_buffer(): string {} function vips_cache_set_max(int $value): void {} diff --git a/vips_arginfo.h b/vips_arginfo.h index 4d17580..02ce584 100644 --- a/vips_arginfo.h +++ b/vips_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b0a895aa400527f647c2f9bd728c4e8a94cb0c9b */ + * Stub hash: 02c5e68c129bc64f2b1ff5d5fb4b083b3fb5f3bc */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_vips_image_new_from_file, 0, 1, MAY_BE_ARRAY|MAY_BE_LONG) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -95,6 +95,8 @@ ZEND_END_ARG_INFO() #define arginfo_vips_image_remove arginfo_vips_image_get_typeof +#define arginfo_vips_image_get_fields arginfo_vips_image_copy_memory + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_vips_error_buffer, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -141,6 +143,7 @@ ZEND_FUNCTION(vips_image_set); ZEND_FUNCTION(vips_type_from_name); ZEND_FUNCTION(vips_image_set_type); ZEND_FUNCTION(vips_image_remove); +ZEND_FUNCTION(vips_image_get_fields); ZEND_FUNCTION(vips_error_buffer); ZEND_FUNCTION(vips_cache_set_max); ZEND_FUNCTION(vips_cache_set_max_mem); @@ -174,6 +177,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(vips_type_from_name, arginfo_vips_type_from_name) ZEND_FE(vips_image_set_type, arginfo_vips_image_set_type) ZEND_FE(vips_image_remove, arginfo_vips_image_remove) + ZEND_FE(vips_image_get_fields, arginfo_vips_image_get_fields) ZEND_FE(vips_error_buffer, arginfo_vips_error_buffer) ZEND_FE(vips_cache_set_max, arginfo_vips_cache_set_max) ZEND_FE(vips_cache_set_max_mem, arginfo_vips_cache_set_max_mem)