├── .nojekyll ├── .eslintignore ├── config ├── prod.env.js ├── dev.env.js └── index.js ├── src ├── index.js ├── main.js ├── examples │ ├── VueAvatarEditor.html │ ├── VueAvatarEditor.js │ ├── BasicVueAvatar.vue │ ├── VueAvatarEditor.vue │ ├── BasicVueAvatar.js │ └── BasicVueAvatar.html ├── App.vue └── components │ ├── VueAvatarEditor.vue │ └── VueAvatar.vue ├── .postcssrc.js ├── .gitignore ├── .babelrc ├── index.html ├── .eslintrc.js ├── LICENSE ├── package.json └── README.md /.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import VueAvatar from './components/VueAvatar.vue'; 2 | import VueAvatarEditor from './components/VueAvatarEditor.vue'; 3 | export default VueAvatarEditor; 4 | 5 | export { VueAvatar, VueAvatarEditor }; -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import App from './App'; 3 | 4 | Vue.config.productionTip = false; 5 | 6 | /* eslint-disable no-new */ 7 | new Vue({ 8 | el: '#app', 9 | render: h => h(App) 10 | }); 11 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserlist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/VueAvatarEditor.html: -------------------------------------------------------------------------------- 1 |
2 | 8 | 9 | 10 |
11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | npm-debug.log* 4 | yarn-debug.log* 5 | yarn-error.log* 6 | 7 | # Editor directories and files 8 | .idea 9 | *.suo 10 | *.ntvs* 11 | *.njsproj 12 | *.sln 13 | 14 | *~ 15 | \#*\# 16 | /.emacs.desktop 17 | /.emacs.desktop.lock 18 | *.elc 19 | .\#* 20 | 21 | dist/ -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }] 9 | ], 10 | "plugins": [], 11 | "env": { 12 | "test": { 13 | "presets": ["env"], 14 | "plugins": ["istanbul"] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | vue-avatar-editor 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/examples/VueAvatarEditor.js: -------------------------------------------------------------------------------- 1 | import VueAvatarEditor from '@/components/VueAvatarEditor'; 2 | 3 | export default { 4 | components: { 5 | VueAvatarEditor 6 | }, 7 | methods: { 8 | onSelectFile (files) { 9 | console.log('here is your file', files[0]); 10 | }, 11 | saveClicked (img) { 12 | this.$refs.image.src = img.toDataURL(); 13 | } 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /src/examples/BasicVueAvatar.vue: -------------------------------------------------------------------------------- 1 | 17 | -------------------------------------------------------------------------------- /src/examples/VueAvatarEditor.vue: -------------------------------------------------------------------------------- 1 | 17 | -------------------------------------------------------------------------------- /src/examples/BasicVueAvatar.js: -------------------------------------------------------------------------------- 1 | import VueAvatar from '@/components/VueAvatar'; 2 | 3 | export default { 4 | components: { 5 | VueAvatar 6 | }, 7 | data () { 8 | return { 9 | rotation: 0, 10 | scale: 1, 11 | borderRadius: 0 12 | }; 13 | }, 14 | methods: { 15 | saveClicked () { 16 | var img = this.$refs.vueavatar.getImageScaled(); 17 | this.$refs.image.src = img.toDataURL(); 18 | }, 19 | onImageReady () { 20 | this.scale = 1; 21 | this.rotation = 0; 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // http://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style 13 | extends: 'standard', 14 | // required to lint *.vue files 15 | plugins: [ 16 | 'html' 17 | ], 18 | // add your custom rules here 19 | 'rules': { 20 | // allow paren-less arrow functions 21 | 'arrow-parens': 0, 22 | // allow async-await 23 | 'generator-star-spacing': 0, 24 | // allow debugger during development 25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, 26 | // use 4 spaces for tab indenting 27 | "indent": ["error", 4], 28 | // require semicolons 29 | "semi": ["error", "always"] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/examples/BasicVueAvatar.html: -------------------------------------------------------------------------------- 1 |
2 | 11 | 12 |
13 | 24 |
25 | 36 |
37 | 48 |
49 | 50 |
51 | 52 |
-------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 two20 4 | 5 | Copyright (c) 2017 islas27 6 | 7 | Copyright (c) 2018 fpluquet 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 63 | 64 | 79 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-avatar-editor-improved", 3 | "version": "1.0.6", 4 | "description": "Resize, rotate and crop your uploaded image using a clear user interface", 5 | "author": "Pluquet Frédéric ", 6 | "homepage": "https://github.com/fpluquet/vue-avatar-editor", 7 | "main": "src/index.js", 8 | "scripts": { 9 | "dev": "node build/dev-server.js", 10 | "start": "node build/dev-server.js", 11 | "build": "node build/build.js", 12 | "lint": "eslint --ext .js,.vue src" 13 | }, 14 | "dependencies": { 15 | "vue": "^2.6.14" 16 | }, 17 | "devDependencies": { 18 | "autoprefixer": "^6.7.2", 19 | "babel-core": "^6.22.1", 20 | "babel-eslint": "^7.1.1", 21 | "babel-loader": "^6.2.10", 22 | "babel-preset-env": "^1.3.2", 23 | "babel-register": "^6.22.0", 24 | "chalk": "^1.1.3", 25 | "connect-history-api-fallback": "^1.6.0", 26 | "copy-webpack-plugin": "^4.6.0", 27 | "css-loader": "^0.28.0", 28 | "eslint": "^4.2.0", 29 | "eslint-config-standard": "^6.2.1", 30 | "eslint-friendly-formatter": "^2.0.7", 31 | "eslint-loader": "^1.7.1", 32 | "eslint-plugin-html": "^3.1.0", 33 | "eslint-plugin-promise": "^3.4.0", 34 | "eslint-plugin-standard": "^2.0.1", 35 | "eventsource-polyfill": "^0.9.6", 36 | "express": "^4.17.1", 37 | "extract-text-webpack-plugin": "^2.0.0", 38 | "file-loader": "^0.11.1", 39 | "friendly-errors-webpack-plugin": "^1.1.3", 40 | "html-loader": "^0.5.5", 41 | "html-webpack-plugin": "^2.28.0", 42 | "http-proxy-middleware": "^0.17.3", 43 | "opn": "^4.0.2", 44 | "optimize-css-assets-webpack-plugin": "^1.3.0", 45 | "ora": "^1.2.0", 46 | "raw-loader": "^0.5.1", 47 | "rimraf": "^2.7.1", 48 | "semver": "^5.7.1", 49 | "shelljs": "^0.7.6", 50 | "url-loader": "^1.1.2", 51 | "vue-loader": "^12.1.0", 52 | "vue-style-loader": "^3.0.1", 53 | "vue-template-compiler": "^2.6.14", 54 | "webpack": "^2.6.1", 55 | "webpack-bundle-analyzer": "^3.9.0", 56 | "webpack-dev-middleware": "^1.10.0", 57 | "webpack-hot-middleware": "^2.25.0", 58 | "webpack-merge": "^4.2.2" 59 | }, 60 | "license": "MIT", 61 | "engines": { 62 | "node": ">= 4.0.0", 63 | "npm": ">= 3.0.0" 64 | }, 65 | "browserslist": [ 66 | "> 1%", 67 | "last 2 versions", 68 | "not ie <= 8" 69 | ] 70 | } 71 | -------------------------------------------------------------------------------- /src/components/VueAvatarEditor.vue: -------------------------------------------------------------------------------- 1 | 44 | 45 | 111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-avatar-editor 2 | 3 | Facebook like, avatar / profile picture component. This is Vue.js clone of mosch/react-avatar-editor 4 | 5 | Resize, rotate and crop your uploaded image using a clear user interface. 6 | 7 | Demo at https://fpluquet.github.io/vue-avatar-editor/ 8 | 9 | # Installation 10 | 11 | This is a [Node.js](https://nodejs.org/en/) module available through the 12 | [npm registry](https://www.npmjs.com/). 13 | 14 | Before installing, [download and install Node.js](https://nodejs.org/en/download/). 15 | Node.js 0.10 or higher is required. 16 | 17 | Installation is done using the 18 | [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): 19 | 20 | ```bash 21 | $ npm install vue-avatar-editor-improved 22 | ``` 23 | 24 | # Usage 25 | 26 | ```html 27 |
28 | 36 | 37 |
38 | 45 | 52 |
53 | 54 |
55 | 56 |
57 | ``` 58 | 59 | ```javascript 60 | import Vue from 'vue' 61 | import {VueAvatar} from 'vue-avatar-editor-improved' 62 | 63 | let vm = new Vue({ 64 | el: '#app', 65 | components: { 66 | VueAvatar, 67 | VueAvatarScale 68 | }, 69 | data () { 70 | return { 71 | rotation: 0, 72 | scale: 1 73 | }; 74 | }, 75 | methods: { 76 | saveClicked () { 77 | var img = this.$refs.vueavatar.getImageScaled() 78 | this.$refs.image.src = img.toDataURL() 79 | }, 80 | onImageReady () { 81 | this.scale = 1 82 | this.rotation = 0 83 | } 84 | } 85 | }) 86 | ``` 87 | 88 | ## Props 89 | | Prop | Type | Description 90 | | ---------------------- | -------- | --------------- 91 | | width | Number | The total width of the editor 92 | | height | Number | The total width of the editor 93 | | border | Number | The cropping border. Image will be visible through the border, but cut off in the resulting image. 94 | | color | Number[] | The color of the cropping border, in the form: [red (0-255), green (0-255), blue (0-255), alpha (0.0-1.0)] 95 | | style | Object | Styles for the canvas element 96 | | scale | Number | The scale of the image. You can use this to add your own resizing slider. 97 | | rotation | Number | The rotation in degrees of the image. You can use this to add your own rotating slider. 98 | | accept | String | Types of accepted files (accept props in file input). Default `image/*`. Exemplary other value `image/png, image/jpeg`. 99 | | placeholderSvg | String | Content of svg file for placeholder image 100 | 101 | ## Accessing the resulting image 102 | 103 | ```javascript 104 | this.$refs.vueavatar.getImage() 105 | ``` 106 | 107 | 108 | The resulting image will have the same resolution as the original image, regardless of the editor's size. 109 | If you want the image sized in the dimensions of the canvas you can use `getImageScaled`. 110 | 111 | 112 | ```javascript 113 | this.$refs.vueavatar.getImageScaled() 114 | ``` 115 | 116 | 117 | # Contributing 118 | 119 | For development you can use following build tools: 120 | 121 | * `npm run build`: Builds the *minified* dist file: `dist/index.js` 122 | * `npm run dev`: Watches for file changes and builds *unminified* into: `dist/index.js` 123 | localhost:8080) 124 | -------------------------------------------------------------------------------- /src/components/VueAvatar.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | 42 | 43 | 550 | --------------------------------------------------------------------------------