@@ -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,93 @@ PHP_FUNCTION(vips_image_copy_memory)
1389
1388
}
1390
1389
/* }}} */
1391
1390
1391
+ /* {{{ proto resource vips_image_write_to_memory(array 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
+ HashTable * ht ;
1396
+ long width ;
1397
+ long height ;
1398
+ long bands ;
1399
+ char * format ;
1400
+ size_t format_len ;
1401
+ int format_value ;
1402
+ VipsBandFormat band_format ;
1403
+ VipsImage * image ;
1404
+ zend_resource * resource ;
1405
+ zval zvalue ;
1406
+
1407
+ VIPS_DEBUG_MSG ("vips_image_new_from_memory:\n" );
1408
+
1409
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "hlllp" ,
1410
+ & ht , & width , & height , & bands , & format , & format_len ) == FAILURE ) {
1411
+ RETURN_LONG (-1 );
1412
+ }
1413
+
1414
+ if ((format_value = vips_enum_from_nick ("enum" , VIPS_TYPE_BAND_FORMAT , format )) < 0 ) {
1415
+ RETURN_LONG (-1 );
1416
+ }
1417
+ band_format = format_value ;
1418
+
1419
+ const int size = zend_hash_num_elements (ht );
1420
+ int arr [size ];
1421
+ int i ;
1422
+
1423
+ for (i = 0 ; i < size ; i ++ ) {
1424
+ zval * ele ;
1425
+
1426
+ if ((ele = zend_hash_index_find (ht , i )) != NULL ) {
1427
+ arr [i ] = zval_get_long (ele );
1428
+ }
1429
+ }
1430
+
1431
+ if (!(image = vips_image_new_from_memory_copy (arr , size , width , height , bands ,
1432
+ band_format ))) {
1433
+ RETURN_LONG (-1 );
1434
+ }
1435
+
1436
+ /* Return as an array for all OK, -1 for error.
1437
+ */
1438
+ array_init (return_value );
1439
+ resource = zend_register_resource (image , le_gobject );
1440
+ ZVAL_RES (& zvalue , resource );
1441
+ add_assoc_zval (return_value , "out" , & zvalue );
1442
+ }
1443
+ /* }}} */
1444
+
1445
+ /* {{{ proto array vips_image_write_to_memory(resource image)
1446
+ Write an image to a memory array. */
1447
+ PHP_FUNCTION (vips_image_write_to_memory )
1448
+ {
1449
+ zval * IM ;
1450
+ VipsImage * image ;
1451
+ size_t arr_len ;
1452
+ uint8_t * arr ;
1453
+
1454
+ VIPS_DEBUG_MSG ("vips_image_write_to_memory:\n" );
1455
+
1456
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "r" , & IM ) == FAILURE ) {
1457
+ RETURN_LONG (-1 );
1458
+ }
1459
+
1460
+ if ((image = (VipsImage * )zend_fetch_resource (Z_RES_P (IM ),
1461
+ "GObject" , le_gobject )) == NULL ) {
1462
+ RETURN_LONG (-1 );
1463
+ }
1464
+
1465
+ if (!(arr = vips_image_write_to_memory (image , & arr_len ))) {
1466
+ RETURN_LONG (-1 );
1467
+ }
1468
+
1469
+ array_init (return_value );
1470
+
1471
+ int i ;
1472
+ for (i = 0 ; i < arr_len ; i ++ ) {
1473
+ add_next_index_long (return_value , arr [i ]);
1474
+ }
1475
+ }
1476
+ /* }}} */
1477
+
1392
1478
/* {{{ proto string|long vips_foreign_find_load(string filename)
1393
1479
Find a loader for a file */
1394
1480
PHP_FUNCTION (vips_foreign_find_load )
@@ -1933,6 +2019,18 @@ ZEND_BEGIN_ARG_INFO(arginfo_vips_image_copy_memory, 0)
1933
2019
ZEND_ARG_INFO (0 , image )
1934
2020
ZEND_END_ARG_INFO ()
1935
2021
2022
+ ZEND_BEGIN_ARG_INFO (arginfo_vips_image_new_from_memory , 0 )
2023
+ ZEND_ARG_INFO (0 , array )
2024
+ ZEND_ARG_INFO (0 , width )
2025
+ ZEND_ARG_INFO (0 , height )
2026
+ ZEND_ARG_INFO (0 , bands )
2027
+ ZEND_ARG_INFO (0 , format )
2028
+ ZEND_END_ARG_INFO ()
2029
+
2030
+ ZEND_BEGIN_ARG_INFO (arginfo_vips_image_write_to_memory , 0 )
2031
+ ZEND_ARG_INFO (0 , image )
2032
+ ZEND_END_ARG_INFO ()
2033
+
1936
2034
ZEND_BEGIN_ARG_INFO (arginfo_vips_foreign_find_load , 0 )
1937
2035
ZEND_ARG_INFO (0 , filename )
1938
2036
ZEND_END_ARG_INFO ()
@@ -2003,6 +2101,8 @@ const zend_function_entry vips_functions[] = {
2003
2101
PHP_FE (vips_image_write_to_file , arginfo_vips_image_write_to_file )
2004
2102
PHP_FE (vips_image_write_to_buffer , arginfo_vips_image_write_to_buffer )
2005
2103
PHP_FE (vips_image_copy_memory , arginfo_vips_image_copy_memory )
2104
+ PHP_FE (vips_image_new_from_memory , arginfo_vips_image_new_from_memory )
2105
+ PHP_FE (vips_image_write_to_memory , arginfo_vips_image_write_to_memory )
2006
2106
PHP_FE (vips_foreign_find_load , arginfo_vips_foreign_find_load )
2007
2107
PHP_FE (vips_foreign_find_load_buffer , arginfo_vips_foreign_find_load_buffer )
2008
2108
PHP_FE (vips_interpolate_new , arginfo_vips_interpolate_new )
0 commit comments