|
|
|
@ -508,7 +508,7 @@ function serialize (formData) {
|
|
|
|
|
* </pre>
|
|
|
|
|
*/
|
|
|
|
|
function downloadImage(img, fileName) {
|
|
|
|
|
var imgData = atob(img.src.split(',')[1]),
|
|
|
|
|
var imgData = atob(img.split(',')[1]),
|
|
|
|
|
len = imgData.length,
|
|
|
|
|
buf = new ArrayBuffer(len),
|
|
|
|
|
view = new Uint8Array(buf),
|
|
|
|
@ -529,8 +529,8 @@ function downloadImage(img, fileName) {
|
|
|
|
|
//var url = URL.createObjectURL(blob);
|
|
|
|
|
var a = document.createElement('a');
|
|
|
|
|
a.style = 'display: none';
|
|
|
|
|
//a.href = url;
|
|
|
|
|
a.href = img.src;
|
|
|
|
|
a.href = URL.createObjectURL(blob);;
|
|
|
|
|
//a.href = img.src;
|
|
|
|
|
a.download = fileName;
|
|
|
|
|
document.body.appendChild(a);
|
|
|
|
|
a.click();
|
|
|
|
@ -541,3 +541,140 @@ function downloadImage(img, fileName) {
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var readBlob = async () => {
|
|
|
|
|
const data = await fetch('https://play-lh.googleusercontent.com/hYdIazwJBlPhmN74Yz3m_jU9nA6t02U7ZARfKunt6dauUAB6O3nLHp0v5ypisNt9OJk');
|
|
|
|
|
const blob = await data.blob();
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = () => {
|
|
|
|
|
const base64data = reader.result;
|
|
|
|
|
console.log(base64data)
|
|
|
|
|
}
|
|
|
|
|
reader.readAsDataURL(blob);
|
|
|
|
|
|
|
|
|
|
fetch('https://www.business2community.com/wp-content/uploads/2014/04/Free.jpg')
|
|
|
|
|
.then((response) => response.blob())
|
|
|
|
|
.then((blob) => {
|
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
document.querySelector('img').src = url;
|
|
|
|
|
document.querySelector('a').href = url;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param b64Data
|
|
|
|
|
* @param contentType
|
|
|
|
|
* @param sliceSize
|
|
|
|
|
* @returns {Blob}
|
|
|
|
|
*/
|
|
|
|
|
// bas64를 blob으로 변환해주는 함수
|
|
|
|
|
function b64toBlob(b64Data, contentType = '', sliceSize = 512) {
|
|
|
|
|
const image_data = atob(b64Data.split(',')[1]); // data:image/gif;base64 필요없으니 떼주고, base64 인코딩을 풀어준다
|
|
|
|
|
|
|
|
|
|
const arraybuffer = new ArrayBuffer(image_data.length);
|
|
|
|
|
const view = new Uint8Array(arraybuffer);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < image_data.length; i++) {
|
|
|
|
|
view[i] = image_data.charCodeAt(i) & 0xff;
|
|
|
|
|
// charCodeAt() 메서드는 주어진 인덱스에 대한 UTF-16 코드를 나타내는 0부터 65535 사이의 정수를 반환
|
|
|
|
|
// 비트연산자 & 와 0xff(255) 값은 숫자를 양수로 표현하기 위한 설정
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Blob([arraybuffer], { type: contentType });
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
const contentType = 'image/png';
|
|
|
|
|
const b64Data =
|
|
|
|
|
'data:image/gif;base64,R0lGODlhAAEAAcQAALe9v9ve3/b393mDiJScoO3u74KMkMnNz4uUmKatsOTm552kqK+1uNLW18DFx3B7gP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bW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SYTp2UYFs7zdA6csaOD3fypicX0DlACAAW0iTjLfxUugUENIepcMAyBVGAA0DCigRgwAEWqggF4IkAB82eAfh0AG5eaCQAeFrAKSlHgAUA4AC8DIgAAtCAR0QCb5noEyfgo4AAOMKlBGhkaxAQ000EwKOSqqlN8QSAooo0EpHQKTl4itSSFrWoKLUpUGdG1apa9apYzapWt8rVrnr1q2ANq1jHStaymvWseggBADs=';
|
|
|
|
|
|
|
|
|
|
const blob = b64toBlob(b64Data, contentType); // base64 -> blob
|
|
|
|
|
const blobUrl = URL.createObjectURL(blob); // object url 생성
|
|
|
|
|
|
|
|
|
|
const img = document.createElement('img');
|
|
|
|
|
img.src = blobUrl;
|
|
|
|
|
document.body.appendChild(img);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 전달받은 이미지를 base64로 인코딩한다
|
|
|
|
|
* @param file - 이미지 파일 또는 이미지 URL
|
|
|
|
|
* @param maxWidth - 인코딩 시의 이미지 max width 사이즈
|
|
|
|
|
* @returns {Promise<any>}
|
|
|
|
|
*/
|
|
|
|
|
var readImage = () => {
|
|
|
|
|
let image = this.$refs.image.src
|
|
|
|
|
this.toBlob(image)
|
|
|
|
|
.then(res => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
this.image = {
|
|
|
|
|
filename: res.name,
|
|
|
|
|
size: res.size,
|
|
|
|
|
type: res.type,
|
|
|
|
|
lastModified: res.lastModified
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 이미지 url을 blob 파일로 변환하여 전달한다
|
|
|
|
|
* @param url
|
|
|
|
|
* @returns {Promise<any>}
|
|
|
|
|
*/
|
|
|
|
|
var toBlob = (url) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this.base64Encode(url)
|
|
|
|
|
.then(res => {
|
|
|
|
|
let byteString = atob(res.dataUrl)
|
|
|
|
|
let ab = new ArrayBuffer(byteString.length)
|
|
|
|
|
let ia = new Uint8Array(ab)
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < byteString.length; i++) {
|
|
|
|
|
ia[i] = byteString.charCodeAt(i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write the array buffer to blob
|
|
|
|
|
let blob = new Blob([ab], {type: 'image/' + res.type})
|
|
|
|
|
|
|
|
|
|
let formData = new FormData()
|
|
|
|
|
formData.append('file', blob, res.name)
|
|
|
|
|
resolve(formData.get('file'))
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 전달받은 이미지를 base64로 인코딩한다
|
|
|
|
|
*/
|
|
|
|
|
var base64Encode = (url) => {
|
|
|
|
|
const re = new RegExp('.(gif|jpg|jpeg|tiff|png|ico)$', 'i')
|
|
|
|
|
let name = (/[^(/|\\)]*$/).exec(url)[0]
|
|
|
|
|
let type = re.test(name) ? re.exec(name)[0].replace('.', '') : 'jpg'
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let image = new Image()
|
|
|
|
|
|
|
|
|
|
image.onload = function (event) {
|
|
|
|
|
let canvas = document.createElement('canvas')
|
|
|
|
|
// draw canvas
|
|
|
|
|
canvas.width = image.naturalWidth
|
|
|
|
|
canvas.height = image.naturalHeight
|
|
|
|
|
canvas.getContext('2d').drawImage(image, 0, 0)
|
|
|
|
|
|
|
|
|
|
let dataUrl = canvas.toDataURL('image/' + type)
|
|
|
|
|
resolve({
|
|
|
|
|
name: name,
|
|
|
|
|
type: type,
|
|
|
|
|
dataUrl: dataUrl.split(',')[1]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
image.onerror = function () {
|
|
|
|
|
let msg = `"${file}"을 로딩하는 데 오류가 발생하였습니다. 이미지 파일을 확인해주세요.`
|
|
|
|
|
alert(msg)
|
|
|
|
|
console.error(msg)
|
|
|
|
|
}
|
|
|
|
|
image.crossOrigin = 'anonymous';
|
|
|
|
|
image.src = url
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|