|
|
|
@ -2557,7 +2557,7 @@ function PaintWeb (win, doc) {
|
|
|
|
|
*
|
|
|
|
|
* @returns {Boolean} True if the operation was successful, or false if not.
|
|
|
|
|
*/
|
|
|
|
|
this.imageSave = function (type) {
|
|
|
|
|
this.imageSave = async function (type) {
|
|
|
|
|
var canvas = _self.layer.canvas,
|
|
|
|
|
cfg = _self.config,
|
|
|
|
|
img = _self.image,
|
|
|
|
@ -2568,8 +2568,9 @@ function PaintWeb (win, doc) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var extMap = {'jpg' : 'image/jpeg', 'jpeg' : 'image/jpeg', 'png'
|
|
|
|
|
: 'image/png', 'gif' : 'image/gif'};
|
|
|
|
|
var extMap = {
|
|
|
|
|
'jpg': 'image/jpeg', 'jpeg': 'image/jpeg', 'png': 'image/png', 'gif': 'image/gif'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Detect the MIME type of the image currently loaded.
|
|
|
|
|
if (typeof type !== 'string' || !type) {
|
|
|
|
@ -2588,18 +2589,18 @@ function PaintWeb (win, doc) {
|
|
|
|
|
// We consider that other formats than PNG do not support transparencies.
|
|
|
|
|
// Thus, we create a new Canvas element for which we set the configured
|
|
|
|
|
// background color, and we render the image onto it.
|
|
|
|
|
if (type !== 'image/png' || img.zoom!=1) {
|
|
|
|
|
if (type !== 'image/png' || img.zoom != 1) {
|
|
|
|
|
canvas = doc.createElement('canvas');
|
|
|
|
|
var context = canvas.getContext('2d');
|
|
|
|
|
|
|
|
|
|
canvas.width = img.width * img.zoom;
|
|
|
|
|
canvas.height = img.height * img.zoom;
|
|
|
|
|
canvas.width = img.width * img.zoom;
|
|
|
|
|
canvas.height = img.height * img.zoom;
|
|
|
|
|
|
|
|
|
|
context.fillStyle = cfg.backgroundColor;
|
|
|
|
|
context.fillRect(0, 0, img.width, img.height);
|
|
|
|
|
context.drawImage(_self.layer.canvas, 0, 0, canvas.width, canvas.height);
|
|
|
|
|
|
|
|
|
|
context = null;
|
|
|
|
|
context = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -2621,16 +2622,34 @@ function PaintWeb (win, doc) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// by gujc
|
|
|
|
|
if (!_self.config.imageSaveURL) {
|
|
|
|
|
if (_self.config.afterImageSave) _self.config.afterImageSave();
|
|
|
|
|
return;
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
// 변경된 부분
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
if (!_self.config.imageSave) {
|
|
|
|
|
if (_self.config.afterImageSave) _self.config.afterImageSave();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imageSaveTo(idata, img.width, img.height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//_self.config.imageSave(idata, img.width, img.height, doc, _self);
|
|
|
|
|
|
|
|
|
|
const fileObject = await toBlob(idata)
|
|
|
|
|
.then(res => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
this.image = {
|
|
|
|
|
filename: res.name,
|
|
|
|
|
size: res.size,
|
|
|
|
|
type: res.type,
|
|
|
|
|
lastModified: res.lastModified
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
});
|
|
|
|
|
_self.config.imageSave(fileObject, img.width, img.height, doc, _self);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
var ev = new appEvent.imageSave(idata, img.width, img.height),
|
|
|
|
|
cancel = _self.events.dispatch(ev);
|
|
|
|
|
|
|
|
|
@ -2638,12 +2657,30 @@ function PaintWeb (win, doc) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
var imgwin = _self.win.open();
|
|
|
|
|
if (!imgwin) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imgwin.location = idata;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
var imgwin = _self.win.open();
|
|
|
|
|
if (!imgwin) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
imgwin.document.write('<iframe src="' + idata + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
var iframe = "<iframe width='100%' height='100%' src='" + idata + "'></iframe>";
|
|
|
|
|
var x = window.open();
|
|
|
|
|
x.document.open();
|
|
|
|
|
x.document.write(iframe);
|
|
|
|
|
x.document.close();
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
idata = null;
|
|
|
|
|
|
|
|
|
|
_self.events.dispatch(new appEvent.imageSaveResult(true));
|
|
|
|
@ -3033,3 +3070,60 @@ PaintWeb.baseFolder = '';
|
|
|
|
|
|
|
|
|
|
// vim:set spell spl=en fo=wan1croqlt tw=80 ts=2 sw=2 sts=2 sta et ai cin fenc=utf-8 ff=unix:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var toBlob = async (url) => {
|
|
|
|
|
return () => {
|
|
|
|
|
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)
|
|
|
|
|
return formData.get('file')
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 전달받은 이미지를 base64로 인코딩한다
|
|
|
|
|
*/
|
|
|
|
|
var base64Encode = async (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 () => {
|
|
|
|
|
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)
|
|
|
|
|
return {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|