@@ -43,7 +43,7 @@ const parsedImage = readSync('../example.jpg');
43
43
```
44
44
45
45
::: tip
46
- Node.js can also load an image via ` fetch ` function . To get more information take a look at "Browser" part of this section.
46
+ Node.js can also load an image via ` fetchURL ` . To get more information take a look at "Browser" part of this section.
47
47
:::
48
48
49
49
Once the image is loaded, it returns an instance of the ` Image ` class, so its methods can be applied.
@@ -72,13 +72,12 @@ writeSync('../example.jpg', image);
72
72
73
73
### Loading your first image in browser
74
74
75
- To load an image via browser, in order to instantiate it, you need to get an ` arrayBuffer ` . One of the ways :
75
+ To load an image via browser, in order to instantiate it, you may use ` fetchURL ` function :
76
76
77
77
``` ts
78
- const data = await fetch (' https:://example.com/image.jpg' );
79
- const bufferedData = await data .arrayBuffer ();
80
- let image = decode (new DataView (bufferedData )); // image is ready for usage
78
+ import { fetchURL } from ' image-js' ;
81
79
80
+ let image = await fetchURL (' https:://example.com/image.jpg' ); // image is ready for usage
82
81
image = image .grey ();
83
82
```
84
83
@@ -129,10 +128,7 @@ In the `<body>` part of your code insert your `image-js` script. For instance, h
129
128
``` html
130
129
<script type =" module" >
131
130
import {(Image , writeCanvas )} from ' image-js' ;
132
- const data = await fetch (' https:://example.com/image.jpg' );
133
- const bufferedData = await data .arrayBuffer ();
134
- let image = decode (new DataView (bufferedData)); // image is ready for usage
135
-
131
+ let image = await fetchURL (' https:://example.com/image.jpg' ); // image is ready for usage
136
132
image = image .grey ();
137
133
const canvas = document .getElementById (' my_canvas' );
138
134
writeCanvas (image, canvas);
@@ -159,12 +155,9 @@ Thus, in the end your html page should look like this:
159
155
< canvas id = " my_canvas" / >
160
156
< script type = " module" >
161
157
import {Image , writeCanvas ,decode } from ' image-js' ;
162
- const data = await fetch (' https:://example.com/image.jpg' );
163
- const bufferedData = await data .arrayBuffer ();
164
- let image = decode (new DataView (bufferedData )); // image is ready for usage
158
+ let image = await fetchURL (' https:://example.com/image.jpg' ); // image is ready for usage
165
159
166
160
image = image .grey ();
167
- console .log (Image );
168
161
const canvas = document .getElementById (' my_canvas' );
169
162
writeCanvas (image , canvas );
170
163
< / script >
0 commit comments