File tree 2 files changed +10
-6
lines changed
2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -87,18 +87,20 @@ sharp(input)
87
87
```
88
88
89
89
``` javascript
90
- const data = await sharp (' my-image.jpg' )
90
+ const { data , info } = await sharp (' my-image.jpg' )
91
91
// output the raw pixels
92
92
.raw ()
93
- .toBuffer ();
93
+ .toBuffer ({ resolveWithObject : true } );
94
94
95
95
// create a more type safe way to work with the raw pixel data
96
96
// this will not copy the data, instead it will change `data`s underlying ArrayBuffer
97
97
// so `data` and `pixelArray` point to the same memory location
98
98
const pixelArray = new Uint8ClampedArray (data .buffer );
99
99
100
100
// When you are done changing the pixelArray, sharp takes the `pixelArray` as an input
101
- await sharp (pixelArray).toFile (' my-changed-image.jpg' );
101
+ const { width , height , channels } = info;
102
+ await sharp (pixelArray, { raw: { width, height, channels } })
103
+ .toFile (' my-changed-image.jpg' );
102
104
```
103
105
104
106
Returns ** [ Promise] [ 5 ] < ; [ Buffer] [ 8 ] >** when no callback is provided
Original file line number Diff line number Diff line change @@ -105,18 +105,20 @@ function toFile (fileOut, callback) {
105
105
* .catch(err => { ... });
106
106
*
107
107
* @example
108
- * const data = await sharp('my-image.jpg')
108
+ * const { data, info } = await sharp('my-image.jpg')
109
109
* // output the raw pixels
110
110
* .raw()
111
- * .toBuffer();
111
+ * .toBuffer({ resolveWithObject: true } );
112
112
*
113
113
* // create a more type safe way to work with the raw pixel data
114
114
* // this will not copy the data, instead it will change `data`s underlying ArrayBuffer
115
115
* // so `data` and `pixelArray` point to the same memory location
116
116
* const pixelArray = new Uint8ClampedArray(data.buffer);
117
117
*
118
118
* // When you are done changing the pixelArray, sharp takes the `pixelArray` as an input
119
- * await sharp(pixelArray).toFile('my-changed-image.jpg');
119
+ * const { width, height, channels } = info;
120
+ * await sharp(pixelArray, { raw: { width, height, channels } })
121
+ * .toFile('my-changed-image.jpg');
120
122
*
121
123
* @param {Object } [options]
122
124
* @param {boolean } [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
You can’t perform that action at this time.
0 commit comments