diff --git a/README.md b/README.md index 08d7337..ed2b020 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,26 @@ So the steps to generate a unique picture for the key are like that: 3. Circles from the first part of the key are bigger and are placed with normal composite mode. Circles from the second part are smaller and placed with 'lighten' composite mode. 4. Then half of the canvas gets reflected to create a nice symmetric 'portrait' to be used as an avatar of a SEA public key. -## Installation +## How to install? + ### npm / pnpm -`npm i gun-avatar` in a build environment +Run `npm i gun-avatar` in a build environment. Then you can `import {gunAvatar} from 'gun-avatar'` and use the function to render the avatar. Or just `import 'gun-avatar'` for custom element use. -### browser +### Browser Add `` to your html -## Usage +## How to use? + +### 1. Custom HTML element + +After you add the script to the page you get a custom element `` for ease of use. The attributes are reactive to changes. Set `dark` attribute if you need a dark version of the avatar. Set `round` attribute to get a rounded image. Also `size` in pixels is available. + +```html + + +``` -### 1. HTML img tag with `data-pub` attribute +### 2. HTML img tag with `data-pub` attribute Add the script to the page and then add `gun-avatar` class to an img tag along with add `data-pub` attribute with the pub key. `gun-avatar` automatically finds them on page and fills with corresponding base64 picture data. You can set `data-size` in px and style the avatar with css as you want. Also there's `data-dark` option to generate a dark version of the same avatar. You can add `.gun-avatar {border-radius: 100%}` to tour css to make it round. @@ -29,7 +39,7 @@ Add the script to the page and then add `gun-avatar` class to an img tag along w ``` -### 2. JS function +### 3. JS function Install the `gun-avatar` package and import the `gunAvatar` function. Then you can use it to generate the base64 string to place into the src attribute with your favourite library or vanilla js. Function get two parameters: `pub` and `size` in px. diff --git a/index.html b/index.html index 6328226..150b9c7 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,8 @@ +