Skip to content

Instantly share code, notes, and snippets.

@vincentiusronalto
Created January 12, 2020 15:16
Show Gist options
  • Save vincentiusronalto/d0ee05fb9bd3e63215ea240d9cc4f0ee to your computer and use it in GitHub Desktop.
Save vincentiusronalto/d0ee05fb9bd3e63215ea240d9cc4f0ee to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
async function uploadImage(inputRaw, location){
try{
let input = inputRaw.map(x=>x[1]);
//input : ['base64_1','base64_2',...] etc
let imageResult = '';
if(input.length > 0){
for(i = 0,j = input.length; i < j; i++){
//convert base64 to image
let base64Str = input[i];
let uncompress_path = './public/upload/uncompressed/';
//input:base64 and output:uncompresspath
// imageInfo : { imageType: 'jpeg', fileName: 'img-1571230468779.jpeg' }
let imageInfo = await base64ToImage(base64Str,uncompress_path);
let uncompress_path_start = uncompress_path+imageInfo.fileName;
let compress_output = './public/upload/'+location;
//input:uncompresspath+filename and output public+location
let check = await compressImg(uncompress_path_start, compress_output);
//delete uncompress image
let checkRemove = await removeFile(uncompress_path_start);
if(i == j-1){
imageResult += imageInfo.fileName + "";
}else{
imageResult += imageInfo.fileName + "_";
}
}
}
return imageResult;
}catch(err){
console.log(err)
}
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">async function uploadImage(inputRaw, location){
try{
let input = inputRaw.map(x=>x[1]);
//input : ['base64_1','base64_2',...] etc
let imageResult = '';
if(input.length > 0){
for(i = 0,j = input.length; i < j; i++){
//convert base64 to image
let base64Str = input[i];
let uncompress_path = './public/upload/uncompressed/';
//input:base64 and output:uncompresspath
// imageInfo : { imageType: 'jpeg', fileName: 'img-1571230468779.jpeg' }
let imageInfo = await base64ToImage(base64Str,uncompress_path);
let uncompress_path_start = uncompress_path+imageInfo.fileName;
let compress_output = './public/upload/'+location;
//input:uncompresspath+filename and output public+location
let check = await compressImg(uncompress_path_start, compress_output);
//delete uncompress image
let checkRemove = await removeFile(uncompress_path_start);
if(i == j-1){
imageResult += imageInfo.fileName + "";
}else{
imageResult += imageInfo.fileName + "_";
}
}
}
return imageResult;
}catch(err){
console.log(err)
}
}</script></body>
</html>
async function uploadImage(inputRaw, location){
try{
let input = inputRaw.map(x=>x[1]);
//input : ['base64_1','base64_2',...] etc
let imageResult = '';
if(input.length > 0){
for(i = 0,j = input.length; i < j; i++){
//convert base64 to image
let base64Str = input[i];
let uncompress_path = './public/upload/uncompressed/';
//input:base64 and output:uncompresspath
// imageInfo : { imageType: 'jpeg', fileName: 'img-1571230468779.jpeg' }
let imageInfo = await base64ToImage(base64Str,uncompress_path);
let uncompress_path_start = uncompress_path+imageInfo.fileName;
let compress_output = './public/upload/'+location;
//input:uncompresspath+filename and output public+location
let check = await compressImg(uncompress_path_start, compress_output);
//delete uncompress image
let checkRemove = await removeFile(uncompress_path_start);
if(i == j-1){
imageResult += imageInfo.fileName + "";
}else{
imageResult += imageInfo.fileName + "_";
}
}
}
return imageResult;
}catch(err){
console.log(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment