Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tui-image-editor.js add blur tool #249

Open
kimsuel opened this issue Oct 7, 2019 · 0 comments
Open

tui-image-editor.js add blur tool #249

kimsuel opened this issue Oct 7, 2019 · 0 comments

Comments

@kimsuel
Copy link

kimsuel commented Oct 7, 2019

Hi,
I want to develop a blur tool, but I'm struggling because the structure of tui-image-editor.js is not well understood.
I do not know the webpack require structure.
Can you please help me make the blur tool.
I used the following code..

var tempCanvas = document.getElementById("tempCanvas");
var tempCtx = tempCanvas.getContext("2d");

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var $canvas = $("#canvas");
var canvasOffset = $canvas.offset();
var offsetX = canvasOffset.left;
var offsetY = canvasOffset.top;
var scrollX = $canvas.scrollLeft();
var scrollY = $canvas.scrollTop();
var isDown = false;

var PI2 = Math.PI * 2;

var img = new Image();
img.crossOrigin = "anonymous";
img.onload = start;
img.src = "https://dl.dropboxusercontent.com/u/139992952/multple/bigben.jpg";

function start() {
    canvas.width = tempCanvas.width = img.width;
    canvas.height = tempCanvas.height = img.height;
    ctx.drawImage(img, 0, 0);
}


function handleMouseDown(e) {
    e.preventDefault();
    e.stopPropagation();
    tempCtx.clearRect(0, 0, tempCanvas.width, tempCanvas.height);
    isDown = true;
}

function handleMouseUp(e) {
    e.preventDefault();
    e.stopPropagation();
    isDown = false;
    tempCtx.save();
    tempCtx.globalCompositeOperation = "source-in";
    tempCtx.drawImage(img, 0, 0);
    tempCtx.restore();
    boxBlurCanvasRGBA("tempCanvas", 0, 0, tempCanvas.width, tempCanvas.height, 4, 0);
    ctx.save();
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.drawImage(tempCanvas, 0, 0);
    ctx.globalCompositeOperation = "destination-over";
    ctx.drawImage(img, 0, 0);
    ctx.restore();
}

function handleMouseOut(e) {
    e.preventDefault();
    e.stopPropagation();
    isDown = false;
}

function handleMouseMove(e) {
    if (!isDown) {
        return;
    }
    e.preventDefault();
    e.stopPropagation();
    mouseX = parseInt(e.clientX - offsetX);
    mouseY = parseInt(e.clientY - offsetY);
    ctx.beginPath();
    ctx.arc(mouseX, mouseY, 20, 0, PI2);
    ctx.closePath();
    ctx.fill();
    tempCtx.beginPath();
    tempCtx.arc(mouseX, mouseY, 20, 0, PI2);
    tempCtx.closePath();
    tempCtx.fill();
}

$("#canvas").mousedown(function (e) {
    handleMouseDown(e);
});
$("#canvas").mousemove(function (e) {
    handleMouseMove(e);
});
$("#canvas").mouseup(function (e) {
    handleMouseUp(e);
});
$("#canvas").mouseout(function (e) {
    handleMouseOut(e);
});

I want to use this code and use the blur tool in the image editor.
Please help me.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants