@@ -1375,8 +1375,7 @@ PHP_FUNCTION(vips_image_copy_memory)
1375
1375
RETURN_LONG (-1 );
1376
1376
}
1377
1377
1378
- new_image = vips_image_copy_memory (image );
1379
- if (!new_image ) {
1378
+ if (!(new_image = vips_image_copy_memory (image ))) {
1380
1379
RETURN_LONG (-1 );
1381
1380
}
1382
1381
@@ -1389,6 +1388,78 @@ PHP_FUNCTION(vips_image_copy_memory)
1389
1388
}
1390
1389
/* }}} */
1391
1390
1391
+ /* {{{ proto resource vips_image_new_from_memory(string data, integer width, integer height, integer bands, string format)
1392
+ Wrap an image around a memory array. */
1393
+ PHP_FUNCTION (vips_image_new_from_memory )
1394
+ {
1395
+ char * bstr ;
1396
+ size_t bstr_len ;
1397
+ long width ;
1398
+ long height ;
1399
+ long bands ;
1400
+ char * format ;
1401
+ size_t format_len ;
1402
+ int format_value ;
1403
+ VipsBandFormat band_format ;
1404
+ VipsImage * image ;
1405
+ zend_resource * resource ;
1406
+ zval zvalue ;
1407
+
1408
+ VIPS_DEBUG_MSG ("vips_image_new_from_memory:\n" );
1409
+
1410
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "slllp" ,
1411
+ & bstr , & bstr_len , & width , & height , & bands , & format , & format_len ) == FAILURE ) {
1412
+ RETURN_LONG (-1 );
1413
+ }
1414
+
1415
+ if ((format_value = vips_enum_from_nick ("php-vips" , VIPS_TYPE_BAND_FORMAT , format )) < 0 ) {
1416
+ RETURN_LONG (-1 );
1417
+ }
1418
+ band_format = format_value ;
1419
+
1420
+ if (!(image = vips_image_new_from_memory_copy (bstr , bstr_len , width , height , bands ,
1421
+ band_format ))) {
1422
+ RETURN_LONG (-1 );
1423
+ }
1424
+
1425
+ /* Return as an array for all OK, -1 for error.
1426
+ */
1427
+ array_init (return_value );
1428
+ resource = zend_register_resource (image , le_gobject );
1429
+ ZVAL_RES (& zvalue , resource );
1430
+ add_assoc_zval (return_value , "out" , & zvalue );
1431
+ }
1432
+ /* }}} */
1433
+
1434
+ /* {{{ proto string vips_image_write_to_memory(resource image)
1435
+ Write an image to a memory array. */
1436
+ PHP_FUNCTION (vips_image_write_to_memory )
1437
+ {
1438
+ zval * IM ;
1439
+ VipsImage * image ;
1440
+ size_t arr_len ;
1441
+ uint8_t * arr ;
1442
+
1443
+ VIPS_DEBUG_MSG ("vips_image_write_to_memory:\n" );
1444
+
1445
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "r" , & IM ) == FAILURE ) {
1446
+ RETURN_LONG (-1 );
1447
+ }
1448
+
1449
+ if ((image = (VipsImage * )zend_fetch_resource (Z_RES_P (IM ),
1450
+ "GObject" , le_gobject )) == NULL ) {
1451
+ RETURN_LONG (-1 );
1452
+ }
1453
+
1454
+ if (!(arr = vips_image_write_to_memory (image , & arr_len ))) {
1455
+ RETURN_LONG (-1 );
1456
+ }
1457
+
1458
+ RETVAL_STRINGL ((char * )arr , arr_len );
1459
+ g_free (arr );
1460
+ }
1461
+ /* }}} */
1462
+
1392
1463
/* {{{ proto string|long vips_foreign_find_load(string filename)
1393
1464
Find a loader for a file */
1394
1465
PHP_FUNCTION (vips_foreign_find_load )
@@ -1933,6 +2004,18 @@ ZEND_BEGIN_ARG_INFO(arginfo_vips_image_copy_memory, 0)
1933
2004
ZEND_ARG_INFO (0 , image )
1934
2005
ZEND_END_ARG_INFO ()
1935
2006
2007
+ ZEND_BEGIN_ARG_INFO (arginfo_vips_image_new_from_memory , 0 )
2008
+ ZEND_ARG_INFO (0 , array )
2009
+ ZEND_ARG_INFO (0 , width )
2010
+ ZEND_ARG_INFO (0 , height )
2011
+ ZEND_ARG_INFO (0 , bands )
2012
+ ZEND_ARG_INFO (0 , format )
2013
+ ZEND_END_ARG_INFO ()
2014
+
2015
+ ZEND_BEGIN_ARG_INFO (arginfo_vips_image_write_to_memory , 0 )
2016
+ ZEND_ARG_INFO (0 , image )
2017
+ ZEND_END_ARG_INFO ()
2018
+
1936
2019
ZEND_BEGIN_ARG_INFO (arginfo_vips_foreign_find_load , 0 )
1937
2020
ZEND_ARG_INFO (0 , filename )
1938
2021
ZEND_END_ARG_INFO ()
@@ -2003,6 +2086,8 @@ const zend_function_entry vips_functions[] = {
2003
2086
PHP_FE (vips_image_write_to_file , arginfo_vips_image_write_to_file )
2004
2087
PHP_FE (vips_image_write_to_buffer , arginfo_vips_image_write_to_buffer )
2005
2088
PHP_FE (vips_image_copy_memory , arginfo_vips_image_copy_memory )
2089
+ PHP_FE (vips_image_new_from_memory , arginfo_vips_image_new_from_memory )
2090
+ PHP_FE (vips_image_write_to_memory , arginfo_vips_image_write_to_memory )
2006
2091
PHP_FE (vips_foreign_find_load , arginfo_vips_foreign_find_load )
2007
2092
PHP_FE (vips_foreign_find_load_buffer , arginfo_vips_foreign_find_load_buffer )
2008
2093
PHP_FE (vips_interpolate_new , arginfo_vips_interpolate_new )
0 commit comments