Skip to content

Commit f81092c

Browse files
committed
add set metadata
1 parent cd7761b commit f81092c

File tree

6 files changed

+128
-5
lines changed

6 files changed

+128
-5
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
vips extension changelog
22

3+
Version 1.0.11 (2020-08-xx)
4+
--------------------------
5+
* add vips_image_set_type()
6+
* add vips_type_from_name()
7+
38
Version 1.0.10 (2018-12-xx)
49
--------------------------
510
* Fix win32 build [TBK]

package.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
1515
<email>jcupitt@php.net</email>
1616
<active>yes</active>
1717
</lead>
18-
<date>2019-09-26</date>
18+
<date>2020-08-26</date>
1919
<version>
20-
<release>1.0.10</release>
20+
<release>1.0.11</release>
2121
<api>1.0.0</api>
2222
</version>
2323
<stability>
@@ -26,9 +26,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2626
</stability>
2727
<license filesource="LICENSE.txt">MIT</license>
2828
<notes>
29-
* Add vips_image_write_to_array() [jcupitt]
30-
* Update links for new home [jcupitt]
31-
* Fix win32 build [TBK]
29+
* add vips_image_set_type()
3230
</notes>
3331
<contents>
3432
<dir name="/">
@@ -100,6 +98,15 @@ http://pear.php.net/dtd/package-2.0.xsd">
10098
</extsrcrelease>
10199
<changelog>
102100

101+
<release>
102+
<stability><release>stable</release><api>stable</api></stability>
103+
<version><release>1.0.11</release><api>1.0.0</api></version>
104+
<date>2020-07-26</date>
105+
<notes>
106+
* add vips_image_set_type()
107+
</notes>
108+
</release>
109+
103110
<release>
104111
<stability><release>stable</release><api>stable</api></stability>
105112
<version><release>1.0.10</release><api>1.0.0</api></version>

tests/042.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
can set metadata
3+
--SKIPIF--
4+
<?php if (!extension_loaded("vips")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
8+
$profilename = dirname(__FILE__) . "/images/sRGB.icc";
9+
$image = vips_image_new_from_file($filename)["out"];
10+
$blob_type = vips_type_from_name("VipsBlob");
11+
$data = file_get_contents($profilename);
12+
$output_filename = dirname(__FILE__) . "/x.tif";
13+
14+
$image = vips_call("copy", $image)["out"];
15+
$result = vips_image_set_type($image, $blob_type, "icc-profile-data", $data);
16+
if ($result == 0) {
17+
echo "pass set_metadata\n";
18+
}
19+
20+
vips_image_write_to_file($image, $output_filename);
21+
$new_image = vips_image_new_from_file($output_filename)["out"];
22+
if ($new_image != FALSE) {
23+
echo("pass reload\n");
24+
}
25+
26+
$new_data = vips_image_get($image, "icc-profile-data")["out"];
27+
if ($new_data == $data) {
28+
echo("pass get_metadata\n");
29+
}
30+
?>
31+
--EXPECT--
32+
pass set_metadata
33+
pass reload
34+
pass get_metadata
35+
--CLEAN--
36+
<?php
37+
$output_filename = dirname(__FILE__) . "/x.tif";
38+
unlink($output_filename);
39+
?>
40+

tests/images/sRGB.icc

6.76 KB
Binary file not shown.

vips-1.0.11.tgz

546 KB
Binary file not shown.

vips.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,7 @@ PHP_FUNCTION(vips_image_get_typeof)
16661666
}
16671667
/* }}} */
16681668

1669+
16691670
/* {{{ proto long vips_image_set(resource image, string field, mixed value)
16701671
Set field on image */
16711672
PHP_FUNCTION(vips_image_set)
@@ -1759,6 +1760,63 @@ PHP_FUNCTION(vips_image_set)
17591760
}
17601761
/* }}} */
17611762

