1717
1818---
1919
20+ ## Live Demo
21+
22+ [ ![ Edit on Stackblitz] ( https://developer.stackblitz.com/img/open_in_stackblitz.svg )] ( https://stackblitz.com/edit/canvas-constructor-vite?file=main.js )
23+
2024## Installation
2125
2226This module requires one of the following packages to be installed for Node.js:
@@ -35,8 +39,8 @@ How to use it:
3539
3640``` js
3741const { Canvas } = require (' canvas-constructor/napi-rs' );
38- // or ` canvas-constructor/skia` if you are using `skia-canvas`
39- // or ` canvas-constructor/cairo` if you are using `canvas`
42+ // or ' canvas-constructor/skia' if you are using `skia-canvas`
43+ // or ' canvas-constructor/cairo' if you are using `canvas`
4044
4145new Canvas (300 , 300 )
4246 .setColor (' #AEFD54' )
@@ -50,6 +54,7 @@ new Canvas(300, 300)
5054** Browser** :
5155
5256``` html
57+ <canvas id =" canvas" width =" 300" height =" 400" ></canvas >
5358<script type =" text/javascript" src =" https://unpkg.com/canvas-constructor" ></script >
5459<script type =" text/javascript" >
5560 const canvasElement = document .getElementById (' canvas' );
@@ -62,17 +67,13 @@ new Canvas(300, 300)
6267 </script >
6368```
6469
65- Alternatively, you can import ` canvas-constructor/browser ` .
70+ Alternatively, you can import ` canvas-constructor/browser ` if you are using a bundler such as Vite, Webpack, or Rollup:
6671
67- - That will create a canvas with size of 300 pixels width, 300 pixels height.
68- - Set the color to #AEFD54
69- - Draw a rectangle with the previous color, covering all the pixels from (5, 5) to (290 + 5, 290 + 5)
70- - Set the color to #FFAE23
71- - Set the font size to 28 pixels with font Impact.
72- - Write the text 'Hello World!' in the position (130, 150)
73- - Return a buffer.
72+ ``` js
73+ import { Canvas } from ' canvas-constructor/browser' ;
74+ ```
7475
75- Now, let's suppose we want to add images, we'll use ` Canvas. loadImage` , which works in both Node.js and browser :
76+ Now, let's suppose we want to add images, we can use the ` loadImage ` function , which works in all supported environments :
7677
7778``` js
7879const { Canvas , loadImage } = require (' canvas-constructor/napi-rs' );
@@ -90,15 +91,8 @@ async function createCanvas() {
9091}
9192```
9293
93- - That will create a canvas with size of 300 pixels width, 400 pixels height.
94- - Draw an image, given a Buffer (the image from the images folder).
95- - Set the color to #FFAE23
96- - Set the font size to 28 pixels with font Impact.
97- - Set the text alignment to center.
98- - Write the text 'Kitten!' in the position (150, 370)
99- - Return a buffer.
100-
101- And now, you have created an image with a kitten in the background and some centred text in the bottom of it.
94+ And now, you have created an image with a kitten in the background and some centered text at the bottom of it.
10295
10396If you experience issues with ` @napi-rs/canvas ` , ` skia-canvas ` , or ` canvas ` , please refer to their respective package repositories, this
104- package is just a convenient wrapper for the three.
97+ package is just a convenient wrapper that makes it easier to use the canvas in both Node.js and the browser. And does not modify the
98+ behavior of the underlying canvas implementation.
0 commit comments