@@ -35,10 +35,19 @@ step during the `npm i` command.
3535## Image
3636
3737``` js
38- const Image = require (' image-raub' );
38+ import Image from ' image-raub' ;
39+ const image = new Image (' images/test.png' ); // relative to CWD
40+ icon .on (' load' , () => { console .log (' data' , image .width , image .height , image .data ); });
3941```
4042
41- See [ TypeScript defenitions] ( /index.d.ts ) for more details.
43+ For loaded images, ` image.data ` will contain a ` Buffer ` of ` 4 * width * height ` bytes.
44+ You can directly interact with that buffer - read or write, and then save the image
45+ to a file or use it any other way.
46+
47+ With ` Image.fromPixels() ` it is possible to generate new images from scratch by providing
48+ your own data buffer.
49+
50+ See [ TS declarations] ( /index.d.ts ) for more details.
4251
4352
4453### Set window icon
@@ -47,7 +56,7 @@ Compatible with [glfw-raub](https://github.com/node-3d/glfw-raub) `window.icon`
4756
4857``` js
4958const icon = new Image ();
50- icon .src = __dirname + ' / icons/logo.png' ;
59+ icon .src = ' icons/logo.png' ;
5160icon .on (' load' , () => { window .icon = icon; });
5261```
5362
@@ -72,7 +81,7 @@ image.onload = () => {
7281 gl .bindTexture (gl .TEXTURE_2D , null );
7382};
7483
75- image .src = ` ${ __dirname } /texture .jpg` ;
84+ image .src = ' textures/grass .jpg' ;
7685```
7786
7887
0 commit comments