├── .babelrc
├── .gitignore
├── LICENSE
├── README.md
├── build
├── build.js
└── main.js
├── dist
└── vue-image-compressor.js
├── index.html
├── package.json
├── src
└── js
│ ├── components
│ ├── app.vue
│ └── vue-image-compressor.vue
│ ├── main.js
│ └── plugin.js
├── webpack-bundle.config.js
├── webpack-prod.config.js
├── webpack.config.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015"],
3 | "plugins": ["transform-object-rest-spread","transform-vue-jsx"]
4 | }
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Naufal Rabbani
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vue Image Compressor
2 | [Vue](http://vuejs.org) Component To Compress Image Files. It's based on [cpol-image](https://beta.webcomponents.org/element/3mp3ri0r/cpol-image) and [others references](#credits)
3 |
4 | [DEMO](https://bosnaufal.github.io/vue-image-compressor)
5 |
6 |
7 | ## Install
8 | You can import [vue-image-compressor.vue](./dist/vue-image-compressor.js) to your vue component file like [this](./src/js/components/app.vue) and process it with your preprocessor.
9 |
10 | You can install it via NPM
11 | ```bash
12 | npm install vue-image-compressor
13 | ```
14 |
15 | Or Just put it after Vue JS~
16 | ```html
17 |
18 |
19 | ```
20 |
21 |
22 | ## Import Module
23 | ```javascript
24 | import imageCompressor from 'vue-image-compressor'
25 | // Or
26 | var imageCompressor = require('vue-image-compressor');
27 | ```
28 |
29 | ## Usage
30 | ```html
31 |
32 |
33 |
37 |
38 |
39 |
40 |
41 |
42 |
58 | ```
59 |
60 | ## Props
61 | #### done (Function)
62 | Callback after Compress the image. It will pass original file and compressed file and also the canvas element. The object pretty complete with blob and base64 and other needed information.
63 |
64 | #### scale (Number)
65 | The percentage of image scaling it starts from 1 to 100.
66 |
67 | #### quality (Number)
68 | The percentage of image quality it starts from 1 to 100.
69 |
70 |
71 | ## Credits
72 | - [https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL)
73 | - [https://davidwalsh.name/convert-canvas-image](https://davidwalsh.name/convert-canvas-image)
74 | - [https://beta.webcomponents.org/element/3mp3ri0r/cpol-image](https://beta.webcomponents.org/element/3mp3ri0r/cpol-image)
75 |
76 | ## Thank You for Making this useful~
77 |
78 | ## Let's talk about some projects with me
79 | Just Contact Me At:
80 | - Email: [bosnaufalemail@gmail.com](mailto:bosnaufalemail@gmail.com)
81 | - Skype Id: bosnaufal254
82 | - twitter: [@BosNaufal](https://twitter.com/BosNaufal)
83 |
84 | ## License
85 | [MIT](http://opensource.org/licenses/MIT)
86 | Copyright (c) 2016 - forever Naufal Rabbani
87 |
--------------------------------------------------------------------------------
/build/build.js:
--------------------------------------------------------------------------------
1 | !function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return t[i].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){var i=n(11),r=n(9);i.config.debug=!0,i.config.devTools=!0,new i({el:"body",components:{App:r}})},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0});var r=n(10),s=i(r);n(6),e["default"]={data:function(){return{files:[]}},components:{fileBase64:s["default"]},methods:{getFiles:function(t){this.files=t}}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e["default"]={props:{multiple:{type:Boolean,"default":!1},done:{type:Function,"default":function(){}}},methods:{onChange:function(t){for(var e=this,n=t.target.files,i=[],r=function(){var t=n[s],r=new FileReader;r.readAsDataURL(t),r.onload=function(){var s={name:t.name,type:t.type,size:Math.round(t.size/1e3)+" kB",base64:r.result,file:t};i.push(s),i.length==n.length&&(e.multiple?e.done(i):e.done(i[0]))}},s=0;s=0&&b.splice(e,1)}function a(t){var e=document.createElement("style");return e.type="text/css",s(t,e),e}function l(t){var e=document.createElement("link");return e.rel="stylesheet",s(t,e),e}function h(t,e){var n,i,r;if(e.singleton){var s=_++;n=g||(g=a(e)),i=c.bind(null,n,s,!1),r=c.bind(null,n,s,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=l(e),i=f.bind(null,n),r=function(){o(n),n.href&&URL.revokeObjectURL(n.href)}):(n=a(e),i=u.bind(null,n),r=function(){o(n)});return i(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;i(t=e)}else r()}}function c(t,e,n,i){var r=n?"":i.css;if(t.styleSheet)t.styleSheet.cssText=y(e,r);else{var s=document.createTextNode(r),o=t.childNodes;o[e]&&t.removeChild(o[e]),o.length?t.insertBefore(s,o[e]):t.appendChild(s)}}function u(t,e){var n=e.css,i=e.media;if(i&&t.setAttribute("media",i),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function f(t,e){var n=e.css,i=e.sourceMap;i&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */");var r=new Blob([n],{type:"text/css"}),s=t.href;t.href=URL.createObjectURL(r),s&&URL.revokeObjectURL(s)}var p={},d=function(t){var e;return function(){return"undefined"==typeof e&&(e=t.apply(this,arguments)),e}},v=d(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),m=d(function(){return document.head||document.getElementsByTagName("head")[0]}),g=null,_=0,b=[];t.exports=function(t,e){e=e||{},"undefined"==typeof e.singleton&&(e.singleton=v()),"undefined"==typeof e.insertAt&&(e.insertAt="bottom");var n=r(t);return i(n,e),function(t){for(var s=[],o=0;o