Skip to content

Commit

Permalink
docs: mention @napi-rs/canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored and favna committed Jun 3, 2022
1 parent ef0be31 commit 3ddf9f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

This module requires one of the following packages to be installed for Node.js:

- [`@napi-rs/canvas`](https://www.npmjs.com/package/@napi-rs/canvas)
- [`skia-canvas`](https://www.npmjs.com/package/skia-canvas)
- [`canvas`](https://www.npmjs.com/package/canvas)

Expand All @@ -33,7 +34,7 @@ How to use it:
**Node.js**:

```js
const { Canvas } = require('canvas-constructor/skia');
const { Canvas } = require('canvas-constructor/napi-rs');
// or `canvas-constructor/cairo` if you are using `canvas`

new Canvas(300, 300)
Expand All @@ -42,7 +43,7 @@ new Canvas(300, 300)
.setColor('#FFAE23')
.setTextFont('28px Impact')
.printText('Hello World!', 130, 150)
.toBuffer();
.png();
```

**Browser**:
Expand All @@ -68,21 +69,21 @@ new Canvas(300, 300)
- Write the text 'Hello World!' in the position (130, 150)
- Return a buffer.

Now, let's suppose we want to add images, we'll use `Canvas.resolveImage`, which works in both Node.js and browser:
Now, let's suppose we want to add images, we'll use `Canvas.loadImage`, which works in both Node.js and browser:

```js
const { Canvas, resolveImage } = require('canvas-constructor/skia');
const { Canvas, loadImage } = require('canvas-constructor/napi-rs');

async function createCanvas() {
const image = await resolveImage('./images/kitten.png');
const image = await loadImage('./images/kitten.png');

return new Canvas(300, 400)
.printImage(image, 0, 0, 300, 400)
.setColor('#FFAE23')
.setTextFont('28px Impact')
.setTextAlign('center')
.printText('Kitten!', 150, 370)
.toBufferAsync();
.pngAsync();
}
```

Expand All @@ -96,5 +97,5 @@ async function createCanvas() {

And now, you have created an image with a kitten in the background and some centred text in the bottom of it.

If you experience issues with `skia-canvas` or `canvas`, please refer to their respective package repositories, this
If you experience issues with `@napi-rs/canvas`, `skia-canvas`, or `canvas`, please refer to their respective package repositories, this
package is just a convenient wrapper for the two.
4 changes: 2 additions & 2 deletions guides/Getting Started/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ new Canvas(300, 300)
- Write the text 'Hello World!' in the position (130, 150)
- Return a buffer.

Now, let's suppose we want to add images, we'll use `Canvas.resolveImage`, which works in both Node.js and browser:
Now, let's suppose we want to add images, we'll use `Canvas.loadImage`, which works in both Node.js and browser:

```js
const { Canvas } = require('canvas-constructor');

async function createCanvas() {
const image = await Canvas.resolveImage('./images/kitten.png');
const image = await Canvas.loadImage('./images/kitten.png');

return new Canvas(300, 400)
.printImage(image, 0, 0, 300, 400)
Expand Down
4 changes: 2 additions & 2 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h3>None</h3>
new CanvasConstructor.Canvas(canvasElement)
.setColor('#AEFD54')
.printRectangle(5, 5, 290, 290)
.printImage(await CanvasConstructor.resolveImage('https://github.com/NM-EEA-Y.png'), 0, 0, 300, 300)
.printImage(await CanvasConstructor.loadImage('https://github.com/NM-EEA-Y.png'), 0, 0, 300, 300)
.setTextAlign('center')
.setColor('#000000')
.setTextFont('28px Impact')
Expand All @@ -105,7 +105,7 @@ <h3>None</h3>

<script type="text/javascript">
(async () => {
const image = await CanvasConstructor.resolveImage('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
const image = await CanvasConstructor.loadImage('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
for (const fit of ['fill', 'contain', 'cover', 'none']) {
const canvasElement = document.getElementById(`circular-image-${fit}`);
new CanvasConstructor.Canvas(canvasElement)
Expand Down

0 comments on commit 3ddf9f6

Please sign in to comment.