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

Exported PNG not transparent #56

Closed
rinne opened this issue Jan 28, 2018 · 2 comments
Closed

Exported PNG not transparent #56

rinne opened this issue Jan 28, 2018 · 2 comments

Comments

@rinne
Copy link

rinne commented Jan 28, 2018

Expected Behaviour

  1. Canvas should by default be transparent and so should in my opinion be the exported bitmap if the export format supports that.

Actual Behaviour

var fs = require('fs');
var PImage = require('pureimage');
var img1 = PImage.make(100,50);
PImage.encodePNGToStream(img1, fs.createWriteStream('out.png')).then(()=> {
    console.log("wrote out the png file to out.png");
}).catch((e)=>{
    console.log("there was an error writing");
});

Results an opaque black PNG.

@elmbrent
Copy link

elmbrent commented Mar 27, 2018

var fs = require('fs');
var PImage = require('pureimage');
var img1 = PImage.make(100,50);
var context = img.getContext('2d')
context.clearRect(0, 0, 100,50)
PImage.encodePNGToStream(img1, fs.createWriteStream('out.png')).then(()=> {
    console.log("wrote out the png file to out.png");
}).catch((e)=>{
    console.log("there was an error writing");
});

You need to add a clearRect and then also set to same height and width of your canvas.

@joshmarinacci
Copy link
Owner

You are right. According to the spec a canvas is transparent by default. I've confirmed this experimentally as well.

I've just pushed back a change which makes the bitmap be clear by default. This should automatically work with exported PNGs as well.

Note that the spec also indicates you can create an opaque canvas by passing an option to getContext(). We should support this in the future.

https://html.spec.whatwg.org/multipage/canvas.html#the-canvas-element

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

3 participants