Commit d68c19fe authored by dtati's avatar dtati

resize image

parent c4a0c841
......@@ -23,14 +23,14 @@ export default {
this.readImage(selectedFile);
}
},
readImage(file) {
async readImage(file) {
this.isLoading = true;
const reader = new FileReader();
reader.onload = (e) => {
this.imagePreview = e.target.result;
};
reader.readAsDataURL(file);
this.binaryFile = file;
this.binaryFile = await Helper.resizeImage(file);
this.$store.dispatch('skyid_extract_info_from_doc_request', {myImage : file, bearToken: this.bearToken}).then(() => {
if(this.response_ocr){
this.isLoading = false;
......
......@@ -5,8 +5,8 @@ export default {
LIVENESS_url : "***",
FACE_MATCHING_url : "***",
skyid_fa_sdk_params_url : "***",
Recover_Face_Matching_Result_URL: "***",
Recover_Face_Matching_Result_URL : "***",
institution_id : "***",
skyid_fa_sdk_user : "***",
skyid_fa_sdk_password : "***",
......@@ -32,6 +32,50 @@ export default {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
},
resizeImage (file) {
console.log(file);
const defaultQualityRatio = 0.9;
const imageType = file.type || 'image/jpeg';
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
const img = new Image();
img.src = e.target.result;
img.onload = () => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 1000;
canvas.height = 600;
if (img.width < img.height) {
canvas.width = 600;
canvas.height = 1000;
}
if (img.width > canvas.width || img.height > canvas.height) {
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
ctx.canvas.toBlob(
(blob) => {
resolve(
new File([blob], file.name, {
type: imageType,
lastModified: Date.now(),
})
);
},
imageType,
defaultQualityRatio
);
}
};
};
reader.onerror = (error) => {reject(error);};
});
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment