利用canvas生成Material design風格的頭像:md-avatar

jopen 9年前發布 | 19K 次閱讀 md-avatar 圖形/圖像處理

利用canvas生成Material design風格的頭像:md-avatar63348403-8385-4102-87fb-25e5bbedffe4

install

bower install md-avatar

usage

new mdAvatar(options); // It will return a canvas dom element.

new mdAvatar({
    size: 100,
    text: 'S'
}); // <canvas width="100" height="100">

new mdAvatar({
    size: 64,
    text: 'G'
}).toDataURL(); // data:image/png;base64,.......

options

  • target (default:null)

    The ID of target canvas, or you can pass a canvas dom. If this field not provide, it will return a new canvas element bydocument.createElement('canvas').

  • size (default:32)

    The size of avatar(canvas).

  • text (default:?)

    The text in avatar. You can pass a string in to this field, but it will only take the FIRST char.

  • textColor (default:white)

    The color of text.

  • textSize (default:this.size / 2)

    The size of text.

  • textAlign (default:center)

  • textBaseline (default:middle)

  • fontFamily (default:sans-serif)

  • bgColor (default: depend onthis.text)

    The avatar's background color. By default, it contains color patterns(500) in Material Design Color. And the color's default value is depend onthis.text(not random).

項目主頁:http://www.baiduhome.net/lib/view/home/1438953702692

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!