Skip to content

Commit

Permalink
Merge pull request #76 from AjithLalps/#74-fix
Browse files Browse the repository at this point in the history
#74 chore: update README.md
  • Loading branch information
jofftiquez authored Mar 10, 2020
2 parents b07b45e + a0e0c55 commit 2d67193
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,59 @@ export default {
</script>
```

### File Upload Sample
You can upload file instead of using direct image link.
*Usage*
In your form add a `file input` along with `vue-croppie` component.
```vue
<template>
<input type="file" @change="croppie"/>
<vue-croppie ref="croppieRef" :enableOrientation="true" :boundary="{ width: 450, height: 300}" :viewport="{ width:400, height:250, 'type':'square' }">
</vue-croppie>
<!-- the result -->
<img :src="cropped">
<button @click="crop">Crop</button>
</template>
<script>
export default {
data() {
return {
croppieImage: '',
cropped: null
};
},
methods: {
croppie (e) {
var files = e.target.files || e.dataTransfer.files;
if (!files.length) return;
var reader = new FileReader();
reader.onload = e => {
this.$refs.croppieRef.bind({
url: e.target.result
});
};
reader.readAsDataURL(files[0]);
},
crop() {
// Options can be updated.
// Current option will return a base64 version of the uploaded image with a size of 600px X 450px.
let options = {
type: 'base64',
size: { width: 600, height: 450 },
format: 'jpeg'
};
this.$refs.croppieRef.result(options, output => {
this.cropped = this.croppieImage = output;
console.log(this.croppieImage);
});
}
}
};
```

### Using Options

All [Croppie options](https://foliotek.github.io/Croppie/) were converted to props to be able use them in the `vue-croppie` component.
Expand Down

0 comments on commit 2d67193

Please sign in to comment.