Skip to content

Commit 310b029

Browse files
committed
vips_image_set_type() can be passed a type name
fixes 32-bit support see #38
1 parent 8002240 commit 310b029

File tree

8 files changed

+43
-14
lines changed

8 files changed

+43
-14
lines changed

Diff for: ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
vips extension changelog
22

3+
Version 1.0.12 (2020-8-xx)
4+
--------------------------
5+
* vips_image_set_type() can be passed a type name
6+
https://github.com/libvips/php-vips-ext/issues/38
7+
38
Version 1.0.11 (2020-1-xx)
49
--------------------------
510
* More php_info() output [jcupitt]

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ libvips website, or build your own.
9191
$ pear package
9292
```
9393

94-
To make `vips-1.0.11.tgz`.
94+
To make `vips-1.0.12.tgz`.
9595

9696
To install by hand:
9797

Diff for: RELEASE-1.0.11 renamed to RELEASE-1.0.12

File renamed without changes.

Diff for: package.xml

+13-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
1515
<email>[email protected]</email>
1616
<active>yes</active>
1717
</lead>
18-
<date>2020-08-28</date>
18+
<date>2020-08-29</date>
1919
<version>
20-
<release>1.0.11</release>
20+
<release>1.0.12</release>
2121
<api>1.0.0</api>
2222
</version>
2323
<stability>
@@ -26,16 +26,15 @@ http://pear.php.net/dtd/package-2.0.xsd">
2626
</stability>
2727
<license filesource="LICENSE.txt">MIT</license>
2828
<notes>
29-
* add vips_image_set_type()
30-
* More php_info() output [jcupitt]
29+
* vips_image_set_type() can be passed a type name
3130
</notes>
3231
<contents>
3332
<dir name="/">
3433
<file role='doc' name='API-1.0.0'/>
3534
<file role='doc' name='CREDITS'/>
3635
<file role='doc' name='LICENSE.txt'/>
3736
<file role='doc' name='README.md'/>
38-
<file role='doc' name='RELEASE-1.0.11'/>
37+
<file role='doc' name='RELEASE-1.0.12'/>
3938
<file role='doc' name='ChangeLog'/>
4039

4140
<file role='src' name='config.m4'/>
@@ -102,6 +101,15 @@ http://pear.php.net/dtd/package-2.0.xsd">
102101
</extsrcrelease>
103102
<changelog>
104103

104+
<release>
105+
<stability><release>stable</release><api>stable</api></stability>
106+
<version><release>1.0.12</release><api>1.0.0</api></version>
107+
<date>2020-08-29</date>
108+
<notes>
109+
* vips_image_set_type() can be passed a type name
110+
</notes>
111+
</release>
112+
105113
<release>
106114
<stability><release>stable</release><api>stable</api></stability>
107115
<version><release>1.0.11</release><api>1.0.0</api></version>

Diff for: php_vips.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
extern zend_module_entry vips_module_entry;
66
#define phpext_vips_ptr &vips_module_entry
77

8-
#define PHP_VIPS_VERSION "1.0.11"
8+
#define PHP_VIPS_VERSION "1.0.12"
99

1010
#ifdef PHP_WIN32
1111
# define PHP_VIPS_API __declspec(dllexport)

Diff for: tests/042.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ can set metadata
77
$filename = dirname(__FILE__) . "/images/img_0076.jpg";
88
$profilename = dirname(__FILE__) . "/images/sRGB.icc";
99
$image = vips_image_new_from_file($filename)["out"];
10-
$blob_type = vips_type_from_name("VipsBlob");
1110
$data = file_get_contents($profilename);
1211
$output_filename = dirname(__FILE__) . "/x.tif";
1312

1413
$image = vips_call("copy", $image)["out"];
15-
$result = vips_image_set_type($image, $blob_type, "icc-profile-data", $data);
14+
$result = vips_image_set_type($image, "VipsBlob", "icc-profile-data", $data);
1615
if ($result == 0) {
1716
echo "pass set_metadata\n";
1817
}

Diff for: vips-1.0.12.tgz

548 KB
Binary file not shown.

Diff for: vips.c

+22-5
Original file line numberDiff line numberDiff line change
@@ -1777,19 +1777,20 @@ PHP_FUNCTION(vips_type_from_name)
17771777
}
17781778
/* }}} */
17791779

1780-
/* {{{ proto long vips_image_set_type(resource image, integer gtype, string field, mixed value)
1780+
/* {{{ proto long vips_image_set_type(resource image, integer|string type, string field, mixed value)
17811781
Set field on image */
17821782
PHP_FUNCTION(vips_image_set_type)
17831783
{
17841784
zval *im;
1785-
long type;
1785+
zval *type;
17861786
char *field_name;
17871787
size_t field_name_len;
17881788
zval *zvalue;
17891789
VipsImage *image;
1790+
GType gtype;
17901791
GValue gvalue = { 0 };
17911792

1792-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlsz",
1793+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rzsz",
17931794
&im, &type, &field_name, &field_name_len, &zvalue) == FAILURE) {
17941795
RETURN_LONG(-1);
17951796
}
@@ -1799,11 +1800,27 @@ PHP_FUNCTION(vips_image_set_type)
17991800
RETURN_LONG(-1);
18001801
}
18011802

1802-
if (type <= 0) {
1803+
switch (Z_TYPE_P(type)) {
1804+
case IS_LONG:
1805+
/* On 32-bit platforms, PHP's long is only 32-bits, so it can't
1806+
* hold a GType. We need to be able accept string as well.
1807+
*/
1808+
gtype = zval_get_long(type);
1809+
break;
1810+
1811+
case IS_STRING:
1812+
gtype = g_type_from_name(ZSTR_VAL(zval_get_string(type)));
1813+
break;
1814+
1815+
default:
1816+
gtype = 0;
1817+
}
1818+
1819+
if (gtype <= 0) {
18031820
RETURN_LONG(-1);
18041821
}
18051822

1806-
g_value_init(&gvalue, type);
1823+
g_value_init(&gvalue, gtype);
18071824

18081825
if (vips_php_zval_to_gval(NULL, zvalue, &gvalue)) {
18091826
RETURN_LONG(-1);

0 commit comments

Comments
 (0)