Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
R
reactjs-skyIdentification
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ProjetDemo
reactjs-skyIdentification
Commits
b7a8e2e4
Commit
b7a8e2e4
authored
Jan 02, 2024
by
dtati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rezise image
parent
3dfbb547
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
53 deletions
+52
-53
src/Components/SkyIdentification.js
src/Components/SkyIdentification.js
+4
-51
src/config/helperConfig.js
src/config/helperConfig.js
+48
-2
No files found.
src/Components/SkyIdentification.js
View file @
b7a8e2e4
...
...
@@ -17,14 +17,13 @@ const SkyIdentification = () => {
readImage
(
event
.
target
.
files
[
0
]);
};
const
readImage
=
(
file
)
=>
{
const
readImage
=
async
(
file
)
=>
{
const
reader
=
new
FileReader
();
//setSelectedFil
e(file);
resizeImage
(
fil
e
);
const
resizedImage
=
await
helper
.
resizeImag
e
(
file
);
setSelectedFile
(
resizedImag
e
);
reader
.
onload
=
function
()
{
setImageSrc
(
reader
.
result
);
};
console
.
log
(
file
)
skyid_extract_info_from_doc_request
(
file
,
responseLogin
.
response_data
.
access_token
);
};
...
...
@@ -158,53 +157,6 @@ const SkyIdentification = () => {
skyid
.
skyid_fa_setup_sdk
();
};
// rezise image function
const
resizeImage
=
(
file
)
=>
{
const
reader
=
new
FileReader
();
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
){
console
.
log
(
"
rezised
"
)
canvas
.
width
=
600
;
canvas
.
height
=
1000
;
}
if
(
img
.
width
>
canvas
.
width
||
img
.
height
>
canvas
.
height
){
console
.
log
(
"
Im here
"
)
ctx
.
drawImage
(
img
,
0
,
0
,
canvas
.
width
,
canvas
.
height
);
canvas
.
toBlob
(
(
blob
)
=>
{
if
(
blob
)
{
const
resizedFile
=
new
File
([
blob
],
file
.
name
,
{
type
:
file
.
type
,
lastModified
:
Date
.
now
(),
});
console
.
log
(
'
Resized File:
'
,
resizedFile
);
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)
);
}
};
};
reader
.
readAsDataURL
(
file
);
};
const
setMessage
=
()
=>
{
skyid
.
message_variables
.
skyid_fa_sdk_access_error_message
=
"
Votre token n'est pas valide
"
;
skyid
.
message_variables
.
skyid_fa_sdk_loading_error_message
=
"
Error lors de chargement des modules
"
;
...
...
@@ -232,6 +184,7 @@ const SkyIdentification = () => {
<
div
id
=
"
multi-step-form-container
"
>
<
input
type
=
"
file
"
onChange
=
{
handleFileChange
}
/
>
<
img
src
=
{
`
${
imageSrc
}
`
}
/
>
<
br
/>
...
...
src/config/helperConfig.js
View file @
b7a8e2e4
...
...
@@ -19,11 +19,13 @@ export default {
const
canvas_bin
=
this
.
skyid_fa_canvas2binary
(
my_selfie_canvas
);
return
new
File
([
canvas_bin
],
"
skyid_fa_selected_frame.jpg
"
,
{
type
:
"
application/octet-stream
"
})
},
skyid_fa_canvas2binary
(
req_canvas
)
{
let
skyid_fa_canvas_data
=
req_canvas
.
toDataURL
(
'
image/jpeg
'
,
1.0
);
skyid_fa_canvas_data
=
skyid_fa_canvas_data
.
replace
(
'
data:image/jpeg;base64,
'
,
''
);
return
this
.
skyid_fa_base64ToArrayBuffer
(
skyid_fa_canvas_data
)
},
skyid_fa_base64ToArrayBuffer
(
base64
)
{
const
binary_string
=
window
.
atob
(
base64
);
const
len
=
binary_string
.
length
;
...
...
@@ -32,8 +34,52 @@ 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment