Skip to content

Commit 7be01a6

Browse files
docs: update image loading via browser
2 parents ed6bd73 + 73b135f commit 7be01a6

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

docs/Getting started.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const parsedImage = readSync('../example.jpg');
4343
```
4444

4545
:::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"](#loading-your-first-image-in-browser) part of this section.
4747
:::
4848

4949
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);
7272

7373
### Loading your first image in browser
7474

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:
7676

7777
```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';
8179

80+
let image = await fetchURL('https:://example.com/image.jpg'); // image is ready for usage
8281
image = image.grey();
8382
```
8483

@@ -129,10 +128,7 @@ In the `<body>` part of your code insert your `image-js` script. For instance, h
129128
```html
130129
<script type="module">
131130
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
136132
image = image.grey();
137133
const canvas = document.getElementById('my_canvas');
138134
writeCanvas(image, canvas);
@@ -159,12 +155,9 @@ Thus, in the end your html page should look like this:
159155
<canvas id="my_canvas" />
160156
<script type="module">
161157
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
165159

166160
image = image.grey();
167-
console.log(Image);
168161
const canvas = document.getElementById('my_canvas');
169162
writeCanvas(image, canvas);
170163
</script>

0 commit comments

Comments
 (0)