1763+
/* {{{ proto long vips_type_from_name(string name)
1764+
find the gtype for a type name */
1765+
PHP_FUNCTION(vips_type_from_name)
1766+
{
1767+
char *name;
1768+
size_t name_len;
1769+
GType gtype;
1770+
1771+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
1772+
&name, &name_len) == FAILURE) {
1773+
RETURN_LONG(-1);
1774+
}
1775+
1776+
RETURN_LONG(g_type_from_name(name));
1777+
}
1778+
/* }}} */
1779+
1780+
/* {{{ proto long vips_image_set_type(resource image, integer gtype, string field, mixed value)
1781+
Set field on image */
1782+
PHP_FUNCTION(vips_image_set_type)
1783+
{
1784+
zval *im;
1785+
long type;
1786+
char *field_name;
1787+
size_t field_name_len;
1788+
zval *zvalue;
1789+
VipsImage *image;
1790+
GValue gvalue = { 0 };
1791+
1792+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlsz",
1793+
&im, &type, &field_name, &field_name_len, &zvalue) == FAILURE) {
1794+
RETURN_LONG(-1);
1795+
}
1796+
1797+
if ((image = (VipsImage *)zend_fetch_resource(Z_RES_P(im),
1798+
"GObject", le_gobject)) == NULL) {
1799+
RETURN_LONG(-1);
1800+
}
1801+
1802+
if (type <= 0) {
1803+
RETURN_LONG(-1);
1804+
}
1805+
1806+
g_value_init(&gvalue, type);
1807+
1808+
if (vips_php_zval_to_gval(NULL, zvalue, &gvalue)) {
1809+
RETURN_LONG(-1);
1810+
}
1811+
1812+
vips_image_set(image, field_name, &gvalue);
1813+
1814+
g_value_unset(&gvalue);
1815+
1816+
RETURN_LONG(0);
1817+
}
1818+
/* }}} */
1819+
17621820
/* {{{ proto long vips_image_remove(resource image, string field)
17631821
Remove field from image */
17641822
PHP_FUNCTION(vips_image_remove)
@@ -2197,6 +2255,17 @@ ZEND_BEGIN_ARG_INFO(arginfo_vips_image_set, 0)
21972255
ZEND_ARG_INFO(0, value)
21982256
ZEND_END_ARG_INFO()
21992257

2258+
ZEND_BEGIN_ARG_INFO(arginfo_vips_type_from_name, 0)
2259+
ZEND_ARG_INFO(0, name)
2260+
ZEND_END_ARG_INFO()
2261+
2262+
ZEND_BEGIN_ARG_INFO(arginfo_vips_image_set_type, 0)
2263+
ZEND_ARG_INFO(0, image)
2264+
ZEND_ARG_INFO(0, type)
2265+
ZEND_ARG_INFO(0, field)
2266+
ZEND_ARG_INFO(0, value)
2267+
ZEND_END_ARG_INFO()
2268+
22002269
ZEND_BEGIN_ARG_INFO(arginfo_vips_image_remove, 0)
22012270
ZEND_ARG_INFO(0, image)
22022271
ZEND_ARG_INFO(0, field)
@@ -2260,6 +2329,8 @@ const zend_function_entry vips_functions[] = {
22602329
PHP_FE(vips_image_get, arginfo_vips_image_get)
22612330
PHP_FE(vips_image_get_typeof, arginfo_vips_image_get_typeof)
22622331
PHP_FE(vips_image_set, arginfo_vips_image_set)
2332+
PHP_FE(vips_type_from_name, arginfo_vips_type_from_name)
2333+
PHP_FE(vips_image_set_type, arginfo_vips_image_set_type)
22632334
PHP_FE(vips_image_remove, arginfo_vips_image_remove)
22642335
PHP_FE(vips_error_buffer, arginfo_vips_error_buffer)
22652336
PHP_FE(vips_cache_set_max, arginfo_vips_cache_set_max)

0 commit comments

Comments
 (0)