All Projects → kirill3333 → React Avatar

kirill3333 / React Avatar

Licence: mit
👤 Load, crop & preview avatar with React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Avatar

Xi Electron
A front-end for the xi-editor built with modern web technologies.
Stars: ✭ 333 (-7.76%)
Mutual labels:  canvas
Taro
A lightweight 3D game engine for the web.
Stars: ✭ 345 (-4.43%)
Mutual labels:  canvas
React Mindmap
React component for MindNode maps
Stars: ✭ 357 (-1.11%)
Mutual labels:  react-component
Phaser3 Docs
Phaser 3 Documentation and TypeScript Defs
Stars: ✭ 339 (-6.09%)
Mutual labels:  canvas
Fmap
宇行地图:高仿高德地图Android客户端(持续更新中...)
Stars: ✭ 347 (-3.88%)
Mutual labels:  canvas
D3 Celestial
A star map with d3.js
Stars: ✭ 351 (-2.77%)
Mutual labels:  canvas
React Particles Webgl
🔆 A 2D/3D particle library built on React, Three.js and WebGL
Stars: ✭ 330 (-8.59%)
Mutual labels:  canvas
React Joyride
Create guided tours in your apps
Stars: ✭ 4,215 (+1067.59%)
Mutual labels:  react-component
React Tabtab
💃 Make your react tab dance🕺
Stars: ✭ 347 (-3.88%)
Mutual labels:  react-component
Canvas
Canvas is a Go drawing library based on OpenGL or using software rendering that is very similar to the HTML5 canvas API
Stars: ✭ 358 (-0.83%)
Mutual labels:  canvas
Grimoirejs
A WebGL framework for Web development.
Stars: ✭ 339 (-6.09%)
Mutual labels:  canvas
Mcanvas
用于合成图片的canvas绘制库
Stars: ✭ 343 (-4.99%)
Mutual labels:  canvas
Shader Doodle
A friendly web-component for writing and rendering shaders.
Stars: ✭ 356 (-1.39%)
Mutual labels:  canvas
React Hint
Tooltip component for React, Preact, Inferno
Stars: ✭ 338 (-6.37%)
Mutual labels:  react-component
Openscope
openScope Air Traffic Control Simulator
Stars: ✭ 358 (-0.83%)
Mutual labels:  canvas
Wiv.js
A library for a more wiggly div
Stars: ✭ 331 (-8.31%)
Mutual labels:  canvas
Vue Audio Visual
VueJS audio visualization components
Stars: ✭ 355 (-1.66%)
Mutual labels:  canvas
Troika
A JavaScript framework for interactive 3D and 2D visualizations
Stars: ✭ 342 (-5.26%)
Mutual labels:  canvas
React Pro Sidebar
Customizable and responsive react sidebar library with dropdown menus and unlimited number of nested submenus
Stars: ✭ 359 (-0.55%)
Mutual labels:  react-component
React Canvas
A pluggable layout and graphics system aimed at powering desktop publishing as well as storm-react-diagrams
Stars: ✭ 357 (-1.11%)
Mutual labels:  canvas

react-avatar

👤 Load, crop and preview avatar with ReactJS component

npm version

Demo

Demo website

Install

npm i react-avatar-edit

Usage

import React from 'react'
import ReactDOM from 'react-dom'
import Avatar from 'react-avatar-edit'

class App extends React.Component {

  constructor(props) {
    super(props)
    const src = './example/einshtein.jpg'
    this.state = {
      preview: null,
      src
    }
    this.onCrop = this.onCrop.bind(this)
    this.onClose = this.onClose.bind(this)
    this.onBeforeFileLoad = this.onBeforeFileLoad.bind(this)
  }
  
  onClose() {
    this.setState({preview: null})
  }
  
  onCrop(preview) {
    this.setState({preview})
  }

  onBeforeFileLoad(elem) {
    if(elem.target.files[0].size > 71680){
      alert("File is too big!");
      elem.target.value = "";
    };
  }
  
  render () {
    return (
      <div>
        <Avatar
          width={390}
          height={295}
          onCrop={this.onCrop}
          onClose={this.onClose}
          onBeforeFileLoad={this.onBeforeFileLoad}
          src={this.state.src}
        />
        <img src={this.state.preview} alt="Preview" />
      </div>
    )
  }
}

ReactDOM.render(<App /> , document.getElementById('root'))

Component properties

Prop Type Description
img Image The Image object to display
src String/Base64 The url to base64 string to load (use urls from your domain to prevent security errors)
width Number The width of the editor
height Number The height of the editor (image will fit to this height if neither imageHeight, nor imageWidth is set)
imageWidth Number The desired width of the image, can not be used together with imageHeight
imageHeight Number The desired height of the image, can not be used together with imageWidth
cropRadius Number The crop area radius in px (default: calculated as min image with/height / 3)
cropColor String The crop border color (default: white)
lineWidth Number The crop border width (default: 4)
minCropRadius Number The min crop area radius in px (default: 30)
backgroundColor Sting The color of the image background (default: white)
closeIconColor String The close button color (default: white)
shadingColor String The shading color (default: grey)
shadingOpacity Number The shading area opacity (default: 0.6)
mimeTypes String The mime types used to filter loaded files (default: image/jpeg,image/png)
label String Label text (default: Choose a file)
labelStyle Object The style object for preview label (use camel case for css properties fore example: fontSize)
borderStyle Object The style for object border preview (use camel case for css properties fore example: fontSize)
onImageLoad(image) Function Invoked when image based on src prop finish loading
onCrop(image) Function Invoked when user drag&drop event stop and return croped image in base64 sting
onBeforeFileLoad(file) Function Invoked when user before upload file with internal file loader (etc. check file size)
onFileLoad(file) Function Invoked when user upload file with internal file loader
onClose() Function Invoked when user clicks on close editor button
exportAsSquare Boolean The exported image is a square and the circle is not cut-off from the image
exportSize Number The size the exported image should have (width and height equal). The cropping will be made on the original image to ensure a high quality. Only supported when using "exportAsSquare"
exportMimeType String The mime type that should be used to export the image, supported are: image/jpeg, image/png (Default: image/png)
exportQuality Number The quality that should be used when exporting in image/jpeg. A value between 0.0 and 1.0.

Contributing

  • To start developer server please use npm run start
  • To build production bundle use npm run build
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].