gifshot icon indicating copy to clipboard operation
gifshot copied to clipboard

black background for transparent images and duplicate layers

Open ranbuch opened this issue 7 years ago • 5 comments

Here are some of the input images: frame # 1: frame1 frame # 10: frame10 frame # 44: frame44

(out of 49 total images)

And this is the end result: final

As you can see the background is black and the images seems to be duplicating i instead of flushing after their frame.

I use those options: { "images": [49 base64 images], "gifWidth": "200", "gifHeight": "200", "sampleInterval": 80 }

ranbuch avatar Feb 09 '18 08:02 ranbuch

same problem.Have you solved this problem?

forget1 avatar Jun 04 '18 11:06 forget1

Same problem. Any solution ???

kabrice avatar Oct 10 '18 10:10 kabrice

It's my first time using this library and I encountered the same problem... Anyways, here's the solution that worked for me.

I have an array called images that contains four base64 image URIs and each of them has transparent areas.

Now I have a function that adds a background color to an image like so:

function addBackgroundColor(imageURI, backgroundColor) {
    var image = new Image();
    image.src = imageURI;

    var canvas = document.createElement('canvas'),
        ctx = canvas.getContext('2d');
    
    canvas.width = 449;
    canvas.height = 449;
   
    // Add background color
    ctx.fillStyle = backgroundColor;
    ctx.fillRect(0, 0, canvas.width, canvas.height);

    ctx.drawImage(image, 0, 0);

    return canvas.toDataURL();
}

Sample Usage

var images = [...]; // Contains 4 base64 image URIs
    backgroundColor = '#222222';

gifshot.createGIF({
    gifWidth: 449,
    gifHeight: 449,
    images: [
        addBackgroundColor(images[0], backgroundColor),
	addBackgroundColor(images[1], backgroundColor),
	addBackgroundColor(images[2], backgroundColor),
	addBackgroundColor(images[3], backgroundColor)
    ],
    interval: 1,
    numFrames: 10,
    frameDuration: 1,
    sampleInterval: 10,
    numWorkers: 2
}, function(obj) {
    if (!obj.error) {
        console.log(obj.image);
    }
});

Hope this helps :)

kennyalmendral avatar May 01 '19 01:05 kennyalmendral

This does not work, any idea how to make the background transparent?

dorofino avatar Dec 15 '21 18:12 dorofino

Anybody have a solution for the bug?

leogitpro avatar Feb 11 '22 03:02 leogitpro