|
123 | 123 | * $im = $im->conv($mask);
|
124 | 124 | * ```
|
125 | 125 | *
|
126 |
| - * `Image::new_from_array` creates an image from an array constant. The 8 at |
| 126 | + * `Image::newFromArray` creates an image from an array constant. The 8 at |
127 | 127 | * the end sets the scale: the amount to divide the image by after
|
128 | 128 | * integer convolution. See the libvips API docs for `vips_conv()` (the operation
|
129 | 129 | * invoked by `Image::conv`) for details on the convolution operator. See
|
@@ -930,6 +930,40 @@ public static function newFromArray(
|
930 | 930 | return $result;
|
931 | 931 | }
|
932 | 932 |
|
| 933 | + /** |
| 934 | + * Wraps an Image around an area of memory containing a C-style array. |
| 935 | + * |
| 936 | + * @param array $data C-style array. |
| 937 | + * @param int $width Image width in pixels. |
| 938 | + * @param int $height Image height in pixels. |
| 939 | + * @param int $bands Number of bands. |
| 940 | + * @param string $format Band format. (@see BandFormat) |
| 941 | + * |
| 942 | + * @return Image A new Image. |
| 943 | + */ |
| 944 | + public static function newFromMemory( |
| 945 | + array $data, |
| 946 | + int $width, |
| 947 | + int $height, |
| 948 | + int $bands, |
| 949 | + string $format |
| 950 | + ): Image { |
| 951 | + Utils::debugLog('newFromMemory', [ |
| 952 | + 'instance' => null, |
| 953 | + 'arguments' => [$data, $width, $height, $bands, $format] |
| 954 | + ]); |
| 955 | + |
| 956 | + $result = vips_image_new_from_memory($data, $width, $height, $bands, $format); |
| 957 | + if ($result === -1) { |
| 958 | + self::errorVips(); |
| 959 | + } |
| 960 | + $result = self::wrapResult($result); |
| 961 | + |
| 962 | + Utils::debugLog('newFromMemory', ['result' => $result]); |
| 963 | + |
| 964 | + return $result; |
| 965 | + } |
| 966 | + |
933 | 967 | /**
|
934 | 968 | * Make an interpolator from a name.
|
935 | 969 | *
|
@@ -1048,6 +1082,28 @@ public function writeToBuffer(string $suffix, array $options = []): string
|
1048 | 1082 | return $result;
|
1049 | 1083 | }
|
1050 | 1084 |
|
| 1085 | + /** |
| 1086 | + * Write an image to a large memory array. |
| 1087 | + * |
| 1088 | + * @return array The memory array. |
| 1089 | + */ |
| 1090 | + public function writeToMemory(): array |
| 1091 | + { |
| 1092 | + Utils::debugLog('writeToMemory', [ |
| 1093 | + 'instance' => $this, |
| 1094 | + 'arguments' => [] |
| 1095 | + ]); |
| 1096 | + |
| 1097 | + $result = vips_image_write_to_memory($this->image); |
| 1098 | + if ($result === -1) { |
| 1099 | + self::errorVips(); |
| 1100 | + } |
| 1101 | + |
| 1102 | + Utils::debugLog('writeToMemory', ['result' => $result]); |
| 1103 | + |
| 1104 | + return $result; |
| 1105 | + } |
| 1106 | + |
1051 | 1107 | /**
|
1052 | 1108 | * Copy to memory.
|
1053 | 1109 | *
|
|
0 commit comments