File tree 2 files changed +9
-3
lines changed
docs/src/content/docs/guides
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ export function createJimp<
201
201
}
202
202
203
203
/**
204
- * Create a Jimp instance from a URL or a file path
204
+ * Create a Jimp instance from a URL, a file path, or a Buffer
205
205
* @example
206
206
* ```ts
207
207
* import { Jimp } from "jimp";
@@ -213,9 +213,13 @@ export function createJimp<
213
213
* const image = await Jimp.read("https://upload.wikimedia.org/wikipedia/commons/0/01/Bot-Test.jpg");
214
214
* ```
215
215
*/
216
- static async read ( url : string ) {
216
+ static async read ( url : string | Buffer | ArrayBuffer ) {
217
+ if ( Buffer . isBuffer ( url ) || url instanceof ArrayBuffer ) {
218
+ return this . fromBuffer ( url ) ;
219
+ }
220
+
217
221
if ( existsSync ( url ) ) {
218
- return Jimp . fromBuffer ( await readFile ( url ) ) ;
222
+ return this . fromBuffer ( await readFile ( url ) ) ;
219
223
}
220
224
221
225
const [ fetchErr , response ] = await to ( fetch ( url ) ) ;
Original file line number Diff line number Diff line change @@ -91,6 +91,8 @@ async function main() {
91
91
}
92
92
```
93
93
94
+ It will also read from a ` Buffer ` or ` ArrayBuffer ` .
95
+
94
96
### ` Jimp.fromBuffer `
95
97
96
98
You can load an image from a buffer.
You can’t perform that action at this time.
0 commit comments