I get reference to fix orientation image from here :
https://github.com/blueimp/JavaScript-Canvas-to-Blob
I try in vue component like this :
<template>
<div>
...
</div>
</template>
<script>
export default {
...
methods: {
...
changeImage(item, $event) {
...
loadImage(
$event.target.files[0],
function (img) {
img.toBlob(
function (blob) {
// create a form
const form = new FormData();
form.append('file', blob, $event.target.files[0].name);
// define the done handler
const onDone = (response) => {
if (!$.trim(response)) {
alert('No response');
}
else {
const files = $event.target.files || $event.dataTransfer.files
if (!files.length)
return;
this.createImage(item, response)
...
}
}
// define th post options
const options = {
url: window.Laravel.baseUrl+'/product/addImageTemp',
type: "POST",
data: form,
enctype: 'multipart/form-data',
processData: false, // tell jQuery not to process the data
contentType: false // tell jQuery not to set contentType
}
// submit the image
$.ajax(options).done(onDone);
}, $event.target.files[0].type
);
},
{
maxWidth: 600,
canvas: true,
pixelRatio: window.devicePixelRatio,
downsamplingRatio: 0.5,
orientation: true
} // Options
);
},
createImage(item, response) {
...
}
}
}
</script>
It works. It success upload image in folder. But on the console exist error :
Uncaught TypeError: Cannot read property 'createImage' of undefined
The error here : this.createImage(item, response)
Seems the error because it cannot use this
in function (img) {
How can I solve this problem?
I need this plugin to fix orientation image