Giter VIP home page Giter VIP logo

yysuni / blockies-react-svg Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 2.0 833 KB

Blockies react SVG function component, blocky identicons, address-unique ethereum avatar, SVG base64 generation in browser or nodejs.

Home Page: https://blockies-react-svg.vercel.app/

License: MIT License

TypeScript 90.26% Shell 0.49% JavaScript 6.74% HTML 1.60% CSS 0.92%
blockies react svg base64 ethereum address avatar nodejs

blockies-react-svg's Introduction

blockies-react-svg

Blockies react SVG function component, blocky identicons, address-unique ethereum avatar, SVG base64 generation in browser or nodejs.

It allows you to use responsive width and height without rerendering because of SVG properties, and it will store the result.

Base64 url is smaller(~2kb) than the canvas size(~16kb), so it is suitable for server-side rendering.(8x8)

The address will automatically be converted to lower case until you set the caseSensitive property.

Sample of generated blockies

Installation

$ npm i blockies-react-svg
$ npm i blockies-react-svg@canary

Usage

// canary
import { BlockiesSvg, BlockiesSvgSync, makeBlockiesUrl, makeBlockiesSvgString } from 'blockies-react-svg'

// <BlockiesSvgSync 
<BlockiesSvg 
  address={address}
//size={8}
//scale={10}
//caseSensitive={false}
//defaultBackgroundColor="black"
  className='classname'
  style={styles} 
  />

<img src={makeBlockiesUrl(address)} />

<div dangerouslySetInnerHTML={{ __html: makeBlockiesSvgString(address) }} />

Why SVG?

  1. Canvas render doesn't support arbitrary size or other customized styles.

  2. SVG is the better experience, because of the infinite resolution.

  3. SVG file size is smaller than canvas.

Todo

  • ts component
  • base64 url
  • js compile
  • demo display (github pages)
  • pure base64 (remove react-dom/server dependence, ~70kb bundle size)
  • support nodejs
  • svg mirror optmization (reduce image size)
  • svg polygon optmization (reduce image size)
  • more shapes
  • different rand algorithm

blockies-react-svg's People

Contributors

amanzrx4 avatar yysuni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

blockies-react-svg's Issues

Attempted import error: 'blockies-react-svg' does not contain a default export (imported as 'BlockiesSvg').

Hi,
thanks for the great library. I ran into a small issue in a next.js v13 app, when using the lib I get the following error:

Attempted import error: 'blockies-react-svg' does not contain a default export (imported as 'BlockiesSvg').

Using it like this:

import BlockiesSvg from 'blockies-react-svg'
<BlockiesSvg 
  address={address.toLowerCase()}
  className="identicon" 
  />

tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "app/[walletId]/currencies"],
  "exclude": ["node_modules"]
}

Any idea what might cause this?

How to limit colors used

Certain colors like dark red and dark green don't go together. Is there a way to limit or change the color options? If not, can you point me to the code loation where I can change that?

thank you for open sourcing this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.