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

Callback/event when the Chromakey effect has been applied to an image #161

Open
polomoshnov opened this issue Dec 9, 2017 · 4 comments
Open

Comments

@polomoshnov
Copy link

Right after seriously.go() I do target.toDataURL('image/png') and get an empty image. But if I setTimeout(function () { target.toDataURL('image/png') }, 1000) the image is not empty and has the Chromakey effect applied successfully. (For the source I use an image not a video.) I think the effect is being applied asynchronously and that's why that happens.

@positlabs
Copy link

Are you preloading the image?

It should be drawn on the next frame. For that, you can do requestAnimationFrame(yourCallback)

@spoji
Copy link

spoji commented Feb 6, 2019

While a lot of threads on different websites say otherwise, toDataURL() is now asynchronous (at least on Chrome) : https://bugs.chromium.org/p/chromium/issues/detail?id=514206

You can fix this using a promise/callback instead of a timeout. For example :

    return new Promise(resolve => {
        const img = new Image();
        ...<snip>...

        img.onload = function() {
            resolve(img);
        };

        img.src = canvas.toDataURL("image/png");
    });

@juliandormon
Copy link

I am having the exact same issue. The target canvas worked perfectly. I wrapped the method in an onload event as specified above but I still get a transparent image. Hoping you can help.Thanks in advance.

 var seriously = new Seriously();
            var source = seriously.source(media);
            var target = seriously.target(canvas);
            chromaEffect = seriously.effect("chroma");
            chromaEffect.screen = [0 / 255, 117 / 255, 49 / 255, 0];
            chromaEffect.weight = 1;
            chromaEffect.balance = 1;
            chromaEffect.clipBlack = 0;
            chromaEffect.clipWhite = 1;
            chromaEffect.source = source;
            target.source = chromaEffect;
            seriously.go();

var finalImg = new Image();

                finalImg.onload = function () {
                    $media.attr("src", finalImg.src);
                }

                finalImg.src = canvas.toDataURL("image/png");

@juliandormon
Copy link

I figured it out. I had to put my final functions within the go(callback);

var seriously = new Seriously();
            var source = seriously.source(media);
            var target = seriously.target(canvas);
            chromaEffect = seriously.effect("chroma");
            chromaEffect.screen = [0 / 255, 117 / 255, 49 / 255, 0];
            chromaEffect.weight = 1;
            chromaEffect.balance = 1;
            chromaEffect.clipBlack = 0;
            chromaEffect.clipWhite = 1;
            chromaEffect.source = source;
            target.source = chromaEffect;
            seriously.go(function () { 

var finalImg = new Image();

                finalImg.onload = function () {
                    $media.attr("src", finalImg.src);
                }

                finalImg.src = canvas.toDataURL("image/png");

});

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

No branches or pull requests

4 participants