Commit 3dfbb547 authored by dtati's avatar dtati

rezise_image-1

parent 5558c086
...@@ -19,6 +19,7 @@ const SkyIdentification = () => { ...@@ -19,6 +19,7 @@ const SkyIdentification = () => {
const readImage = (file) => { const readImage = (file) => {
const reader = new FileReader(); const reader = new FileReader();
//setSelectedFile(file);
resizeImage(file); resizeImage(file);
reader.onload = function () { reader.onload = function () {
setImageSrc(reader.result); setImageSrc(reader.result);
...@@ -71,9 +72,9 @@ const SkyIdentification = () => { ...@@ -71,9 +72,9 @@ const SkyIdentification = () => {
formData.append('institution_id', helper.institution_id); formData.append('institution_id', helper.institution_id);
formData.append('application_id', helper.skyid_fa_sdk_appId); formData.append('application_id', helper.skyid_fa_sdk_appId);
formData.append('channel_id', "02"); formData.append('channel_id', "02");
formData.append('service_id', "01"); formData.append('service_id', "09");
formData.append('sub_service_id', "005"); formData.append('sub_service_id', "005");
formData.append("request_data", '{"doc_type":"01"}'); formData.append("request_data", '{"doc_type":"09"}');
axios.post(helper.OCR_url, formData, { axios.post(helper.OCR_url, formData, {
headers: { headers: {
Authorization: `Bearer ${bearToken}`, Authorization: `Bearer ${bearToken}`,
...@@ -159,36 +160,44 @@ const SkyIdentification = () => { ...@@ -159,36 +160,44 @@ const SkyIdentification = () => {
// rezise image function // rezise image function
const resizeImage = (file) => { const resizeImage = (file) => {
const reader = new FileReader(); const reader = new FileReader();
reader.onload = (e) => { reader.onload = (e) => {
const img = new Image(); const img = new Image();
img.src = e.target.result; img.src = e.target.result;
img.onload = () => { img.onload = () => {
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
canvas.width = 1000; canvas.width = 1000;
canvas.height = 600; canvas.height = 600;
if(img.width < img.height){
console.log("rezised")
canvas.width = 600;
canvas.height = 1000;
}
ctx.drawImage(img, 0, 0, canvas.width, canvas.height); if(img.width > canvas.width || img.height > canvas.height){
canvas.toBlob( console.log("Im here")
(blob) => { ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
if (blob) { canvas.toBlob(
const resizedFile = new File([blob], file.name, { (blob) => {
type: file.type, if (blob) {
lastModified: Date.now(), const resizedFile = new File([blob], file.name, {
}); type: file.type,
console.log('Resized File:', resizedFile); lastModified: Date.now(),
setSelectedFile(resizedFile); });
} else { console.log('Resized File:', resizedFile);
console.error('Failed to create Blob.'); setSelectedFile(resizedFile);
} } else {
}, console.error('Failed to create Blob.');
file.type, // Set the image type explicitly }
0.9 // Adjust the quality (0.0 to 1.0, 1.0 for maximum quality) },
); file.type, // Set the image type explicitly
0.9 // Adjust the quality (0.0 to 1.0, 1.0 for maximum quality)
);
}
}; };
}; };
......
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